Archive for November, 2015

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


How to use WebLogic 12c provided Maven Synchronization Plug-In ?

Hi,

Maven based development and deployment is the choice of most of the developers. WebLogic 12c has worked a lot on that direction.

Oracle Fusion Middleware 12c provides Maven Synchronization plug-in that simplifies the process of setting up repositories and completely eliminates the need to know what patches are installed in a particular environment.

Oracle homes in 12c contain maven directories which contain Maven Project Object Models (POMs) for artifacts provided by Oracle, archetypes for creating projects, and Maven plug-ins provided by Oracle, for executing various build operations.

WebLogic 12c (12.2.1.0) also provides “org.apache.maven_3.2.5” inside it, Which can be used to run Maven in your machines.

    export M2_HOME=/PATH/TO/wls1221/oracle_common/modules/org.apache.maven_3.2.5

As part of this example we will see how to install the Oracle Maven Synchronization Plug-In. Few things to remember while going through this article:

Point-1). The default maven local repository location is in the “${HOME}/.m2/repository” directory.

Point-2). For this demo we are using “Oracle WebLogic Server 12.2.1 (12c)” which can be downloaded from: http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html

Point-3). Even if WebLogic 12c provides it’s own Maven installation, we are using our own Maven Installation. Users can use any maven of their choice.

Setting up Classpath and Maven Environment.

Step-1). First of all we will set the environment variables and the ClassPath by running the “setWLSEnv.sh” script.

   $ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin

   $ ./setWLSEnv.sh 

   $ export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221

If JAVA_HOME is not set then please set that as well in the same command prompt.
Deploy the plugin as following:

Installing Oracle Maven Synchronization plug-in in Local Maven Repo

Step-2). Before we start using the “Oracle Maven Synchronization Plug-In” we will need to install it in our local repository (default: “${HOME}/.m2/repository”) on your computer, or We can also deploy it into our shared internal repository. So Lets run the following command, Make sure to move to the below mentioned directory before running the command mentioned below:

   
   $ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1
   
   $ mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar -Durl=file:///Users/jsensharma/.m2/repository
    .
    .
    . 
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar
Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar (71 KB at 3509.6 KB/sec)
Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom
Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom (9 KB at 8366.2 KB/sec)
Downloading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml
Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml
Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml (355 B at 346.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.368 s
[INFO] Finished at: 2015-11-03T12:35:46+05:30
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------

Here the “/Users/jsensharma/.m2/repository” is my default local maven repository path.
NOTE: Please do not use “~” to define the “-Durl” else you mat encounter issues later.

Observation-1). If you will not define the “-Durl” parameter to define your local repository path here then you may get the following kind of error :

   $ mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar
   .
   .
   .
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.318 s
[INFO] Finished at: 2015-11-02T13:59:15+05:30
[INFO] Final Memory: 6M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

Running Oracle Maven Synchronization plug-in

Step-3). Now lets try to run the “Oracle Maven Synchronization plug-in” to see if everything is working fine or not.

  .
  .
  $ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail  
  
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom ---
[INFO] com.oracle.maven:oracle-maven-sync:12.2.1-0-0

Name: Oracle Maven Synchronization Plugin
Description: Maven plugin to load a Maven repository with the contents of the
  Oracle Home directory
Group Id: com.oracle.maven
Artifact Id: oracle-maven-sync
Version: 12.2.1-0-0
Goal Prefix: oracle-sync

This plugin has 2 goals:

oracle-sync:help
  Description: Display help.
  Implementation: com.oracle.maven.sync.ODMHelp
  Language: java

  This mojo doesn't use any parameters.

