Tag: WebService

Why and How to use Apache CXF Service in WebLogic 12c ?

Hi,

Why and how to deploy Apache CXF based web service on WebLogic? This is the question we are going to focus as part of this article. First lets see what is apache cxf. Apache CXF implements the JAX-WS APIs which make building web services easy. It allows us generating WSDL from Java classes and generating Java classes from WSDL, Provider API which allows you to create simple messaging receiving server endpoints, Dispatch API which allows you to send raw XML messages to server endpoints.

Apache CXF provides support for the Spring 2.0 XML syntax support and integration. It also enables the development of RESTful services via annotations using the HTTP Binding. The Apache CXF uses Aegis Databinding (2.0.x) which has it;s own databinding library that makes development of code-first web services incredibly easy. The Apache CXF also provides support for variety of WS specifications like WS-Addressing, WS-Policy, WS-ReliableMessaging and WS-Security.

What this demo is about ?

As part of this demo we will see how to use Apache CXF 3.1.4 based WebService on latest WebLogic 12.2.1 (12c). While running this demo we will learn about the following things:

1. How to develop a CXF based WebService using top down approach. Means generating WebService WSDL first and then Creating WebService artifacts (like wrappers, Service interface) from it.

2. How to use the “cxf-codegen-plugin” Maven plugin to generate CXF service artifacts from WSDL.

3. How to deploy the CXF based WebService on WebLogic using WebLogic 12.2.1 using maven plugin “weblogic-maven-plugin”. If you get following kind of error while using this plugin then refer to the article How to use WebLogic 12c provided Maven Synchronization Plug-In ?

4. Invoking the deployed CXF web service using a simple Curl Based Client.

Developing CXF WebService from WSDL

Step-1). First create a directory some where in our filesystem where we will be keeping our projects.

 $ mkdir WebLogic12c_CXF_Demo_Maven

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/resources

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic 

Step-2). Lets start developing a simple WSDL “helloworld.wsdl” and place it inside the “WebLogic12c_CXF_Demo_Maven/src/main/resources/” as following:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" 
				  xmlns:impl="http://middlewaremagic.com" 
				  xmlns:intf="http://middlewaremagic.com" 
				  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
			  	  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
				  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
				  targetNamespace="http://middlewaremagic.com">

 <wsdl:types>
  <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://middlewaremagic.com">
   <element name="sayHello">
    <complexType>
     <sequence>
      <element name="name" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="sayHelloResponse">
    <complexType>
     <sequence>
      <element name="sayHelloReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="sayHelloResponse">
      <wsdl:part element="impl:sayHelloResponse" name="parameters">
      </wsdl:part>
   </wsdl:message>

   <wsdl:message name="sayHelloRequest">
      <wsdl:part element="impl:sayHello" name="parameters">
      </wsdl:part>
   </wsdl:message>

   <wsdl:portType name="HelloWorld">
      <wsdl:operation name="sayHello">
         <wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest">
       </wsdl:input>
         <wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse">
       </wsdl:output>
      </wsdl:operation>
   </wsdl:portType>
   
   <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="sayHello">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="sayHelloRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="sayHelloResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   
   <wsdl:service name="HelloWorldService">
      <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
         <wsdlsoap:address location="http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld"/>
      </wsdl:port>
   </wsdl:service>   
   
</wsdl:definitions>

Step-3). Now lets write a simple “pom.xml” file inside the “WebLogic12c_CXF_Demo_Maven” directory as following where we will use the “cxf-codegen-plugin” plugin’s “wsdl2java” goal to generate the WebService artifacts like helper classes, implementation class and the webservice interface..etc


<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
         
    <modelVersion>4.0.0</modelVersion>
    <groupId>middleware.magic</groupId>
    <artifactId>WebLogic12c_CXF_Demo</artifactId>
    <packaging>war</packaging>
    <name>WSDL first demo on WenLogic 12.2.1</name>
    <version>1.0</version>
    <description>A very simple demo showing how to develop and use a CXF based WebService on WebLogic 12.2.1</description>

    <properties>
        <cxf.version>3.1.4</cxf.version>
        <cxf.xjc-utils.version>3.0.5</cxf.xjc-utils.version>
        <spring.version>4.1.4.RELEASE</spring.version>
    </properties>
    
    <build>
        <defaultGoal>install</defaultGoal>
        <finalName>WebLogic_CXF_Demo</finalName>   <!-- WAR name -->
        
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                        <webResources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>*.wsdl</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>src/main/resources/helloworld.wsdl</wsdl>  <!-- Where the original WSDL is present -->
                                    <wsdlLocation>WEB-INF/wsdl/helloworld.wsdl</wsdlLocation>  <!-- Where to place the WSDL -->
                                    <bindingFiles>
                                        <bindingFile>src/main/resources/binding.xml</bindingFile>
                                    </bindingFiles>
                                    <extraargs>
                                        <extraarg>-impl</extraarg>  <!-- will generate a dummy  webservice implementation -->
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>    


            <plugin> 
              <groupId>com.oracle.weblogic</groupId> 
              <artifactId>weblogic-maven-plugin</artifactId> 
              <version>12.2.1-0-0</version> 
              <configuration> 
                  <adminurl>t3://localhost:7001</adminurl>
                  <user>weblogic</user> 
                  <password>weblogic1</password> 
                  <upload>true</upload> 
                  <action>deploy</action> 
                  <remote>false</remote> 
                  <verbose>true</verbose> 
                  <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source> 
                  <name>${project.build.finalName}</name> 
              </configuration> 
           </plugin>                   
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf.xjc-utils</groupId>
            <artifactId>cxf-xjc-runtime</artifactId>
            <version>${cxf.xjc-utils.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
       </dependency>
    </dependencies>
</project>

Step-4). Now if users want to provide their own custom binding then they can add the “binding.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/resources/” directory as following, Here i am putting a dummy file without having much information in it:

