Results 1 to 17 of 17
  1. #1
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default Java SOAP - Best Practice

    Given a WSDL, and wanting to develop a Java Client. Does anyone know what is the best technique. I've tried usine jax-ws but that does not give access to the header - only the business methods.

    I've take a look at using Jaxb, but that only converts to and from java beans, xsds and xml. It dosn't give any accesss to transport mechanisms etc. Also it results in really horrible code (bit like trying to create an HTML page by using HtmlUnit!).

    Is SOAP the worst technology ever invented for getting computers to talk to each other in a distributed heterogeneous, when the've been doing this for years using text over HTTP - (oops! did I mension REST).

    Anyway, any help on the soap question would be great before I throw my computer out the window!

    Thanks
    Adam

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    SOAP (and web services in general) are all about computers talking to each other.
    You expose an interface (your business methods) and the client makes calls to them.

    What's the problem with that?

    If you need to get at the headers (which are usually dealt with by the client/server engines anyway) then you can attach handlers (or interceptors) to your client or server which will allow you to get at the raw message itself.

    JAXB has nothing whatsoever to do with SOAP or web services. It is purely for generating Java classes from an XSD, and generating objects from XML files based on those XSDs.

  3. #3
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    It’s an incredibly complicated way for doing something which is incredibly simple.

    It’s a technology that smacks of over-engineering. What’s the problem with just sending or requesting information form a URL and getting or sending normal xml documents from those endpoints. I know people will go on about bit representation of numbers, method signatures, impedance miss-match etc., but that’s just a bunch of rubbish.

    I’ve been communicating via text over http for years and never had to worry about all that stuff that SOAP is supposed to ‘solve’. It seems to me that REST services just blows all that SOAP stuff out of the water.

    It’s because of the horrific complication of using SOAP that is leading to the slow demise of Java, and allowing simpler ways of doing things, such as Ruby, to grab the ‘productivity’ ground.

    Case in point; to use a REST web service, even with security will take about 2 minutes. To do the same in SOAP will take all day just to write the configuration files and put the client-side framework together.

    The SOAP service I’m trying to connect to is just an organisation search service, and the provider has said it will probably be a two man-week project! Just to do an address search for a company!!! Most of that will be the configuration of the SOAP rubbish. It would be quicker to write a screen-scraper and use Yell.

    I’m not an expert in SOAP, but that’s the problem – you have to be to use it.

    If on the other hand you’re interested in getting things done then SOAP is not the way to go. And, unfortunately I’ve got no option.

    Adam

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    You seem to be grandstanding...:)

    SOAP and WSDL were designed to provide a technique for developing services that someone who is not in touch with the original developers can simply point their app at and easily cobble together a client. As the server, all I need to do is stick up my WSDL. As the client, all you need to do is generate a client (for which there are numerous tools for several languages) and voila, you have a client that can talk to my service.

    REST is great, but it works in a completely different environment. I need to know what language you're speaking in order to write my client. A WSDL/SOAP service I don't, because it's all predefined.

    I have no idea what this service you are having problems with is, so I can't say where they expect the time to go. But you should have a basic client up and running in the amount of time it takes to get either Axis or JAX-WS to generate the client code. You don't need to faff with the headers...

  5. #5
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    More like ranting rather than grandstanding.

    All that is still a lot easier with REST services. No need to create client, no need to know anything about the original developers.

    Secondly, you dont need to know what 'language' you speaking when talking to rest (other than json or xml) - but as one can be converted into the other then where's the pain in that. If your talking about predefined by meaning what methods and signatures there are, then thats just a bunch of hogs wash. Having all that pre-defined just makes the code fragile - if the service provider changes a method the your code breaks and you have to go through that whole rigmarole again. Sure something will have to change on the client side with REST - if your using that method, but if your not then they can change what they like. It wont effect client side at all.

    BTW,
    Trying to find examples of using handlers to get at the produced XML on a jaxws-rt produced client and I can't find any or any use. The ones I can find say you have to have some customer configuration file on the server and on the client. So much for not having to be in touch with the original developers. SOAP is rubbish for many reasons - but mostly because its fragile and inflexible.

    Why cant I see the headers!!!


  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    With REST you still need to define what the JSON string sent back means.
    You still need to define what parameters to send up. That's what I mean by language.
    With SOAP it's XML.

    Why do you need to see the headers?
    This is what I don't understand...

    Also you are clearly looking in the wrong places. I can (and have) written interceptors to grab the raw xml sent from and received by the client. On the client. No contact with the servers developers. That's how soapui works...

  7. #7
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    OK OK,
    I've been compiling the wsdl using jaxws-maven-plugin. Its produced a bunch of files fine. The wsdls are from a company called Atradius who provide insurance cover for invoices (in case they don't get paid). However part of their doc says this:

    ------------------------------------------------------------------------------------
    The validation of credentials for the Connect2 services is based on the WSS 1.0.
    The security header of each request must contain a username token element with its password.
    4.2.2 Example
    An example is described below:

    Java Code:
    […] 
    <SOAP-ENV:Header> 
      <wsse:Security 
       SOAP-ENV:mustUnderstand="0" 
       xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
       <wsse:UsernameToken> 
        <wsse:Username>[USER]</wsse:Username> 
        <wsse:Password 
         Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"> 
         [PASSWORD] 
        </wsse:Password> 
       </wsse:UsernameToken> 
      </wsse:Security> 
    </SOAP-ENV:Header> 
    […]
    With
    - SOAP-ENV defined as xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    - [USER] and [PASSWORD], the credential used for the dedicated environment.
    A timestamp in the header can also be added.
    ------------------------------------------------------------------------------------

    So, I thought to myself, I'll take a look at the headers produced by jaxws and take it from there. Perhapse, I thought, I would just stick this file snippet in there using jaxb. No such luck - Slipped on SOAP!!!

    Other problem is that when I try and connect to their service I get the following error:

    ------------------------------------------------------------------------------------
    Java Code:
    com.atradius.services.organisationsearch._2006_03_17.OrganisationSearchError: 
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:141)
    	at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)DONE
    
    	at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
    	at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
    	at $Proxy31.getOrganisations(Unknown Source)
    	at com.vetrado.atradius.AtradiusClient.findOrganisation(AtradiusClient.java:89)
    	at com.vetrado.atradius.AtradiusClient.main(AtradiusClient.java:31)
    ------------------------------------------------------------------------------------
    I would send you the original wsdl and my simple client, but there doesn't seem to be a way to attached files to these posts.

    Adam

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Adding stuff to the header.
    Saved me trying to figure out how to do it...:)
    That's for JAX-WS by the way, essentially doing your "just stick it in there" technique.

    It's what I said earlier about handlers...(interceptors might be Spring).

    As for that erro, that looks like something from their server.

  9. #9
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    Yah, thats what I thought, but its a dammed weird error.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    com.atradius.services.organisationsearch._2006_03_ 17.OrganisationSearchError
    That's an error defined (presumably) in their WSDL?
    I would hope it would mean something, but it could just be a generic "this hasn't worked".
    If your security stuff wasn't working, could it be a rubbish security-failed error?

  11. #11
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    Well thanks for that. That seems to work fine as far as putting in the header. What a long winded way of inserting a bit of xml in a file. Bring on templates!!

    Anyway, I think that's got me started, but I still have the other exception to deal with.



    BTW. Is that Java Code Examples, Java Tips and Java Related Articles site a good site for general code examples?

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    SOAP Headers are a problem, it has to be said.
    It's because they don't actually have to be declared in the WSDL, so isn't something that can be auto-generated.
    If it's declared then it'll be available to set on the client...if it's not then the generated client has nothing to work with, so you have to manually add them.
    Still, once you have one Handler coded you just copy/paste it and change it depending on what needs to go in it.

    Can't guarantee that site, to be fair. I was simply going on that example being code I recognised doing myself, and it's not Rose India...:)

  13. #13
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    Well thanks for that. That seems to work fine as far as putting in the header. What a long winded way of inserting a bit of xml in a file. Bring on templates!!

    Anyway, I think that's got me started, but I still have the other exception to deal with.



    BTW. Is that Java Code Examples, Java Tips and Java Related Articles site a good site for general code examples?

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Blimey that was a 15 minute double post...
    Nice work!

  15. #15
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    Just one more question.

    In my wsdl I have the following:

    Java Code:
    <wsdl:port name="OrgSearchSoapPort" binding="impl:OrgSearchSoapBinding">
            <soap:address location="https://www.atradius.com/PRODORGSEARCH/services/OrgSearchSoapPort"/>
    </wsdl:port>
    Which I guess is the URL as which the soap service is listening for request. However, I can not find for love or money where that URL is referanced in the source java classes created by jaxws.

    Anyone who create a simple wrapper around the SOAP stuff will make a mint. Perhaps have a method such as set/get ServiceURL()

    ALSO where is a good source to learn about all this SOAP stuff. Particularly around the area of security certificates etc.

    Adam
    Last edited by Jeeni101; 07-26-2011 at 07:08 PM.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    I thought you could change that value.
    I've not used JAX-WS, only Axis, and that was a couple of years ago now, but I do seem to remember generating against a test ws and supplying (in a configuration) the real web service when it was deployed.

    As for tutorials, there's the Oracle one for JAX-WS I suppose, but it's a bit thin.
    Other than that you could always refer to the main docs for SOAP, or w3schools for some simple tutorials on SOAP.

    As for the security bit, I only have books for that.

  17. #17
    Jeeni101 is offline Member
    Join Date
    Apr 2011
    Posts
    22
    Rep Power
    0

    Default

    OK,thanks. Think I'll investing in some hard copy today.

    Cheers for your help

Similar Threads

  1. Java SOAP Listener
    By njitram in forum Advanced Java
    Replies: 1
    Last Post: 01-29-2011, 09:59 PM
  2. Replies: 1
    Last Post: 10-25-2010, 06:54 PM
  3. I need help on a practice code for java
    By Sageinquisitor in forum New To Java
    Replies: 12
    Last Post: 07-13-2010, 04:00 PM
  4. java practice
    By miko5054 in forum New To Java
    Replies: 3
    Last Post: 03-22-2010, 05:31 PM
  5. Building small web application in java for practice.
    By Saurabh321 in forum New To Java
    Replies: 1
    Last Post: 02-01-2008, 03:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •