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
January 6th, 2016 on 1:33 pm
Hi Jaya,
Please let me know how can i post my queries or start a new thread
Thanks
January 6th, 2016 on 1:37 pm
Hello Utkarsh,
In the http://middlewaremagic.com/weblogic link you can find the “Forums” tab in that select the correct category for your query (like webservice/ejb/security ..etc) and after clicking on the subtab at the bottom of the page you will be able to find the Comment section where you can post your query.
However now it is easy to pose your queries on the LinkedIn Group https://www.linkedin.com/groups/8403306 of MiddlewareMagic where you will get larger audience to answer your queries.
Regards
Jay SenSahrma
February 5th, 2016 on 7:43 pm
I’m deploying one war containing some webservices which is packaged in ear on Weblogic 12.1.2
I’m using CXF 2.5.4.
My web.xml is confirming to configurations as mentioned in the article. The CXF libraries are present in WEB-INF/lib/ of war. In weblogic.xml I’ve put following to give preference to application libraries,
true
org.apache.cxf.binding.soap.saaj.*
org.apache.cxf.endpoint.*
org.apache.cxf.frontend.*
org.apache.cxf.transport.http.*
org.apache.cxf.interceptor.*
org.apache.cxf.transports.http.configuration.*
com.sun.xml.messaging.saaj.*
But still the application uses
wlserver_12.1.2/installation/oracle_common/modules/com.sun.xml.ws.jaxws-rt_2.2.jar
wlserver_12.1.2/installation/oracle_common/modules/com.sun.xml.ws.jaxws-tools_2.2.jar
and so on to generate WSDLs and XSDs of the web services. I can see it in WSDL
http://myhost:port/my-service/QueryWs?WSDL
http://myhost:port/my-service/QueryWs?xsd=1
Why isn’t the Weblogic using CXF libraries to generate WSDLs and XSDs for WebServices in my ear/war?
February 7th, 2016 on 12:47 pm
Hello Akshay,
You mentioned that you are still observing that your application is still using “com.sun.xml.ws.jaxws-rt_2.2.jar” and “com.sun.xml.ws.jaxws-tools_2.2.jar”, So can you please verify how are you validating the same ?
Also can you please post the list of JARs present inside the $EAR/lib (OR $EAR/APP-INF/lib) and the “WEB-INF/lib”?
Regards
Jay SenSharma
February 5th, 2016 on 7:46 pm
I even tried by putting weblogic-application.xml in META-INF of ear with following:
org.apache.cxf.binding.soap.saaj.*
org.apache.cxf.endpoint.*
org.apache.cxf.frontend.*
org.apache.cxf.transport.http.*
org.apache.cxf.interceptor.*
org.apache.cxf.transports.http.configuration.*
com.sun.xml.messaging.saaj.*
But it doesn’t work.
February 5th, 2016 on 7:47 pm
I even tried by putting weblogic-application.xml in META-INF of ear with following:
org.apache.cxf.binding.soap.saaj.*…
…
But it doesn’t work.
February 8th, 2016 on 7:05 pm
I came to conclusion that com.sun.xml.ws.jaxws-rt_2.2.jar and com.sun.xml.ws.jaxws-tools_2.2.jar are being used from two points,
1. the generated WSDL mentions at the top line in it,
2. In lsof output I found these two files referred by the Weblogic server process,
I was wondering who is generating these WSDLs because neither we had put jax-ws RI library in our artifact nor java home had jax-ws libs. So when I checked with pt.2 I got these references and it matched with pt.1 line.
Here is list of files in WEB-INF/lib/ of the war packed inside EAR,
asm-3.3.1.jar
commons-codec-1.3.jar
commons-logging-1.1.1.jar
cxf-2.5.4.jar
cxf-api-2.5.4.jar
cxf-common-utilities-2.5.4.jar
cxf-rt-bindings-soap-2.5.4.jar
cxf-rt-bindings-xml-2.5.4.jar
cxf-rt-core-2.5.4.jar
cxf-rt-databinding-jaxb-2.5.4.jar
cxf-rt-frontend-jaxws-2.5.4.jar
cxf-rt-frontend-simple-2.5.4.jar
cxf-rt-management-2.5.4.jar
cxf-rt-transports-common-2.5.4.jar
cxf-rt-transports-http-2.5.4.jar
cxf-rt-ws-addr-2.5.4.jar
cxf-tools-common-2.5.4.jar
inv-api-ws-9.3.0-SNAPSHOT.jar
jsp-api-2.1.jar
jstl-api-1.2.jar
neethi-3.0.2.jar
openws-1.4.2-1.jar
ossif-9.3.0-SNAPSHOT.jar
ossif-integration-9.0.1-SNAPSHOT.jar
slf4j-api-1.6.4.jar
spring-web-3.1.1.RELEASE.jar
stax2-api-3.1.1.jar
woodstox-core-asl-4.1.2.jar
wsdl4j-1.6.2.jar
wss4j-1.6.7.jar
xml-resolver-1.2.jar
xmlschema-core-2.0.2.jar
I don’t see $EAR/APP-INF/ in my ear.
ANY inputs on sequence of files mentioned in classpath in Weblogic is APPRECIATED.
I strongly feel its class loading issue where the CLASSES are being loaded from these jars from oracle_common and so server is not loading same classes from cxf-rt-frontend-jaxws-2.5.4.jar.
February 8th, 2016 on 7:18 pm
And how to change the classpath to put my files first.
February 9th, 2016 on 10:34 am
Hello Akshay,
If you want that the WLDL should be generated by the CXF itself then you can specify the “genWsdl” option in your pom.xml files “cxf-codegen-plugin” plugin as following:
Then you can package that wsdl and relevant xsd file under your web applications “WEB-INF/wsdl”
Please check if that works for you.
Regards
Jay SenSharma
February 9th, 2016 on 10:40 am
Hello Akshay,
Regarding your query: “And how to change the classpath to put my files first.”
You can add the “prefer-web-inf-classes” tag inside your “WEB-INF/weblogic.xml” file to give a precedence of your JARs on the WLS Shipped JARs. prefer-web-inf-classes
The prefer-web-inf-classes element, if set to true, will cause classes located in the WEB-INF directory of a Web application to be loaded in preference to classes loaded in the application or system classloader. The default value is false. A value specified in the Administration Console will take precedence over a value set manually.
See: https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#WBAPP602
Regards
Jay SenSharma
February 9th, 2016 on 12:07 pm
I have already given prefer-web-inf-classes in the WEB-INF/weblogic.xml. But it is not using the CXF library to generate WSDL and XSDs.
That is my main concern.
February 9th, 2016 on 2:01 pm
Hello Akshay,
CXF is not Weblogic’s default WebService provider hence WLS will not use CXF to generate the WSDL.
So If you want that the WSLDL should be generated by the CXF itself then you can specify the “genWsdl” option in your pom.xml files “cxf-codegen-plugin” plugin as mentioned earlier. And then you can package you can package that wsdl and relevant xsd file under your web applications “WEB-INF/wsdl”
Regards
Jay SenSharma
February 9th, 2016 on 4:06 pm
Hey Jay,
Thanks a lot for your quick responses.
I tried using the option. Initially the WSDLs were being packaged in jar.
But I even tried to put the generated wsdls at WEB-INF/wsdl in generated war. But still Weblogic is generating the WSDLs and using JAX-RS local libraries.
Thanks to JAX-RS RI library coders at least they have put their name on the generated WSDLs and XSDs making it easy to verify.
February 9th, 2016 on 4:13 pm
Hello Jay,
That prefer-web-inf-classes is already used by me and its not working. I have gone through Weblogic documentation. But if I have given libraries and packages in the weblogic.xml then server should respect the configuration and use CXF (in WEB-INF/lib/) to generate WSDLs and XSDs when they are not provided in Archive.
But even when I’m providing the server is generating and generating with native jaxrs library. This is not expected and leaving me stranded..
Thanks,
Akshay
February 9th, 2016 on 4:46 pm
Hello Akshay,
I retested the same on WLS12.2.1 and i do not see the issue which you reported. I have uploaded my TestCase to the URL: https://github.com/jaysensharma/MiddlewareMagicDemos/blob/master/Misc/Test_WLS1221_CXF.zip
Can you please try the same app at your end and try comparing it with yours to see if there is any difference. Just to reduce the size of the project i removed the JARs from the “target/WebLogic_CXF_Demo/WEB-INF/lib” and listed all the needed jars inside the file “target/WebLogic_CXF_Demo/WEB-INF/lib/list_of_jars.txt”. As soon as you will build this project those jars will be downloaded there.
Regards
Jay SenSharma,a
February 12th, 2016 on 7:04 pm
Hi Jay,
I tried to build and deploy this war. Build and deployment was successful. Only thing is I installed the war from Admin console instead of using maven plugin.
But neither the WSDL is coming at the WSDL URL nor service invocation with service URL is giving anything.
For both I get 404 error.
February 12th, 2016 on 7:08 pm
Sorry please ignore my last comment I was checking with wrong hostname.
this App is working Fine and CXF is being used properly to generate WSDLs.
Thanks.
I must check what is wrong with my App now..
February 12th, 2016 on 7:13 pm
Hello Akshay,
The following URL should be ideally working for the WSDL:
http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld?wsdl
And the following kind of log should appear in your logs for successful deployment of the CXF webservice:
Regards
Jay SenSharma