Announcement Announcement Module
Collapse
No announcement yet.
Webservice-Client: Common approach with Spring WS, JAXB and just one WSDL file? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Webservice-Client: Common approach with Spring WS, JAXB and just one WSDL file?

    Hello,

    I would like to use Spring WS to build a Webservice-Client with JAXB for marshalling and unmarshalling the Java classes.

    But what I have is just one WSDL file. When I understand it right, I can generate Java classes with JAXB (xbj.exe), which then can be used by me with Spring WS to retrieve the Webservice-Data and send an answer.

    But JAXB can only generate Java classes from xsd-schema files. Must I now manually copy those xsd-definitions from within the WSDL file to generate those classes via JAXB? (in my case the WSDL file contains 4 XSD definitions).

    Or is there a way to just convert the whole WSDL to Java classes which I can use with Spring WS (I know there is the "wsimport", but it is part of JAX-WS and I think I can't use it in this scenario, right?).

    So what is the common approach with Spring WS / JAXB / one WSDL file?

    I really would like to get startet with Spring WS and JAXB - thanks a lot for your help!

  • #2
    look here http://blog.dawouds.com/2008/09/mave...sing-jaxb.html

    Comment


    • #3
      Hello ptalakanti,

      thanks for your answer. Your link describes the maven task like the following webpage: http://jaxb.java.net/jaxb-maven2-plugin/

      The difference is, that the official JAXB-page also uses .xsd files directly, not the WSDL. The example in your link uses quite the same approach with the small difference, that for "xjc.exe" the parameter "-wsdl" will be used. But when I start "xjc.exe" manually and display the help, the "-wsdl" parameter reads:

      "treat input as WSDL and compile schemas inside it (experimental,unsupported)".

      So I thought this could not be the common way to do it.

      Comment


      • #4
        I am not sure why the example was not working but I ended up creating a maven build file to generate java objects from wsdl

        I could not download the plugin, It turns out it is not available on maven central so I added this repository to pom.xml

        Code:
        <pluginRepositories>
          	<pluginRepository>
          	  <id>maven2-repository.java.net</id>
        	  <name>Java.net Repository for Maven</name>
        	  <url>http://download.java.net/maven/2</url>
        	  <layout>default</layout>
          	</pluginRepository>
          </pluginRepositories>
        I have to say the documentation is not really good for this plugin, I stumbled around a bit before I got this working. I used the following maven plugin config to generate the java objects from wsdl input

        Code:
        <plugin>
        <groupId>com.sun.tools.xjc.maven2</groupId>
        <artifactId>maven-jaxb-plugin</artifactId>
        <version>1.1.1</version>
         <configuration>
        	<generateDirectory>src/main/java</generateDirectory>
        	<generatePackage>prasanna.generated</generatePackage>
        	<schemaDirectory>src/main/resources</schemaDirectory>
         </configuration>
        	<executions>
        	  <execution>
        		<phase>compile</phase>
        		<goals>
        	        	<goal>generate</goal>
        		</goals>
        		<configuration>
        		<schemaDirectory>src/main/resources</schemaDirectory>
        		<readOnly>true</readOnly>
        		<includeSchemas>
        		<includeSchema>hello.wsdl</includeSchema>
        		</includeSchemas>
        		<args>-wsdl</args>
        		</configuration>		
        	</execution>
        	</executions>
         </plugin>
        looks like you did the same thing, I don't know why you got that error. I tried to attach my pom.xml to the post but I keep getting invalid file error

        Comment


        • #5
          Hi,

          I am looking for a similar way of developing a webservice-Client, can you please suggest me a good site , where i can start with.Since i do not know much about JAXB.

          Comment


          • #6
            Hello GSP,

            when starting with Spring WS, I think the official reference documentation is a good start point. It is not as heavy as the Spring core documentation, so I think, especially when focusing the development of a Webservice client, you will get started quickly.

            As for JAXB, when you only want to generate classes out of a XML Schema file (.xsd), you just use the command line tool "xjc.exe", found in your JDK bin-directory, it is really easy. For a webservice client, this is what you only need. Of course, JAXB is more than that, and if you want to learn to annotate your own classes with JAXB, I suggest consulting JAXB's official documentation, also. But for a Webservice client, you only need JAXB generate your files and then have a look at the Marshalling mechanism in the Spring WS documentation.
            Last edited by patb; Aug 2nd, 2011, 11:35 AM.

            Comment


            • #7
              Thank you so much for your help.I will try Spring WS and let you know.

              Comment


              • #8
                This very helpful to me too ptalakanti...

                _____________________________________
                Education Consultants in India

                Comment


                • #9
                  I use WSDL generation using this maven artefact.

                  Here are some problems i already met with other technologies (no Spring ws) remote webservices :
                  - SOAP Action is required by some remote webservices ==> you have to add it in soap header using a callback
                  - the wsdl only declares complexType and no element ==> you have to add the complexType object in a JAXBElement with the good QName
                  - the wsdl uses the same root tag for all functions (for example : parameters) and functions all returns the same root tag ==> you have to use a JAXBElement with the good QName for the request / You have to use a specific source extractor

                  In order to call remote services using their wsdl, i shared an interceptor that allows all those functions : https://itcb.svn.sourceforge.net/svn...terceptor.java
                  In my java code, i just have to code a JAVA interface that matches the remote wsdl with generated classes as parameters and return types. The interceptor does his work in order to call webservice.

                  Hope it helps.

                  Comment


                  • #10
                    Check the following tutorials. You might find something interesting:

                    http://krams915.blogspot.com/p/tutorials.html

                    http://krams915.blogspot.com/2010/12...ing-3-mvc.html
                    http://krams915.blogspot.com/2010/12...ng-client.html

                    Comment


                    • #11
                      Hello Everyone,

                      Did anyone suceed in developeing clien web service code using Spring WS, starting with wsdl and using Ant script ?

                      Thanks
                      Prachi

                      Comment

                      Working...
                      X