<jaxws:bindings wsdlLocation="helloworld.wsdl"
          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
          
		<jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema">
			<jxb:globalBindings>
			</jxb:globalBindings>
		</jaxws:bindings>
		
</jaxws:bindings>

Step-5). Now lets run the maven to build the above project which will internally read the WSDL and generate the WebService Artifacts along with a dummy implementation class which later we will modify according to our need. So open a terminal and run the following commands in order to set the maven properly.
For Unix Based OS

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ cd /WebLogic12c_CXF_Demo_Maven
$ mvn clean install

For Windows Based OS

$ set M2_HOME=C:\PATH\TO\apache_maven_3.2.3
$ set JAVA_HOME=C:\PATH\TO\jdk1.8.0_60
$ set PATH=%JAVA_HOME%/bin;C:\PATH\TO\apache_maven_3.2.3\bin;%PATH%

$ cd C:\WebLogic12c_CXF_Demo_Maven
$ mvn clean install 

As soon as you will run the “mvn clean install” the web service artifacts will be generated as following:

$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12c_CXF_Demo ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target
[INFO] 
[INFO] --- cxf-codegen-plugin:3.1.4:wsdl2java (generate-sources) @ WebLogic12c_CXF_Demo ---
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -d /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf -b file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/binding.xml -impl -verbose -wsdlLocation WEB-INF/helloworld.wsdl file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/helloworld.wsdl
wsdl2java - Apache CXF 3.1.4

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebLogic12c_CXF_Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebLogic12c_CXF_Demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebLogic12c_CXF_Demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1:war (default-war) @ WebLogic12c_CXF_Demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebLogic12c_CXF_Demo] in [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Processing war project
[INFO] Copying webapp webResources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources] to [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/webapp]
[INFO] Webapp assembled in [55 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12c_CXF_Demo ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.320 s
[INFO] Finished at: 2015-11-14T11:52:19+05:30
[INFO] Final Memory: 23M/245M
[INFO] ------------------------------------------------------------------------

Updating WebService Impl and deploying on WLS12c

Step-6). After running the above “cxf-codegen-plugin” task “wsdl2java” it will create some artifacts (WebService interface and helper and impementation classes) from the WSDL. We can see that the following kind of web service implementation class “HelloWorldImpl.java” would have been generated inside the “WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic”


/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.middlewaremagic;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 3.1.4
 * 2015-11-14T11:52:18.278+05:30
 * Generated source version: 3.1.4
 * 
 */

@javax.jws.WebService(
                      serviceName = "HelloWorldService",
                      portName = "HelloWorld",
                      targetNamespace = "http://middlewaremagic.com",
                      wsdlLocation = "WEB-INF/helloworld.wsdl",
                      endpointInterface = "com.middlewaremagic.HelloWorld")
                      
public class HelloWorldImpl implements HelloWorld {

    private static final Logger LOG = Logger.getLogger(HelloWorldImpl.class.getName());

    /* (non-Javadoc)
     * @see com.middlewaremagic.HelloWorld#sayHello(java.lang.String  name )*
     */
    public java.lang.String sayHello(java.lang.String name) { 
        LOG.info("Executing operation sayHello");
        System.out.println(name);
        try {
            java.lang.String _return = "";
            return _return;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

}

Step-7). As we see a dummy WebService implementation class is generated as above by CXF, Hence lets customize it base don our need. Lets Copy the above file “HelloWorldImpl.java” from “WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic” to “WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic”

 $ cp -f WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic/HelloWorldImpl.java  WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic

Once we copied the above file then edit the “pom.xml” file to make sure that the following tag is commented or removed. So that when we do the “mvn clean build”

        <extraargs>
            <!-- <extraarg>-impl</extraarg> -->  <!-- REMOVE THIS LINE  -->
            <extraarg>-verbose</extraarg>
        </extraargs>

Step-8). Now lets edit the “WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic/HelloWorldImpl.java” file and then provide our own implementation.