oracle-sync:push
  Description: Install to the local repository and optionally deploy to a
    remote repository from the specified oracle home
    
    
    The plugin will use your current Maven settings to determine the path to
    the local repository and, optionally, a remote deployment repository. For
    details on how to configure Maven's repository settings, see the Maven
    settings reference: http://maven.apache.org/settings.html
    
    You can specify the parameters on the command line like this:
    -DserverId=archiva-internal -DdryRun=false -DfailOnError=false
    
    To override the localRepository target used by the plugin, you can specify
    the following option on the command-line:
    -Dmaven.local.repo=/alternate/path/to/repository
    
    To supply an alternate settings.xml for purposes of this operation, use the
    --settings option. For example:
    
     mvn --settings /alternate/path/settings.xml ... 
    ...or in your POM like this:
     <plugin>
         <groupId>com.oracle.maven</groupId>
         <artifactId>oracle-maven-sync</artifactId>
         <version>12.2.1-0-0</version>
         <configuration>
           <oracleHome>/home/mark/Oracle/Middleware</oracleHome>
           <failOnError>false</failOnError>
         </configuration>
       </plugin> 
  Implementation: com.oracle.maven.sync.ODMPushMojo
  Language: java

  Available parameters:

    dryRun (Default: false)
      User property: dryRun
      If set to 'true' this goal execution will only log push actions but will
      not actually make any changes.

    failOnError (Default: true)
      User property: failOnError
      If set to 'true' the plugin will stop and return an error immediately
      upon the first failure to deploy an artifact. Otherwise, the plugin will
      log the error and attempt to complete deployment of all other artifacts.

    localRepository (Default: ${localRepository})
      Provide an alternate local repository path to install pushed artifacts
      to.

    oracleHome
      User property: oracleHome
      Path to the Oracle home.
      Required.

    overwriteParent (Default: false)
      User property: overwriteParent
      If true, the plugin will overwrite POM artifacts with ancestry to
      oracle-common if they exist in the target repository. The default value
      of false will prevent automatic overwrite of customized POM contents. If
      any such POMs are encountered during plugin execution, an error will be
      thrown and handled according to the failOnError flag value. To carry over
      changes, save the existing POMs, run the push goal with
      overwriteParent=true and manually transfer the changes to the newly
      pushed POMs.

    pushDuplicates (Default: false)
      User property: pushDuplicates
      Push all duplicate locations. If multiple POMs with different Maven
      coordinates (GAV) are assigned to the same location path, the plugin will
      push them all to the destination repository if this flag is true.
      If the value is false, the push operation will fail. Set failOneError to
      false if you would like to skip all duplicates except the GAV in the set
      of duplicates that is encountered first.

    serverId
      User property: serverId
      This is the ID of the server (repository) in your settings.xml file -
      where you have specified the remote Maven repository and its
      authentication information. The plugin will only install to the local
      repository if this parameter is not set.


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.880 s
[INFO] Finished at: 2015-11-03T12:43:43+05:30
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------

Observation-2). Just in case if you encounter the following error while running the above command, Then make sure that in the previous step while running the “mvn deploy:deploy-file” you specified the fully qualified PATH for the “-Durl”. (Do not use ~ character while defining the URL)

$ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail  

.
.
$ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail  
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/maven-metadata.xml
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom ---
Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom
[WARNING] The POM for com.oracle.maven:oracle-maven-sync:jar:12.2.1-0-0 is missing, no dependency information available
Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.425 s
[INFO] Finished at: 2015-11-03T12:37:40+05:30
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-help-plugin:2.2:describe (default-cli) on project standalone-pom: Plugin does not exist: Plugin could not be found, please check its coordinates for typos and ensure the required plugin repositories are defined in the POM
[ERROR] com.oracle.maven:oracle-maven-sync:maven-plugin:12.2.1-0-0
[ERROR] 
[ERROR] from the specified remote repositories:
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

NOTE:
It is always better to add the “pluginGroup” inside the “/Users/jsensharma/.m2/settings.xml” (${user.home}/.m2/settings.xml) file as following:

<?xml version="1.0" encoding="UTF-8"?> 
<settings xmlns="http://maven.apache.org/settings/1.0.0"  
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 
  <pluginGroups> 
    <pluginGroup>com.oracle.maven</pluginGroup>
  </pluginGroups>  
</settings>

Populating the local repository

Now as the plugin is setup properly hence we will now go ahead and push the WebLogic JARs to the Maven repository. We will achieve it by using the “com.oracle.maven:oracle-maven-sync” command as following:


mvn com.oracle.maven:oracle-maven-sync:12.2.1-0-0:push -Doracle-maven-sync.oracleHome=/Users/jsensharma/NotBackedUp/Installed/wls1221 -DtestingOnly=false

Article is done here. Following part is just to simplify this whole above mentioned lengthy process. So i have written following kind of very simple shell script to automate these steps.
.
.
.
.
.

Simplified Shell Script to Do the Above

I have written the following kind of simple Shell script “weblogic_maven_sync.sh” which will make this whole task easy. Just make sure to set the Variables properly in this script.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
echo "JAVA_HOME = $JAVA_HOME"
echo 
export M2_HOME=/Users/jsensharma/NotBackedUp/Support_Tools/apache_maven_3.2.3
echo "M2_HOME = $M2_HOME"
echo
export M2_REPO=/Users/jsensharma/.m2/repository
echo "M2_REPO=$M2_REPO"
echo
export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221
echo "MW_HOME = $MW_HOME"
echo
export PATH=$JAVA_HOME/bin:/Users/jsensharma/NotBackedUp/Support_Tools/apache_maven_3.2.3/bin:$PATH:
echo "PATH = $PATH"

cd $MW_HOME//wlserver/server/bin
. ./setWLSEnv.sh

cd $MW_HOME/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1

mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar -Durl=file://${M2_REPO}

mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail  

mvn com.oracle.maven:oracle-maven-sync:12.2.1-0-0:push -Doracle-maven-sync.oracleHome=$MW_HOME -DtestingOnly=false

mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml

.
.

Known Issue

While running this script or while manually following these steps you might face the following error, which seems to be because of bad “org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom” pom , Contact Apache regarding this:

[INFO] ------------------------------------------------------------------------
[INFO] ISSUE DETAILS:
[INFO] ------------------------------------------------------------------------
[INFO]  POM PARSE ERROR : 
[INFO]  ISSUE #1: /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom
   Failed to parse POM at "/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom".  Repository copy will not be performed for this artifact    POM /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom appears to be missing a necessary GAV component: G:A:V:P null:doxia-sink-api:null:jar
[INFO]    
[INFO] 
[INFO] IMPORTANT NOTE
[INFO] This operation may have added/updated archetypes in your repository.
[INFO] To update your archetype catalog, you should run:
[INFO] 'mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml'

.
.
Source Code
Please find this script in the MiddlewareMagicDemos Github repo.
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/Maven/Maven_Synchronization_Plug-In
.
.
Regards
Jay SenSharma


Apache Camel based EJB Client accessing the EJBs deployed on WebLogic 12c

Hi,

In our last demo we have seen how to develop and deploy an EJB3.0 based application on WebLogic 12c and how to access those EJBs from a standalone java code. See the following for more details on this: http://middlewaremagic.com/weblogic/?p=8283

However as part of this example we will see how ti use Apache Camel’s “org.apache.camel.component.ejb.EjbComponent” in order to access an EJB deployed on WebLogic12c. In order to see more about the Apache Camel EJB Component, which binds EJBs to Camel message exchanges, please refer to : http://camel.apache.org/ejb.html

So lets begin with writing the EJB Project.

We are assuming that you have already developed and deployed your EJB on WebLogic 12c as described in the article: http://middlewaremagic.com/weblogic/?p=8283 Now we will continue from there and will try developing a simple apache camel based client.

Developing Camel Based EJB Client

Step-1). First of all lets make a directory “Apache_Camel_As_WebLogic_EJB_Client” We will place our client artifacts there.

   $ mkdir -p Apache_Camel_As_WebLogic_EJB_Client/src/main/java/ejb3
   $ mkdir -p Apache_Camel_As_WebLogic_EJB_Client/src/main/resources/META-INF/spring

Step-2). As we are assuming that you have already deployed your EJB application on WebLogic 12c. The client needs the EJB remote interface to invoke the EJBs. Hence we will use the “HelloRemote.java” EJB remote interface here. Create a file “HelloRemote.java” as following inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/java/ejb3” directory.

package ejb3;
import javax.ejb.*;
@Remote
public interface HelloRemote {
        public String sayHello(String name);
}

Step-3). Now we will create the XML based apache camel context route. In order to do that lets create a file “camel-context.xml” inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/resources/META-INF/spring” directory 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:camel="http://camel.apache.org/schema/spring"
       xmlns:p="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <p:properties id="jndiProperties">
        <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
        <prop key="java.naming.provider.url">t3://localhost:7001</prop>
        <!--
        <prop key="remote.connection.default.username">ejbuser</prop>
        <prop key="remote.connection.default.password">ejbuser@123</prop>
        -->
    </p:properties>


    <!-- setup Camel EJB component -->
    <bean id="ejbComponent" class="org.apache.camel.component.ejb.EjbComponent">
        <property name="properties" ref="jndiProperties"/>
    </bean>
    
    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
      <camel:route id="testCamelEJBClient">
            <camel:from uri="timer:foo?period=5000"/>
            <setBody>
                <simple>MiddlewareMagic!!!</simple>
            </setBody>
            <!-- NOTE: "java:global/TestApp/TestEJB/HelloBean!ejb3.HelloRemote" is the JNDI name of WLS 12c deployed EJB -->
            <camel:to uri="ejbComponent:java:global/TestApp/TestEJB/HelloBean!ejb3.HelloRemote?method=sayHello" />
            
            <camel:log message="[EJB Response] ===> ${body}" />
      </camel:route>
    </camel:camelContext>

</beans>

Step-4). Just in case if we want to provide your own logging configuration to DEBUG the camel code and its execution then we can add the following kind of “log4j.properties” file inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/resources” directory.

#
# The logging properties used
#
log4j.rootLogger=INFO, out
#log4j.logger.org.apache.camel=DEBUG
log4j.logger.org.springframework=INFO

# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer

Step-5). Now we will write the most important part which will make the whole project and will define how the execution will happen. Hence lets write the “pom.xml” file inside the “Apache_Camel_As_WebLogic_EJB_Client” location as following:

