WebService

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


UserName Token In JAXWS WebService

Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple demonstration of using the UserName Token in WebLogic JAXWS WebServices.

Step1). Create a Directory  “F:DELETEAuthXML_UserName_Token” where we can place all our application sources…

Step2). Now we need to create our own UserNameToken.xml file. In order to do that Please create a Directory “policies” in the current directory “F:DELETEAuthXML_UserName_Token” and place the following “UsernameToken.xml

<?xml version="1.0"?>
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512">
<sp:SupportingTokens>
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SupportingTokens>
</wsp:Policy>
Step3). Now In the “F:DELETEAuthXML_UserName_Token” Directory Write your WebService “SecureHelloWorldImpl.java
package examples.webservices.security_jws;
import weblogic.jws.Policies;
import weblogic.jws.Policy;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;

@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
@Policies({@Policy(uri="policy:UsernameToken.xml")})
@WebService(name="SecureHelloWorldPortType",serviceName="SecureHelloWorldService")
public class SecureHelloWorldImpl
{
@WebMethod()
public String sayHello(String s) {
return "JAXWS Service Says ... Hello " + s;
}
}
Step4). Now write the WebService Client in “F:DELETEAuthXML_UserName_Token” the Client name is “SecureHelloWorldClient.java
package client;
import examples.webservices.security_jws.client.*;
import java.util.*;
import javax.xml.ws.BindingProvider;
import weblogic.wsee.security.unt.ClientUNTCredentialProvider;
import weblogic.xml.crypto.wss.provider.CredentialProvider;
import weblogic.xml.crypto.wss.WSSecurityContext;
public class SecureHelloWorldClient {
public static void main(String[] args) throws Throwable {
String USERNAME = "weblogic";
String PASSWORD = "weblogic";
SecureHelloWorldService service=new SecureHelloWorldService();
SecureHelloWorldPortType port=service.getSecureHelloWorldPortTypePort();

//////////NOT TRY TO COMMENT OUT THE BELOW 8 Lines....Client Will Fail With Security Header Missing Exception
System.out.println("nnt-----1 Port: "+port);
BindingProvider bindingProvider = (BindingProvider) port;
Map<String,Object> rc = (Map<String,Object>)bindingProvider.getRequestContext();
List<CredentialProvider> credProviders = new ArrayList<CredentialProvider>();
credProviders.add(new ClientUNTCredentialProvider(USERNAME.getBytes(),PASSWORD.getBytes()));
rc.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
rc.put(BindingProvider.USERNAME_PROPERTY, USERNAME);
rc.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);;
/////////////////////////////////////////////////////////////
String response = port.sayHello("World");
System.out.println("response = " + response);
}
}
Step 5). Now we need to write the “build.xml” so build the Service and the Client…
<project name="webservices-security_jws" default="all" basedir=".">
<!-- set global properties for this build -->
<property name="ws.file" value="SecureHelloWorldImpl" />
<property name="ear.dir" value="${basedir}/webservicesSecurityeEar" />
<property name="client.dir" value="${basedir}/webservicesSecurity_client" />
<property name="cert-dir" value="C:replicationcerts" />
<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" />

<path id="client.class.path">
<pathelement path="${client.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" />
<target name="all" depends="clean,server,zip,deploy,client,run" />

<!-- Cleaning the WorkSpace -->
<target name="build" depends="clean,server,client" />
<target name="clean">
<delete dir="${ear.dir}"/>
<delete dir="${client.dir}"/>
</target>

<!-- To Build the WebService -->
<target name="server">
<mkdir dir="${ear.dir}"/>
<jwsc  srcdir="${basedir}"
       destdir="${ear.dir}"
       classpath="${java.class.path}"
       fork="true"
       keepGenerated="true"
       deprecation="${deprecation}"
       debug="true">
      <jws file="${ws.file}.java"  type="JAXWS"/>
</jwsc>
</target>

<!-- To add the Policy File Inside the WebService WAR file -->
<target name="zip">
<zip destfile="${ear.dir}/${ws.file}.war" update="true">
<zipfileset dir="." prefix="WEB-INF">
<include name="policies/*.xml"/>
</zipfileset>
</zip>
</target>

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

<!-- Redeploy Application -->
<target name="redeploy">
<wldeploy action="redeploy"
          source="${ear.dir}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          failonerror="${failondeploy}"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
</target>

<!-- To Generate the Client Side Artifacts -->
<target name="client">
<mkdir dir="${client.dir}"/>
<clientgen type="JAXWS"
           wsdl="http://localhost:7001/SecureHelloWorldImpl/SecureHelloWorldService?WSDL"
           destDir="${client.dir}"
           classpath="${java.class.path}"
           packageName="examples.webservices.security_jws.client"/>
<javac  srcdir="${client.dir}" destdir="${client.dir}" classpath="${java.class.path}" includes="examples/webservices/security_jws/client/**/*.java"/>
<javac srcdir="${basedir}" destdir="${client.dir}" classpath="${java.class.path};${client.dir}" includes="SecureHelloWorldClient.java"/>
</target>

<!-- To Run the Client Program -->
<target name="run" >
<java fork="true" classname="client.SecureHelloWorldClient" failonerror="false" >
     <classpath refid="client.class.path"/>
     <arg line="weblogic weblogic" />
</java>
</target>
</project>

Step6). Now open a Command prompt and then run “setWLSEnv.cmd” or “setWLSEnv.sh”  and then just enter “ant” in the command prompt…
.
.
Thanks
Jay SenSharma


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