package com.middlewaremagic;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@javax.jws.WebService(
                      serviceName = "HelloWorldService",
                      portName = "HelloWorld",
                      targetNamespace = "http://middlewaremagic.com",
                      wsdlLocation = "WEB-INF/helloworld.wsdl",
                      endpointInterface = "com.middlewaremagic.HelloWorld")
                      
public class HelloWorldImpl implements HelloWorld {

    private static final Logger LOG = Logger.getLogger(HelloWorldImpl.class.getName());

    public java.lang.String sayHello(java.lang.String name) { 
        System.out.println("\n\t [HelloWorld_Impl] sayHello("+name+") invoked.");
        return "Hello World !!! Mr. "+ name + " at " + new java.util.Date();
    }
}

Step-9). Before deploying the above application lets make sure to add the “web.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF/” as following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"> 
    <display-name>wls_cxf_demo</display-name>
    <servlet>
        <servlet-name>cxf</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

Step-10). The most important part now, is to add the following kind of CXF specific “cxf-servlet.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF/” as following:

<?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:jaxws="http://cxf.apache.org/jaxws"
      xmlns:soap="http://cxf.apache.org/bindings/soap"
      xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
             http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:endpoint xmlns:hello="http://middlewaremagic.com/"
            id="HelloWorldHTTP" address="/HelloWorld"
            serviceName="hello:HelloWorldService" endpointName="hello:HelloWorldPort"
            implementor="com.middlewaremagic.HelloWorldImpl">
    </jaxws:endpoint>

</beans>

Step-11). Now lets do a clean build again with the “weblogic:deploy” plugin to deploy it on WebLogic.



$ mvn clean install weblogic:deploy


[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12c_CXF_Demo ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target
[INFO] 
[INFO] --- cxf-codegen-plugin:3.1.4:wsdl2java (generate-sources) @ WebLogic12c_CXF_Demo ---
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -d /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf -b file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/binding.xml -verbose -wsdlLocation WEB-INF/wsdl/helloworld.wsdl file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/helloworld.wsdl
wsdl2java - Apache CXF 3.1.4

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebLogic12c_CXF_Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebLogic12c_CXF_Demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebLogic12c_CXF_Demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1:war (default-war) @ WebLogic12c_CXF_Demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebLogic12c_CXF_Demo] in [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Processing war project
[INFO] Copying webapp webResources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources] to [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/webapp]
[INFO] Webapp assembled in [66 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12c_CXF_Demo ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:deploy (default-cli) @ WebLogic12c_CXF_Demo ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name WebLogic_CXF_Demo -source /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war -upload -verbose -adminurl t3://localhost:7001
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name WebLogic_CXF_Demo -source /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war -upload -verbose -adminurl t3://localhost:7001
<Nov 14, 2015 12:51:48 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, WebLogic_CXF_Demo [archive: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war], to configured targets.> 
Task 6 initiated: [Deployer:149026]deploy application WebLogic_CXF_Demo on AdminServer.
Task 6 completed: [Deployer:149026]deploy application WebLogic_CXF_Demo on AdminServer.
Target state: deploy completed on Server AdminServer

Target Assignments:
+ WebLogic_CXF_Demo  AdminServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.753 s
[INFO] Finished at: 2015-11-14T12:51:50+05:30
[INFO] Final Memory: 38M/502M
[INFO] ------------------------------------------------------------------------

Running Curl Based WebSerivce Client

Step-12). As the web service is deployed hence lets try accessing the WSDL and the service endpoint information from WLS server by accessing the following URL:

http://localhost:7001/WebLogic_CXF_Demo/services
And
http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld?wsdl

Step-13). Now lets create a SOAP request XML which we will send to the web service. Hence write the “soap_request.xml” file inside the any directory of your choice like “WebLogic12c_CXF_Demo_Maven//client”

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mid="http://middlewaremagic.com">
   <soapenv:Header/>
   <soapenv:Body>
      <mid:sayHello>
         <mid:name>MiddlewareMagic!!!</mid:name>
      </mid:sayHello>
   </soapenv:Body>
</soapenv:Envelope>

Step-14). Also lets write a simple CURL based command which will send the above SOAP request to the WebService endpoint. Write the following file “request.sh” inside the “WebLogic12c_CXF_Demo_Maven/client”

## A simple "curl" based SOAP Request 
## Which will invoke the HelloWorld Service:

request=`cat soap_request.xml`
curl -s -H "Content-Type: text/xml" -d "$request" http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld
echo

Step-15). Run the client to access the WebService and to receive the response.

  $ cd WebLogic12c_CXF_Demo_Maven/client

  $ chmod 755 ./request.sh 

  $ ./request.sh

        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
               <sayHelloResponse xmlns="http://middlewaremagic.com">
                   <sayHelloReturn>Hello World !!! Mr. MiddlewareMagic!!! at Sat Nov 14 12:59:32 IST 2015</sayHelloReturn>
               </sayHelloResponse>
            </soap:Body>
       </soap:Envelope>

