-
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.
-
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.
-
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="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<!-- Webservice client Definition -->
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMe ssageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOA P_11"/>
</property>
</bean>
<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServi 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>
<bean id="validationEventHandler" class="sample.IgnoreValidationEventHandler">
</bean>
<!--
<bean id="jaxb1Marshaller" class="org.springframework.oxm.jaxb.Jaxb1Marshalle r">
<property name="contextPath" value="schema path; like com.echo"/>
</bean>-->
<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>
<bean id="baseInterceptor" class="sample.BaseClientInterceptor">
</bean>
<bean name="emplService" class="sampleBean">
<property name="webServiceTemplate" ref="webServiceTemplate"/>
</bean>
</beans>
--
-- sampleBean
--
package sample;
import java.io.IOException;
import java.math.BigInteger;
import sample.EmployeeRequest;
import sample.EmployeeResponse;
import org.springframework.ws.client.core.WebServiceTempl 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) {
System.out.println(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 org.springframework.context.support.ClassPathXmlAp 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...");
testEmp.callWS();
System.out.println("..done");
}
}
-
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.