Announcement Announcement Module
No announcement yet.
Create request object from WSDL Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create request object from WSDL

    Could you please give some directions on this..

    What tool should I use to get java objects corresponding xml elements in WSDL (no XSD in WSDL). Once I get those objects, I can pass in my service layer to fill out.


  • #2
    wsimport for jax-ws; wsdl2java for axis are couple examples. These commands generate necessary java classes from WSDL.


    • #3
      thank you for quick reply.

      Yes I used wsdl2java tool and it is creating java files.. but java objects contains the methods specific to axis.. example, it has the following methods: parse(), getParser(), registerPrefix(), writeQNames(), writeAttribute(), getOMElement() etc., I do not see attributes corresponding to xml elements.

      here the command which I used.
      wsdl2java -ss -g -uri http://localhost:8080/echo/myecho?WSDL

      What I want is, java object should have getters and setters; similary to xjc which convers xsd to java files. Since I dont have XSD, I want to extract type/schema from WSDL and generate java files.

      Here is the reason I am asking, currently I have one wsdl and it has imported XSD, I used xjc tool to convert xml to java objects and used in Spring to get data. And there is another wsdl which my business partner is building has no imported XSD, schema is embedded in the WSDL and I could not use xjc to get java files.

      I hope, I explained the problem I am facing here..



      • #4
        Just do a cut and paste job and lift out the inline schema - jobs a good un.


        • #5
          Thank you,

          I took out schema and generated java files. I am able to generate Request and while calling WebServiceTemplate.marshalSendAndReceive(), I am getting the following error:

 xception: Forbidden [403]
          at ate.handleError(
          at ate.doSendAndReceive(
          at ate.sendAndReceive(
          at ate.marshalSendAndReceive( 289)
          at ate.marshalSendAndReceive( 283)
          at ate.marshalSendAndReceive( 275)
          at sample.CallWS.callEmpInfo(Unknown Source)

          If I call the same WS by sending same request in SoapUI, I am getting response.

          so I am doing something wrong, but I could not see where it is. Can you please help me.



          • #6
            I could figured it out the mistake, i made spelling mistake in my URI value in my bean. I corrected it and is working fine.

            Thank you.


            • #7
              New to create web service client


              I am creating WebService client for the first time. I have read WebServiceTemplate tutorial to understand some of the points.

              I have to call some of the methods of a webservice and I have WSDL.

              I need to know how to call specific methods of WebService using WebServiceTemplate and how to pass the parameters required to call the webservice method.

              I have read that I can use SoapAction to specify which method to call but not sure how to send the parameters.

              Please help.


              • #8
                I think that is what the Uri setting is for. Which can be set either in the bean config for the WebServiceTemplate or passed into the send~ method you wish to use.

                I could be wrong, pretty new to Spring-ws myself.


                • #9
                  DefaultUri is the URL to access the WebService I guess.
                  What I need here is to call one of the methods of the webservice and before calling the method need to assign params.

                  What I think I need to do is to create WebServiceMessage and set the params in it but not sure how to do it.

                  Thanks for your reply though.


                  • #10
                    Ah, ok, not so sure.
                    My understanding was that assuming you have you Template setup correctly, you should be able to create one of the request objects generated from the wsdl, populate this with values, make this the parameter of one of the send methods, and that was all there is too it.

                    At least that my understanding.


                    • #11
                      You may be right. But the class that are created using WSDL do not seem to have getter/setter for the params or in other words, classes those are created using WSDL are different to those created using JAXB. (I might be wrong in saying this but not really sure).

                      Which tool do you use to convert WSDL2Java? Axis2?

                      The creator of this thread might be able to help me here as the work which I want to do is very similar to this post.


                      • #12
                        No, I am not using AXIS, I am using ws-import which is part of jdk 6, or you should be able to download it for 1.5.

                        I am using it via maven and the jaxws-maven-plugin and the classes I have do have getters and setters.


                        • #13
                          Here is my sampel script.. I have not included interceptor and validator, those are just skeletons..

                          see if this helps..

                          -- Context xml

                          <?xml version="1.0" encoding="UTF-8"?>
                          <beans xmlns=""

                          <!-- Webservice client Definition -->

                          <bean id="messageFactory" class=" ssageFactory">
                          <property name="soapVersion">
                          <util:constant static-field=" P_11"/>

                          <bean id="webServiceTemplate"
                          class=" ceTemplate" scope="singleton">
                          <constructor-arg ref="messageFactory"/>
                          <property name="defaultUri" value="your WSDL goes here"/>
                          <property name="marshaller" ref="jaxb2Marshaller"/>
                          <property name="unmarshaller" ref="jaxb2Marshaller"/>
                          <property name="interceptors" ref="baseInterceptor"/>

                          <bean id="validationEventHandler" class="sample.IgnoreValidationEventHandler">

                          <bean id="jaxb1Marshaller" class="org.springframework.oxm.jaxb.Jaxb1Marshalle r">
                          <property name="contextPath" value="schema path; like com.echo"/>

                          <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
                          <property name="contextPath" value="sample"/>
                          <!-- <property name="schema" value="your XSD goes here/> -->
                          <property name="validationEventHandler" ref="validationEventHandler"/>

                          <bean id="baseInterceptor" class="sample.BaseClientInterceptor">

                          <bean name="emplService" class="sampleBean">
                          <property name="webServiceTemplate" ref="webServiceTemplate"/>


                          -- sampleBean
                          package sample;

                          import java.math.BigInteger;

                          import sample.EmployeeRequest;
                          import sample.EmployeeResponse;

                          import ate;

                          public class EmpServiceImpl {

                          private WebServiceTemplate webServiceTemplate;
                          // call web service
                          public void callWS() {

                          long startTime = 0,finishTime=0;

                          EmployeeRequest req = new EmployeeRequest();
                          try {
                          req.setId(new BigInteger("1"));
                          startTime = System.currentTimeMillis();
                          EmployeeResponse resp = callEmpInfo(req);
                          finishTime = System.currentTimeMillis();
                          System.out.println("Directory Webservice call took "+(finishTime-startTime)+"ms");
                          if(resp==null) {
                          System.out.println("Directory Webservice returned null response.");
                          } else {
                          String nm = resp.getName();
                          String te = resp.getTitle();
                          System.out.println("Name : " + nm + ", Title : " + te );
                          } catch(Exception ex) {

                          * Call Employee Info webservice
                          * @param req Schema request object to send to the webservice
                          * @return
                          * @throws IOException
                          private EmployeeResponse callEmpInfo(EmployeeRequest req) throws IOException {
                          //WebserviceContext.setInterfaceTypeCode(INTR_TYPE_C D_ACCINFO);
                          return(EmployeeResponse)webServiceTemplate.marshal SendAndReceive(req);

                          public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
                          this.webServiceTemplate = webServiceTemplate;


                          -- main class
                          import org.springframework.context.ApplicationContext;
                          import plicationContext;
                          import sample.EmpServiceImpl;

                          public class Main {
                          public static void main(String[] z) {
                          ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
                          EmpServiceImpl testEmp = (EmpServiceImpl)context.getBean("emplService");
                          System.out.print("Calling Websevice...");



                          • #14
                            xjc with -wsdl option

                            As a best practice, schema file should be separated from wsdl file and it should be imported into wsdl file. If schema file is not available as a separate file then we need to generate the java files from wsdl file using the below mentioned command.

                            Example :

                            Change to your project directory. ..\src\main

                            xjc -d java -wsdl webapp\WEB-INF\wsdl\calculator.wsdl

                            it creates the java objects and places it in to java folder.