.
.
Source code for this demo is present in:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/WebService/WebLogic12c_CXF_Demo_Maven

.
.
Regards
Jay SenSharma


SOAP Attachment using JAXWS Style of WebService

Hi,

Jay SenSharma

Jay SenSharma

Based on the comment/query of one of our subscriber “Mauriciohttp://middlewaremagic.com/weblogic/?page_id=131#comment-4208 , Here we are going to see a very simple demonstration of using the SOAP Attachment on JAXWS Style of WebServices. Using following sample we can upoad an attachment on WebLogic DOMAIN_HOME directory (or in any other location defined in our WebService class).

Step1). Create a Directory somewhere in your file system like “C:SOAP_Attachment”

Step2). Now create a directory with name “src” inside “C:SOAP_Attachment”

Step3). Write the following kind of WebService “AttachmentService_Impl.java” inside “C:SOAP_Attachmentsrc”

package ws;
import java.io.*;
import java.util.*;
import javax.activation.*;   //DataHandler, FileDataSource

//XML Related APIs
import javax.xml.transform.*;   // Source, Transformer, TransformerFactory
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;

//WebService APIs
import javax.jws.*;
import javax.jws.soap.SOAPBinding;

@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL,parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

public class AttachmentService_Impl
	{
	   public DataHandler dataHandler=null;
       public String attachAnyFile(DataHandler dataHandler, String file)
		   {
		          String filename="";
             try {
				    //DataHandler dataHandler=new DataHandler(fileDataSource);
					File f=new File(file);
					filename=f.getName();
                    System.out.println("nt Writing to File /" + filename);
                    BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(filename));
                    BufferedInputStream bin = new BufferedInputStream(dataHandler.getInputStream());

		            byte[] buffer = new byte[256];
				    while (true)
					{
						int bytesRead = bin.read(buffer);
		                if (bytesRead == -1)
				            break;
						bout.write(buffer, 0, bytesRead);
					}
		            bin.close();
				    bout.close();
		        }
			   catch (Exception e)
				{
					System.out.println("nt [AttachmentService_Impl] Exception Occured While Writing in File : "+e);
					return e.toString();
				}
               return ("nt File Attachment Completed Succesfully " + filename + "t at " + new Date());
            }
}

Step4). Now write the WebService Client program inorder to send the Attachment to WebService. “Client.java” inside “C:SOAP_Attachmentsrc”

package client;
import javax.activation.DataHandler;
import javax.activation.*;
import java.io.*;
public class Client
{
	public static void main(String[] ar) throws Exception
	{
		System.out.println("ntstart client");
		AttachmentServiceImplService service=new AttachmentServiceImplService();
		AttachmentServiceImpl port=service.getAttachmentServiceImplPort();

        String fileName_WithPath=ar[0];
		long length=new java.io.File(ar[0]).length();
		FileDataSource fileDataSource = new FileDataSource(fileName_WithPath);
        DataHandler dataHandler = new DataHandler(fileDataSource);
        System.out.println("ntCalling service to send a file from a customer...");

  	    BufferedInputStream bin = new BufferedInputStream(dataHandler.getInputStream());
		byte b[]=new byte[(int)length];
		bin.read(b);
        String result = port.attachAnyFile(b,fileName_WithPath);
        System.out.println("nt Result From Service: "+result);
        System.out.println("ntend client");
	}
}

Step5). Now we will write the following ANT Sctipt to completely Build, Deploy and Run the Client. “build.xml” inside “C:SOAP_Attachment” directory.

<project name="DwAttach" 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.deploy.name" value="SOAP_JAXWS_AttachmentEar" />
 <property name="client-output" value="output" />
 <property name="tempjar-dir" value="${client-output}/tempjardir" />
 <property name="ear.dir" value="${client-output}/SOAP_JAXWS_AttachmentEar" />
 <property name="clientclass-dir" value="${client-output}/clientclasses" />

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

 <taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
 <taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />

 <target name="all" depends="clean,build-service,deploy-attach,client,run" />
 <target name="clean" depends="undeploy-attach">
	 <delete dir="${client-output}"/>
 </target>

 <target name="build-service">
	  <javac srcdir="src" destdir="src" classpath="${client.class.path}" includes="*Attach*.java"/>
	  <jwsc srcdir="src" destdir="${ear.dir}" debug="true" classpathref="client.class.path">
	       <jws file="AttachmentService_Impl.java" type="JAXWS" />
	  </jwsc>
 </target>

 <target name="deploy-attach">
  <wldeploy action="deploy" name="${ear.deploy.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-attach">
 <wldeploy action="undeploy" name="${ear.deploy.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}/AttachmentService_Impl/AttachmentService_ImplService?WSDL"
                destDir="${clientclass-dir}"  packageName="client" type="JAXWS"/>
             <javac   debug="true"  srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
             <!-- <javac  debug="true"  srcdir="client" destdir="${clientclass-dir}" includes="client/**/*.java"/>  -->
 </target>

 <target name="run">
      <javac srcdir="src" destdir="${clientclass-dir}" classpath="${client.class.path}" includes="Client.java"/>
      <java classname="client.Client"   fork="true"  failonerror="true">
               <classpath refid="client.class.path"/>
			   <jvmarg value="-Xmx512m" />
               <arg line="Cant_Stop_Dancing.mp3" /> <!-- Name of the file for SOAP Attachment -->
      </java>
 </target>
