Tag: WebServices

Creating JAXWS Service in WebLogic Workshop

Hi,

Jay SenSharma

Jay SenSharma

Here is a simple demo which explains how we can create a Complex JAXWS WebService using WebLogic Workshop.  Most of the instractions are mentioned in the below images, so nothing much to explain.

This example also demonstrates how we can export the JAXWS WebService WAR file from the WebLogic Workshop.

Step1).  Creating a WebService Project.

JAXWS_Workspace_Creation

JAXWS_Workspace_Creation

Creating_Project_In_Workshop

Creating_Project_In_Workshop

Chosing_Webservice_Project

Chosing_Webservice_Project

Other_Project_Facets

Other_Project_Facets

Project_WebModule_Next

Project_WebModule_Next

Step2). Coding BasicStruct.java code.

Creating_SimpleClass

Creating_SimpleClass

BasicStruct

BasicStruct

BasicStruct_Code

BasicStruct_Code

package misc;
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;
	  }
	}

Step3). Creating WebService.

Creating_WebService

Creating_WebService

Creating_ComplexJAXWS_Service

Creating_ComplexJAXWS_Service

Complex_JAXWS_Code

Complex_JAXWS_Code

package ws;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.Oneway;
import javax.jws.soap.SOAPBinding;

import misc.BasicStruct;
@WebService(serviceName="ComplexService",name="ComplexPortType",targetNamespace="http://middlewaremagic")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL,
             parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class ComplexJAXWS {
  @WebMethod()
  @Oneway
  public void echoVoid() {
    System.out.println("ntechoVoid called");
  }

  @WebMethod()
  @WebResult(name="EchoStructReturnMessage", targetNamespace="http://middlewaremagic/docLiteralBare")
  public BasicStruct echoStruct(BasicStruct struct){
    System.out.println("nt echoStruct called");
    return struct;
  }
}

Step4). Exporting  JAXWS Project WAR.

Exporting_WAR_File_For_JAXWS

Exporting_WAR_File_For_JAXWS

Exported_WAR_Location

Exported_WAR_Location

Step5). Running The WebService and Accessing WSDL: http://localhost:7001/TestJAXWSProject/ComplexService?wsdl

Running_JAXWS_On_Server

Running_JAXWS_On_Server

Choose_Correct_Server

Choose_Correct_Server

Chosing_Deployment_Domain

Chosing_Deployment_Domain

  <?xml version="1.0" encoding="UTF-8" ?>
- <!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.3-07/10/2008 08:41 PM(bt).
  -->
- <!--  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.3-07/10/2008 08:41 PM(bt).
  -->
- <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://middlewaremagic" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://middlewaremagic" name="ComplexService">
- <types>
- <xsd:schema>
  <xsd:import namespace="http://middlewaremagic/docLiteralBare" schemaLocation="http://localhost:7001/TestJAXWSProject/ComplexService?xsd=1" />
  </xsd:schema>
- <xsd:schema>
  <xsd:import namespace="http://middlewaremagic" schemaLocation="http://localhost:7001/TestJAXWSProject/ComplexService?xsd=2" />
  </xsd:schema>
  </types>
- <message name="echoVoid">
  <part name="parameters" element="tns:echoVoid" />
  </message>
- <message name="echoStruct">
  <part name="parameters" element="tns:echoStruct" />
  </message>
- <message name="echoStructResponse">
  <part name="parameters" element="tns:echoStructResponse" />
  </message>
- <portType name="ComplexPortType">
- <operation name="echoVoid">
  <input message="tns:echoVoid" />
  </operation>
- <operation name="echoStruct">
  <input message="tns:echoStruct" />
  <output message="tns:echoStructResponse" />
  </operation>
  </portType>
- <binding name="ComplexPortTypePortBinding" type="tns:ComplexPortType">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="echoVoid">
  <soap:operation soapAction="" />
- <input>
  <soap:body use="literal" />
  </input>
  </operation>
- <operation name="echoStruct">
  <soap:operation soapAction="" />
- <input>
  <soap:body use="literal" />
  </input>
- <output>
  <soap:body use="literal" />
  </output>
  </operation>
  </binding>
- <service name="ComplexService">
- <port name="ComplexPortTypePort" binding="tns:ComplexPortTypePortBinding">
  <soap:address location="http://localhost:7001/TestJAXWSProject/ComplexService" />
  </port>
  </service>
  </definitions>

.

.

Thanks

Jay SenSharma


Debugging WebLogic WebService Using SOAPUI

Hi,

