Hi,

Jay SenSharma

Jay SenSharma

If we want to create a WebService using JAXWS which contains some method arguments as Complex types then we can use the following Samples. We need to keep one thing in mind while implementing such WebServices that all the Complex types should contain Setters and Getter Methods for all of it’s Properties (attributes/Instance Variables).

Step1). Create a Folder some where in your File system…sithat we can start developing our codes here:
Example: C:JavaTestDemo-2-ComplexDataType
Step2). Create a “ComplexImpl.java” in location: (C:JavaTestDemo-2-ComplexDataTypesrcexampleswebservicescomplex)
package examples.webservices.complex;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import examples.webservices.complex.BasicStruct;

@WebService(serviceName=”ComplexService”, name=”ComplexPortType”,targetNamespace=”http://example.org“)
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL,parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class ComplexImpl
{

@WebMethod()
@WebResult(name=”IntegerOutput”,targetNamespace=”http://example.org/complex“)
public int echoInt(@WebParam(name=”IntegerInput”,targetNamespace=”http://example.org/complex”)int input)
{
System.out.println(“nntechoInt ‘” + input + “‘ to you too!”);
return input;
}

@WebMethod(operationName=”echoComplexType”)
@WebResult(name=”EchoStructReturnMessage”,targetNamespace=”http://example.org/complex“)
public BasicStruct echoStruct(BasicStruct struct)
{
System.out.println(“nntechoComplexType called”);
return struct;
}

@WebMethod(operationName=”echoOrderStatus”)
@WebResult(name=”EchoOrderStatusReturnMessage”,targetNamespace=”http://example.org/complex“)

public OrderStatus putOrder (Order order)
{
System.out.println(“nntechoOrderStatus called order.getOrderName(): “+order.getOrderName());
OrderStatus orderStatus=new OrderStatus();
orderStatus.setDate(new java.util.Date());
orderStatus.setOrder(order);
return orderStatus;
}
}
——————-

Step3). Now develop the “BasicStruct.java” like following in location: (C:JavaTestDemo-2-ComplexDataTypesrcexampleswebservicescomplex)

package examples.webservices.complex;
public class BasicStruct
{
private int intValue;
private String stringValue;
private String[] stringArray;

public int getIntValue()
{
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
public String getStringValue() {
return stringValue;
}
public void setStringValue(String stringValue) {
this.stringValue = stringValue;
}
public String[] getStringArray() {
return stringArray;
}
public void setStringArray(String[] stringArray) {
this.stringArray = stringArray;
}
public String toString() {
return “IntValue=”+intValue+”, StringValue=”+stringValue;
}
}
——————–

Step 4). Now develop the “Order.java” like following in location: (C:JavaTestDemo-2-ComplexDataTypesrcexampleswebservicescomplex)

package examples.webservices.complex;
public class Order
{
private String orderName=”No-Order”;

public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
public String toString() {
return “orderName =”+orderName;
}
}
———————
Step5). Now develop the “OrderStatus.java” like following in location: (C:JavaTestDemo-2-ComplexDataTypesrcexampleswebservicescomplex)

package examples.webservices.complex;
import java.util.Date;
public class OrderStatus
{
private Date date;
private Order order;

public Date getDate()
{
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Order getOrder() {
return this.order;
}
public void setOrder(Order order) {
this.order = order;
}
public String toString() {
return “Date=”+date+”, Order=”+order;
}
}
——————–
Step6). Finally we need to develop the ANT build file sothat we can Compile our WebService using JAXWS attribute of Jwsc Ant Task: (C:JavaTestDemo-2-ComplexDataTypebuild.xml)

<project name=”webservices-complex” default=”all”>
<!– set global properties for this build –>
<property name=”wls.username” value=”weblogic” />
<property name=”wls.password” value=”weblogic” />
<property name=”wls.hostname” value=”localhost” />
<property name=”wls.port” value=”7001″ />
<property name=”wls.server.name” value=”AdminServer” />
<property name=”ear.deployed.name” value=”complexServiceEAR” />
<property name=”example-output” value=”output” />
<property name=”ear-dir” value=”${example-output}/complexServiceEar” />
<property name=”clientclass-dir” value=”${example-output}/clientclass” />

<path id=”client.class.path”>
<pathelement path=”${clientclass-dir}”/>
<pathelement path=”${java.class.path}”/>
</path>

<taskdef name=”jwsc” classname=”weblogic.wsee.tools.anttasks.JwscTask” />
<taskdef name=”clientgen” classname=”weblogic.wsee.tools.anttasks.ClientGenTask” />
<taskdef name=”wldeploy” classname=”weblogic.ant.taskdefs.management.WLDeploy” />

<target name=”all” depends=”clean,build-service,deploy,client”/>

<target name=”clean” depends=”undeploy”>
<delete dir=”${example-output}”/>
</target>

<target name=”build-service”>
<jwsc srcdir=”src” destdir=”${ear-dir}” keepGenerated=”true”>
<jws file=”examples/webservices/complex/ComplexImpl.java” type=”JAXWS”/>
</jwsc>
</target>

<target name=”deploy”>
<wldeploy action=”deploy” name=”${ear.deployed.name}” source=”${ear-dir}” user=”${wls.username}”
password=”${wls.password}” verbose=”true” adminurl=”t3://${wls.hostname}:${wls.port}” targets=”${wls.server.name}”/>
</target>

<target name=”undeploy”>
<wldeploy action=”undeploy” failonerror=”false” name=”${ear.deployed.name}” user=”${wls.username}” password=”${wls.password}” verbose=”true” adminurl=”t3://${wls.hostname}:${wls.port}” targets=”${wls.server.name}”/>
</target>

<target name=”client”>
<clientgen type=”JAXWS” wsdl=”http://${wls.hostname}:${wls.port}/ComplexImpl/ComplexService?WSDL” destDir=”${clientclass-dir}” packageName=”examples.webservices.complex.client”/>
<javac srcdir=”${clientclass-dir}” destdir=”${clientclass-dir}” includes=”**/*.java”/>
<javac srcdir=”src” destdir=”${clientclass-dir}” includes=”examples/webservices/complex/client/**/*.java”/>
</target>

<target name=”run” >
<java fork=”true” classname=”examples.webservices.complex.client.Main” failonerror=”true” >
<classpath refid=”client.class.path”/>
<arg line=”http://${wls.hostname}:${wls.port}/complex/ComplexService”/>
</java>
</target>

</project>

Step7). Now open a command prompt and then set the Environment here …by running “setDomainEnv.sh” or “setWLSEnv.sh” here….then move to the Directory in the command prompt upto the Directory where the “build.xml” is available and then run the ANT build:

C:JavaTestDemo-2-ComplexDataType>ant
.

.

Thanks
Jay SenSharma