</project>

Step6). Open a command prompt and then run “. ./setWLSEnv.sh” to set the Environment (classpath/path) , then run the ant script to build, Deploy and run the WebService Client. like following


C:SOAP_Attachment>ant
Buildfile: build.xml

undeploy-attach:
 [wldeploy] weblogic.Deployer -verbose -noexit -name SOAP_JAXWS_AttachmentEar -targets AdminServer -adminurl t3://localhost:7001 -user weblo
gic -password ******** -undeploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -name SOAP_JAXWS_AttachmentEar -targets AdminServer -adminurl t3://loc
alhost:7001 -user weblogic -undeploy
 [wldeploy] <Jun 12, 2011 4:47:27 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application, SOAP_JAX
WS_AttachmentEar [archive: null], to AdminServer .>
 [wldeploy] Task 8 initiated: [Deployer:149026]remove application SOAP_JAXWS_AttachmentEar on AdminServer.
 [wldeploy] Task 8 completed: [Deployer:149026]remove application SOAP_JAXWS_AttachmentEar on AdminServer.
 [wldeploy] Target state: undeploy completed on Server AdminServer
 [wldeploy]

clean:
   [delete] Deleting directory C:SOAP_Attachmentoutput

build-service:
    [javac] Compiling 1 source file to C:SOAP_Attachmentsrc
     [jwsc] JWS: processing module /AttachmentService_Impl
     [jwsc] Parsing source files
     [jwsc] Parsing source files
     [jwsc] 1 JWS files being processed for module /AttachmentService_Impl
     [jwsc] JWS: C:SOAP_AttachmentsrcAttachmentService_Impl.java Validated.
     [jwsc] Processing 1 JAX-WS web services...
     [jwsc] warning: Annotation types without processors: [javax.xml.bind.annotation.XmlRootElement, javax.xml.bind.annotation.XmlAccessorTy
pe, javax.xml.bind.annotation.XmlType, javax.xml.bind.annotation.XmlElement]
     [jwsc] 1 warning
     [jwsc] Compiling 3 source files to C:DOCUME~1DELLUS~1LOCALS~1Temp_6vmlr8
     [jwsc] Building jar: C:SOAP_AttachmentoutputSOAP_JAXWS_AttachmentEarAttachmentService_Impl.war
     [jwsc] Created JWS deployment outputFile: C:SOAP_AttachmentoutputSOAP_JAXWS_AttachmentEarAttachmentService_Impl.war
     [jwsc] [EarFile] Application File : C:SOAP_AttachmentoutputSOAP_JAXWS_AttachmentEarMETA-INFapplication.xml
[AntUtil.deleteDir] Deleting directory C:DOCUME~1DELLUS~1LOCALS~1Temp_6vmlr8

deploy-attach:
 [wldeploy] weblogic.Deployer -verbose -noexit -name SOAP_JAXWS_AttachmentEar -source C:SOAP_AttachmentoutputSOAP_JAXWS_AttachmentEar -ta
rgets AdminServer -adminurl t3://localhost:7001 -user weblogic -password ******** -deploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -name SOAP_JAXWS_AttachmentEar -source C:SOAP_AttachmentoutputSOAP_
JAXWS_AttachmentEar -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -deploy
 [wldeploy] <Jun 12, 2011 4:47:33 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, SOAP_JAXWS
_AttachmentEar [archive: C:SOAP_AttachmentoutputSOAP_JAXWS_AttachmentEar], to AdminServer .>
 [wldeploy] Task 9 initiated: [Deployer:149026]deploy application SOAP_JAXWS_AttachmentEar on AdminServer.
 [wldeploy] Task 9 completed: [Deployer:149026]deploy application SOAP_JAXWS_AttachmentEar on AdminServer.
 [wldeploy] Target state: deploy completed on Server AdminServer
 [wldeploy]
 [wldeploy] Target Assignments:
 [wldeploy] + SOAP_JAXWS_AttachmentEar  AdminServer