Jay SenSharma

Jay SenSharma

Here is a very simple demonstration of Debugging WebService related issues using one of the Best Debugging utility “SOAPUI”. I have found this tool as a Best tool to debug, analyze and understand WebServices. We can download SOAPUI from the following link: http://www.eviware.com/Download-soapUI/download-soapui-pro.html . I am using the trial verson of this tool. I have downloaded the Windows version of this installer which is in ZIP format (soapui-pro-3.5.1-windows-bin.zip) …so Just download it …extract it and Start Using it.

NOTE: all the features will not available with this Utiltiy without having a Valid License.

In the following demonstration we will create a Simplest WebService and then we will use the SOAPUI utility to send the request to the WebService as well as we will get the response back from the Serice inside the Great SOAPUI Editor.

Step1). Create a Directory some where in your File System “C:SOAP_UI” download and extract the “soapui-pro-3.5.1-windows-bin.zip” here. You will see the following Directory structutre now:

Step2). Now we are going to start a Simplest Test Webservice Creation … Create a Directory “TestWebService” inside “C:SOAP_UI”

Step3). Now create “src” directory inside “C:SOAP_UITestWebService”

Step4). Now start writing the WebService “HelloWorldImpl.java” inside “C:SOAP_UITestWebServicesrc” like follwoing:

package ws;
import javax.jws.WebService;
@WebService(name="HelloWorldPortType", serviceName="HelloWorldService")
public class HelloWorldImpl
{
public String sayHelloWorld(String message)
{
System.out.println("sayHelloWorld:" + message);
return "Here is the message: '" + message + "'";
}
}

Step5). Now create a “TestClient.java” program which will work as a webserice client.

package client;
public class TestClient
{
public static void main(String ar[]) throws Exception
{
HelloWorldService service=new HelloWorldService_Impl();
HelloWorldPortType port=service.getHelloWorldPortTypeSoapPort();
String result=port.sayHelloWorld(ar[0]);
System.out.println("nnt WebService Returned: "+result);
}
}

Step6). Now create a “build.xml” Ant script inside “C:SOAP_UITestWebService” like following to build and deploy the WebService and to run the testClient in one GO…

<project name="webservices-hello_world" 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="helloWorldEar" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/helloWorldEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses"/>

<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,run" />

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

<target name="build-service">
    <jwsc srcdir="src" destdir="${ear-dir}">
     <jws file="HelloWorldImpl.java" />
    </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" name="${ear.deployed.name}"
          failonerror="false" user="${wls.username}" password="${wls.password}"
          verbose="true" adminurl="t3://${wls.hostname}:${wls.port}"
          targets="${wls.server.name}" />
</target>

<target name="client">
<clientgen  wsdl="http://${wls.hostname}:${wls.port}/HelloWorldImpl/HelloWorldImpl?WSDL"
            destDir="${clientclass-dir}"
            packageName="client"/>
   <javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
   <javac srcdir="src" destdir="${clientclass-dir}" includes="client/**/*.java"/>
</target>

<target name="run">
    <javac srcdir="src" destdir="${clientclass-dir}" includes="TestClient.java"/>
    <java classname="client.TestClient" fork="true" failonerror="true" >
         <classpath refid="client.class.path"/>
         <arg line="'Jay SenSharma'" />
    </java>
</target>
</project>

Step7). Now run the “setWlsEnv.cmd” to set the CLASSPATH and PATH properly in our command prompt…

running the setWLSEnv.cmd to set CLASSPATH/PATH

running the setWLSEnv.cmd to set CLASSPATH/PATH

Step8). Run the ANT script to build, deploy and run the WebService in one GO…

Building WebService using ANT Script for SOAP UI Test

Building WebService using ANT Script for SOAP UI Test

Running WebService before testing it using SOAPUI

Step9). Now please follow the below Steps in order to test/debug the WebService from the SOAP UI …

setting JAVA_HOME before starting SOAPUI

starting SOAPUI using the "soapui-pro.bat" file

Creating a SOAPUI Project --1

Creating a SOAPUI Project--2

Creating a SOAPUI Project--2

Creating a SOAP Request in SOAPUI

Creating a SOAP Request in SOAPUI

sending SOAPUI created SOAP Request

sending SOAPUI created SOAP Request

Getting SOAP Response from WebService in SOAPUI editor

Above is just a basic introduction of SOAP UI …you can explore it more.
.
.
Thanks
Jay SenSharma


Copyright © 2010-2012 Middleware Magic. All rights reserved. |