0

The only web services I've ever integrated with or used have been RESTful. I'm now trying to integrate with a 3rd party SOAP service and am awe-struck at how seemingly convoluted SOAP appears to be.

With REST, I use a JAX-RS client called Jersey that makes hitting RESTful endpoints a piece a' cake. For instance, if a service is exposing a POST endpoint at http://api.example.com/fizz (say, for upserting Fizz objects), then in Jersey I might make a service client that looks like this (pseudo-code):

// Groovy pseudo-code
class Fizz {
    int type
    boolean derps
    String uid
}

class FizzClient {
    WebResource webResource = initAt("https://api.example.com")

    upsertFizz(Fizz fizz) {
        webResource.path("fizz").post(fizz)
    }
}

But Java-based SOAP clients seem, at first blush, to be fairly more complicated. If I understand the setup correctly, the general process is this:

  1. Obtain an XML document called a WSDL from the service provider; this appears to be a language-agnostic description of all the available endpoints
  2. Run a JDK tool called wsimport on the WSDL which actually generates Java source code, which implements JAX-WS APIs and actually represents my SOAP client
  3. Import those generated source files into my project and use them

First off, if anything I have said about this process is incorrect, please begin by correcting me! Assuming I'm more or less correct, what I don't understand is: why is this necessary if its all an HTTP conversation? Why couldn't I achieve SOAP-based conversations with Jersey, and bypass all this source-generation boilerplate?

For instance, say the same endpoint exists, but is governed by SOAP:

class FizzClient {
    WebResource webResource = initAt("https://api.example.com")
    FizzSerializer serializer // I take Fizz instances and turn them into XML
    FizzDeserializer deserializer // I take XML and turn them into Fizz instances

    upsertFizz(Fizz fizz) {
        String xmlFizz = serializer.serialize(fizz)
        webResource.path("fizz").post(xmlFizz)
    }
}

If I understand SOAP correctly, its just a way of utilizing HTTP verbs and request/response entities to send app-specific messages around; it's an HTTP "conversation". So why couldn't I hijack a REST framework like Jersey to HTTP POST messages, and in doing so, bypass this SOAP overhead?

smeeb
  • 27,777
  • 57
  • 250
  • 447
  • 1
    this may help http://stackoverflow.com/questions/19884295/soap-vs-rest-differences – Uttesh Kumar Apr 28 '15 at 19:05
  • Thanks @UtteshKumar (+1) - however I understand, in principle, the differences between SOAP and REST. I guess I'm just pointing out that Jersey can be used to send any type of entity, as any type of content, to any URL, using any HTTP verb...so why (**ever?**) use JAX-WS/SOAP if it can be mimicked with REST/Jersey? – smeeb Apr 28 '15 at 19:07

1 Answers1

1

This is going to attract opinion-based answers, but first, you should understand that

  • is much younger than ( had a final draft in 2006, JAX-RS came out in 2008-9).

  • RESTful webservices standard, for many purposes is quite amorphous - many businesses prefer the comfort of a contract in the form of a WSDL.

  • Not to mention that JAX-WS, in concert with WS-I provides many other standards that govern security, message reliability and other enterprise-goodies (under the generic "WS-*" banner) that businesses care about. There's a hodge-podge of libraries that are attempting to get that kind of uniformity on to the platform, but for now, /WS-I is the industry standard

kolossus
  • 20,559
  • 3
  • 52
  • 104
  • Thanks @kolossus (+1) - but are you saying that I *can't* coerce Jersey to honor the client-side of SOAP, or just that I *shouldn't*? Thanks again! – smeeb Apr 28 '15 at 19:35
  • [You can](http://stackoverflow.com/questions/3886653/jax-rs-jersey-schema-validation) @smeeb, it's just not built into the platform (at least, not that I know of) – kolossus Apr 28 '15 at 19:37