client:
[clientgen]
[clientgen] *********** jax-ws clientgen attribute settings ***************
[clientgen]
[clientgen] wsdlURI: http://localhost:7001/AttachmentService_Impl/AttachmentService_ImplService?WSDL
[clientgen] packageName : client
[clientgen] destDir : C:SOAP_Attachmentoutputclientclasses
[clientgen]
[clientgen] *********** jax-ws clientgen attribute settings end ***************
[clientgen] Consider using <depends>/<produces> so that wsimport won't do unnecessary compilation
[clientgen] parsing WSDL...

[clientgen] generating code...

[clientgen] compiling code...

[clientgen] Note: C:SOAP_AttachmentoutputclientclassesclientAttachmentServiceImplService.java uses unchecked or unsafe operations.
[clientgen] Note: Recompile with -Xlint:unchecked for details.

run:
    [javac] Compiling 1 source file to C:SOAP_Attachmentoutputclientclasses

          start client

          Calling service to send a file from a customer...

           Result From Service:
           File Attachment Completed Succesfully Cant_Stop_Dancing.mp3     at Sun Jun 12 16:47:40 IST 2011

          end client

all:

BUILD SUCCESSFUL
Total time: 14 seconds
C:SOAP_Attachment>

Step7). NOTE: as soon as you will run the above sample …you will find that the Attachment is created inside the $DOMAIN_HOME of your WebLogic Server. The Path of Attachement creation on the server side can be defined in the WebService program in the following line:

BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(filename));
Example:
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(“/home/userone/”+filename));
OR
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(“C:/Attachements/”+filename));
.
.
Thanks
Jay SenSharma


Creating a JAXWS ComplexType WebService Using Top to Bottom Approach

Hi,

Jay SenSharma

Jay SenSharma

Based on the query of one of Our Magic Subscriber “Mauricio” we are going to see how we can create a JAXWS WebService using Contract First (from WSDL) mechanism.  So basically in Top to Bottom approach (Contract First Approach). We already have an existing WSDL and based on that we want to create a WebService.  WebLogic provides a best utility to achieve the same. The utility is called as  “weblogic.wsee.tools.anttasks.WsdlcTask” using this utility we can create any kind of WebService from a WSDL just by specifying type=”JAXWS”  or  type=”JAXRPC” as an attribute to the above ANT task.

Suppose we already have a contract (WSDL) like following  “ComplexImpl.wsdl” which internally can contain some Complex Data Types as well… The Following WSDL contains a Complex Datatype as “BasicStruct

==============>

Step1). Create a directory somewhere in your file system like :   “/demos/TopDown” and then place the above WSDL inside this directory.

<?xml version="1.0" encoding="UTF-8"?>
<s0:definitions name="ComplexServiceDefinitions" targetNamespace="http://example.org" xmlns="" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://example.org" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/">
  <s0:types>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://example.org" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://example.org" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:import namespace="java:examples.webservices.complex"/>
      <xs:element name="echoComplexType">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="struct" type="java:BasicStruct" xmlns:java="java:examples.webservices.complex"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="echoComplexTypeResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="EchoStructReturnMessage" type="java:BasicStruct" xmlns:java="java:examples.webservices.complex"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="echoInt">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="IntegerInput" type="xs:int"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="echoIntResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="IntegerOutput" type="xs:int"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="java:examples.webservices.complex" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://example.org" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="BasicStruct">
        <xs:sequence>
          <xs:element minOccurs="1" name="IntValue" nillable="false" type="xs:int"/>
          <xs:element minOccurs="1" name="StringValue" nillable="true" type="xs:string"/>
          <xs:element maxOccurs="unbounded" minOccurs="0" name="StringArray" nillable="true" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
  </s0:types>
  <s0:message name="echoComplexType">
    <s0:part element="s1:echoComplexType" name="parameters"/>
  </s0:message>
  <s0:message name="echoComplexTypeResponse">
    <s0:part element="s1:echoComplexTypeResponse" name="parameters"/>
  </s0:message>
  <s0:message name="echoInt">
    <s0:part element="s1:echoInt" name="parameters"/>
  </s0:message>
  <s0:message name="echoIntResponse">
    <s0:part element="s1:echoIntResponse" name="parameters"/>
  </s0:message>
  <s0:portType name="ComplexPortType">
    <s0:operation name="echoComplexType" parameterOrder="parameters">
      <s0:input message="s1:echoComplexType"/>
      <s0:output message="s1:echoComplexTypeResponse"/>
    </s0:operation>
    <s0:operation name="echoInt" parameterOrder="parameters">
      <s0:input message="s1:echoInt"/>
      <s0:output message="s1:echoIntResponse"/>
    </s0:operation>
  </s0:portType>
  <s0:binding name="ComplexServiceSoapBinding" type="s1:ComplexPortType">
    <s2:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <s0:operation name="echoComplexType">
      <s2:operation style="document"/>
      <s0:input>
        <s2:body parts="parameters" use="literal"/>
      </s0:input>
      <s0:output>
        <s2:body parts="parameters" use="literal"/>
      </s0:output>
    </s0:operation>
    <s0:operation name="echoInt">
      <s2:operation style="document"/>
      <s0:input>
        <s2:body parts="parameters" use="literal"/>
      </s0:input>
      <s0:output>
        <s2:body parts="parameters" use="literal"/>
      </s0:output>
    </s0:operation>
  </s0:binding>
  <s0:service name="ComplexService">
    <s0:port binding="s1:ComplexServiceSoapBinding" name="ComplexPortTypeSoapPort">
      <s2:address location="http://localhost:7001/ComplexImpl/ComplexImpl"/>
    </s0:port>
  </s0:service>
