Implement a SOAP webservice in scala

4.6k Views Asked by At

What is the best library/framework to implement a SOAP webservice in scala?

an example of using scalaxb to implement a SOAP webservice?

Please, no heavy frameworks such as lift.

2

There are 2 best solutions below

0
On

I guess there is no such library at the moment and maybe never will be, anyway, the situation is not that bad as it seems. You can create a Scala wrappers on top of existing Java SOAP libs. Have a look here for more info SOAP-proxy in Scala - what do I need? and for starters here: http://java.dzone.com/articles/basic-ws-scala-sbt-and-jee-6

0
On

I ran into this very old question, and I'm not sure if the situation was different when it was posted, but here's an example using jax-ws, from https://redsigil.weebly.com/home/a-scala-soap-web-service.

@WebService(
  targetNamespace = "http://com.redsigil/soapserver",
  name = "com.redsigil.soapserver",
  portName = "soap",
  serviceName = "SoapServerSample")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@Addressing(enabled = true, required = false)
class SoapServerImpl() {
  @WebMethod(action = "hashing")
  def test(@WebParam(name = "mystr", mode = WebParam.Mode.IN) value: String): String = sha256Hash(value)

  def sha256Hash(text: String): String =
    String.format("%064x",
      new java.math.BigInteger(1, java.security.MessageDigest.getInstance("SHA-256").digest(text.getBytes("UTF-8"))))
}

As you can see, it's fairly simple, although the annotations makes it a little ugly. The service defines one SOAP method ("test") which takes a string and returns its hash. The main function looks like this:

val myservice: SoapServerImpl = new SoapServerImpl()
val ep:Endpoint = Endpoint.publish("http://localhost:8080/test", myservice)

Yes, I know the OP indicate he did not like using jax-ws -- a little rant there in a comment, but consider that it's not something that cannot be solved through proper design and abstraction.