Announcement Announcement Module
Collapse
No announcement yet.
JAXBElement not capable of nested structures? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JAXBElement not capable of nested structures?

    Hi there,

    I'm working on a project, where I received a WSDL of a WS that is not yet up and running.
    As I'm new to Spring WS I decided to set up a dummy web service by myself, so I can test my client implementation in the meantime.

    Using wsimport I generated some Java classes out of the WSDL. Then I pretty much followed the steps described in krams nice tutorial:

    http://krams915.blogspot.com/2010/12...t-200-rc2.html

    Also using Castor as the marshaller (even though JAXB might have bee less work, because wsimport does already generate some annotations for JAXB?)

    When consuming the WS in SOAP UI, everything works fine.

    Code:
    @PayloadRoot(localPart = REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
    	@ResponsePayload
    public Response getResponse getArtikelBestand(@RequestPayload Request) {
    ...
    }
    When writing the client I noticed that the request and response class generated by wsimport are not annotated with @XmlRootElement. So I need to wrap them with a JAXBElement

    Code:
    JAXBElement<Response> jaxbResponse = (JAXBElement<Response>) webServiceTemplate.marshalSendAndReceive(jaxbRequest);
    Using TCP/IP Monitor in Eclipse I see that the request and response are successful:

    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <ns3:getInformation xmlns:ns3="...">
    <id>123</id>
    </ns3:getInformation>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    Code:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <ns3:getInformationResponse xmlns:ns3="http://pim.migros.net/migrosinout/services/v2/pimDataExport">
    <getInformationResponseDto>
    <id>123</id>
    <information>
    ...
    </information>
    </getInformationResponseDto>
    </ns3:getInformationResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    The weird thing now is that when i call

    Code:
    Response response = jaxbResponse.getValue();
    I receive a object of type Response. However the child of it is null.

    Code:
    response.getInformationDto() == null
    However if I change my web service to

    Code:
    @PayloadRoot(localPart = REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
    	@ResponsePayload
    public JAXBElement<Response> getResponse getArtikelBestand(@RequestPayload JAXBElement<Request>) {
    ...
    }
    It works fine.

    What is wrong here?

    Cheers,
    wi.lee

  • #2
    To make it simple :

    Code:
    IF (GeneratedClass Has @XmlRootElement) {
                 you can use it directly
        }
    ELSE  use it like this : JAXBElement<GeneratedClass>
    It is not a bug , is is a feature (or maybe a bugeature )

    Wanna learn why ? See the full explanation

    Comment


    • #3
      Thanks for the reply, but I dont' think this is my issue.

      1) I've generated java classes using wsimport, which have JAXB annotations.

      2) I assume that wsimport is not making any mistakes.

      Now that I have that class files, I simply instantiate them (and if needed wrap them in a JAXBElement) e.g. the request object and send them using marshalSendAndReceive.

      When using the Jaxb2Marshaller I assume I don't need to write any mappings as the class files are already annotated. However this doesn't work. I guess there the marshalling is not done properly, using TCP/IP monitor however everything looks fine.

      When I introduce a payloadValidatingInterceptor on the client side it says:

      Code:
      XML validation error on response: cvc-complex-type.2.4.a: Invalid content was found starting with element 'id'
      TCP/IP monitor doesn't show anything, somehow the request has not been sent but the error seems to be on the response, which is really weird.

      Anyway when switching to a Castor Marshaller (Castor is also used on the server side) everythin works fine.

      I right now don't see why JAXB should not work..

      Comment


      • #4
        It seems that your id has no namespace so tha why ther is a xml validaton.

        Im sure just half sure about that.

        Anyway, i may dont know the problem but im pretty confident about the solution to it.
        First, you should follow a best practice already available in spring Ws sample if you are using a maven project.
        The classes should be generated by a maven plugin during the compilaton phase
        See some samples of spring ws (maybe the airline sample).

        So please,don't generate it at will, it is too much error-prone.
        Here is a tutorial how to integrate XJC
        Last edited by mada; Jan 13th, 2011, 03:20 PM. Reason: typo

        Comment


        • #5
          No solutions found yet..
          So I stick to castor for now.

          Comment

          Working...
          X