</s0:definitions>

Step2). Now write the following kind of ANT build script to use the WSDLC utility to create a dummy WebService with default implementation of Service Operations (Methods)

build.xml

<project name="GenerateWS" default="all">
<property name="build" value="output" />
<property name="adminurl" value="t3://localhost:7001" />
<property name="serverName" value="AdminServer" />
<property name="userName" value="weblogic" />
<property name="password" value="weblogic" />
<property name="ear.name" value="Complex_JAXWS_Ear" />

<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>
<target name="all" depends="generate-from-wsdl,wait"/>

<target name="generate-from-wsdl">
     <wsdlc srcWsdl="ComplexImpl.wsdl"
            destJwsDir="jarJws"
            destImplDir="." type="JAXWS"
            packageName="ws"/>
</target>

<target name="wait">
    <echo message=" Now you need to provide your own Implementation for sayHello() of [[[ ws/ComplexService_ComplexPortTypeSoapPortImpl.java ]]]" />
    <echo message=" then you need to run 'ant deploy' to rebuild your edited Service and to Deploy it on the Server..." />
</target>

<target name="build-service">
     <mkdir dir="${build}/${ear.name}" />
     <jwsc srcdir="." destdir="${build}/${ear.name}">
          <jws file="ws/ComplexService_ComplexPortTypeSoapPortImpl.java" compiledWsdl="jarJws/ComplexImpl_wsdl.jar" type="JAXWS"/>
     </jwsc>
</target>

<target name="deploy" depends="build-service">
     <wldeploy action="deploy"
               source="${build}/${ear.name}" user="${userName}"
               password="${password}" verbose="true"
               failonerror="yes"
               adminurl="${adminurl}"
               targets="${serverName}" />
</target>

<target name="redeploy">
     <wldeploy action="redeploy"
               source="${build}/${ear.name}" user="${userName}"
               password="${password}" verbose="true"
               failonerror="yes"
               adminurl="${adminurl}"
               targets="${serverName}" />
</target>
</project>

Step3). Now  Open a command prompt then run the “. ./setWLSEnv.sh”  to set the CLASSPATH and PATH properly.

Run the “setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
.  ./setWLSEnv.sh

Note: the first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Now as soon as you will run the  command like “ant -buildfile build.xml  generate-from-wsdl”  it will generate all the artifacts for your WebService and a Dummy WebService implementation.

ant -buildfile build.xml
Buildfile: build.xml

generate-from-wsdl:
    [wsdlc] Download file [ComplexImpl.wsdl] to /tmp/_ckr59b
    [wsdlc] srcWsdl is redefined as [ /tmp/_ckr59b/ComplexImpl.wsdl ]
    [wsdlc] Consider using <depends>/<produces> so that wsimport won't do unnecessary compilation
    [wsdlc] parsing WSDL...

    [wsdlc] [WARNING] src-resolve: Cannot resolve the name 'java:BasicStruct' to a(n) 'type definition' component.
    [wsdlc]   line 9 of file:/tmp/_ckr59b/ComplexImpl.wsdl#types?schema1

    [wsdlc] generating code...

    [wsdlc] compiling code...

    [wsdlc] Note: /demos/TopDown/jarJws/generated/ws/ComplexService.java uses unchecked or unsafe operations.
    [wsdlc] Note: Recompile with -Xlint:unchecked for details.
[AntUtil.deleteDir] Deleting directory /tmp/_ckr59b

wait:
     [echo]  Now you need to provide your own Implementation for sayHello() of [[[ ws/ComplexService_ComplexPortTypeSoapPortImpl.java ]]]
     [echo]  then you need to run 'ant deploy' to rebuild your edited Service and to Deploy it on the Server...

all:

BUILD SUCCESSFUL
Total time: 3 seconds

Step5). Inside “/demos/TopDown/ws” you will find a WebService implementation class is generated with some name like “ComplexPortTypeSoapPortImpl.java” this is actually our WebService like following:

NOTE: A JAR also will be generated inside “/demos/TopDown/jarJws/ComplexImpl_wsdl.jar” this JAR will basically contain all the required classes and the Complex Datatypes which is going to be used by the WebService.


package ws;

import javax.jws.WebService;
import javax.xml.ws.BindingType;

/**
 * This class was generated by the JAX-WS RI.
 * Oracle JAX-WS 2.1.3-06/19/2008 07:03 PM(bt)
 * Generated source version: 2.1
 *
 */