<?xml version="1.0" encoding="UTF-8"?>
<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>Apache_Camel_As_WebLogic12c_EJB_Client</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>Apache Camel As WebLogic 12c Based EJB Client</name>
  <url>http://middlewaremagic.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <middleware.home>/Users/jsensharma/NotBackedUp/Installed/wls12130</middleware.home> <!-- CHANGE ME !!! -->
  </properties>

  <dependencies>   
       <!-- Needed to have access to WebLogic related class access like "weblogic.jndi.WLInitialContextFactory" -->
       <dependency>
        	<groupId>weblogic</groupId>
        	<artifactId>needed.jars</artifactId>
        	<version>1.0</version>
            <scope>system</scope>   
            <systemPath>${middleware.home}/wlserver/server/lib/wlthint3client.jar</systemPath>     	
       </dependency>  
             
       <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xbean</groupId>
            <artifactId>xbean-spring</artifactId>
            <version>3.16</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
          <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
             <version>1.2.15</version>
             <exclusions>
                <exclusion>
                     <groupId>com.sun.jmx</groupId>
                     <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>com.sun.jdmk</groupId>
                     <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>javax.jms</groupId>
                     <artifactId>jms</artifactId>
                </exclusion>
             </exclusions>
           </dependency>
           <dependency>
               <groupId>org.apache.camel</groupId>
               <artifactId>camel-ejb</artifactId>
               <version>2.15.0</version>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>6.0</version>
                <scope>provided</scope>
            </dependency>
   </dependencies>

   <pluginRepositories>
      <pluginRepository>
         <id>apache.snapshots</id>
         <name>Apache Development Snapshot Repository</name>
         <url>https://repository.apache.org/content/repositories/snapshots/</url>
         <releases>
            <enabled>false</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </pluginRepository>
   </pluginRepositories>

   <repositories>
      <repository>
         <id>apache.snapshots</id>
         <name>Apache Development Snapshot Repository</name>
         <url>https://repository.apache.org/content/repositories/snapshots/</url>
         <releases>
            <enabled>false</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </repository>
   </repositories>
   
  <build>
    <defaultGoal>install</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <!-- allows the route to be ran via 'mvn camel:run' -->
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>2.15.4</version>
      </plugin>
    </plugins>
  </build>
</project>

Running the Camel Based EJB Client

Step-6). Now lets run the client code as following:

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 /PATH/TO/Apache_Camel_As_WebLogic_EJB_Client

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:\Apache_Camel_As_WebLogic_EJB_Client

Step-7). Once the environment is set then run the Apache Camel Based ejb client as following:

   $ mvn clean camel:run

.
.

Raw output of the client execution

$ mvn clean camel:run
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Camel As WebLogic 12c Based EJB Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] 
[INFO] >>> camel-maven-plugin:2.15.4:run (default-cli) > test-compile @ Apache_Camel_As_WebLogic12c_EJB_Client >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Compiling 1 source file to /Apache_Camel_As_WebLogic_EJB_Client/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Apache_Camel_As_WebLogic_EJB_Client/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5:testCompile (default-testCompile) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] No sources to compile
[INFO] 
[INFO] <<< camel-maven-plugin:2.15.4:run (default-cli) < test-compile @ Apache_Camel_As_WebLogic12c_EJB_Client <<<
[INFO] 
[INFO] --- camel-maven-plugin:2.15.4:run (default-cli) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using org.apache.camel.spring.Main to initiate a CamelContext
[INFO] Starting Camel ...
[pache.camel.spring.Main.main()] MainSupport                    INFO  Apache Camel 2.15.0 starting
[pache.camel.spring.Main.main()] ClassPathXmlApplicationContext INFO  Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@32ef2304: startup date [Sun Nov 01 21:48:40 IST 2015]; root of context hierarchy
[pache.camel.spring.Main.main()] XmlBeanDefinitionReader        INFO  Loading XML bean definitions from file [/Apache_Camel_As_WebLogic_EJB_Client/target/classes/META-INF/spring/camel-context.xml]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.0 (CamelContext: camel-1) is starting
[pache.camel.spring.Main.main()] ManagedManagementStrategy      INFO  JMX is enabled
[pache.camel.spring.Main.main()] DefaultTypeConverter           INFO  Loaded 183 type converters
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route: testCamelEJBClient started and consuming from: Endpoint[timer://foo?period=5000]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Total 1 routes, of which 1 is started.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.0 (CamelContext: camel-1) started in 0.751 seconds

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:44 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:49 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:54 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:59 IST 2015

Source Code:
The complete source code of this demo can be found at the following git repo:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/ApacheCamel/Apache_Camel_As_WebLogic_EJB_Client

.
.
Regards
Jay SenSharma


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