@WebService(portName = "ComplexPortTypeSoapPort", serviceName = "ComplexService", targetNamespace = "http://example.org", wsdlLocation = "/wsdls/ComplexImpl.wsdl", endpointInterface = "ws.ComplexPortType")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class ComplexService_ComplexPortTypeSoapPortImpl
    implements ComplexPortType
{

    public ComplexService_ComplexPortTypeSoapPortImpl() {
    }

    /**
     *
     * @param struct
     * @return
     *     returns ws.BasicStruct
     */
    public BasicStruct echoComplexType(BasicStruct struct) {
        //replace with your impl here
        return null;
    }

    /**
     *
     * @param integerInput
     * @return
     *     returns int
     */
    public int echoInt(int integerInput) {
        //replace with your impl here
        return 0;
    }

}

Step6).Now We need to just add our Business implementation according to our requirement inside the methods present inside the WebService “ComplexPortTypeSoapPortImpl.java”  like following:

package ws;
import javax.jws.WebService;
import javax.xml.ws.BindingType;

/**
 * This class was generated by the JAX-WS RI.
 * Oracle JAX-WS 2.1.3-06/19/2008 07:03 PM(bt)
 * Generated source version: 2.1
 *
 */
@WebService(portName = "ComplexPortTypeSoapPort", serviceName = "ComplexService", targetNamespace = "http://example.org", wsdlLocation = "/wsdls/ComplexImpl.wsdl", endpointInterface = "ws.ComplexPortType")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class ComplexService_ComplexPortTypeSoapPortImpl
    implements ComplexPortType
{

    public ComplexService_ComplexPortTypeSoapPortImpl() {
          System.out.println("nt ComplexPortTypeSoapPortImpl  Instentiated...");
    }

    /**
     *
     * @param struct
     * @return
     *     returns ws.BasicStruct
     */
    public BasicStruct echoComplexType(BasicStruct struct) {
        //replace with your impl here
          System.out.println("nt ComplexPortTypeSoapPortImpl  echoComplexType method called...Got struct  = "+struct);
        return struct;
    }

    /**
     *
     * @param integerInput
     * @return
     *     returns int
     */
    public int echoInt(int integerInput) {
          System.out.println("nt ComplexPortTypeSoapPortImpl  echoInt method called...Got integerInput  = "+integerInput);
        return integerInput;
    }

}

Step7). Now just run the ANT build again to build and deploy the WebService as following “ant -buildfile build.xml  deploy

ant deploy
Buildfile: build.xml

build-service:
    [mkdir] Created dir: /demos/TopDown/output/Complex_JAXWS_Ear
     [jwsc] JWS: processing module /ws/ComplexService_ComplexPortTypeSoapPortImpl
     [jwsc] Parsing source files
     [jwsc] Parsing source files
     [jwsc] 1 JWS files being processed for module /ws/ComplexService_ComplexPortTypeSoapPortImpl
     [jwsc] JWS: /demos/TopDown/ws/ComplexService_ComplexPortTypeSoapPortImpl.java Validated.
     [jwsc] Processing 1 JAX-WS web services...
     [jwsc] Compiling 1 source file to /tmp/_4ixn4v
     [jwsc] Building jar: /demos/TopDown/output/Complex_JAXWS_Ear/ws/ComplexService_ComplexPortTypeSoapPortImpl.war
     [jwsc] Created JWS deployment outputFile: /demos/TopDown/output/Complex_JAXWS_Ear/ws/ComplexService_ComplexPortTypeSoapPortImpl.war
     [jwsc] [EarFile] Application File : /demos/TopDown/output/Complex_JAXWS_Ear/META-INF/application.xml
[AntUtil.deleteDir] Deleting directory /tmp/_4ixn4v

deploy:
 [wldeploy] weblogic.Deployer -verbose -noexit -source /demos/TopDown/output/Complex_JAXWS_Ear -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -password ******** -deploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -source /demos/TopDown/output/Complex_JAXWS_Ear -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -deploy
 [wldeploy] <May 4, 2011 3:55:10 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, Complex_JAXWS_Ear [archive: /demos/TopDown/output/Complex_JAXWS_Ear], to AdminServer .>
 [wldeploy] Task 0 initiated: [Deployer:149026]deploy application Complex_JAXWS_Ear on AdminServer.
 [wldeploy] Task 0 completed: [Deployer:149026]deploy application Complex_JAXWS_Ear on AdminServer.
 [wldeploy] Target state: deploy completed on Server AdminServer

 [wldeploy] Target Assignments:
 [wldeploy] + Complex_JAXWS_Ear  AdminServer

BUILD SUCCESSFUL
Total time: 5 seconds

Step8). Once the Service is deployed you can login to AdminConsole and then you can test it.

TestingWebService_FromConsol

.

.

Thanks

Jay SenSharma


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