Sunday, September 17, 2017

Weblogic 12.2 1 - implement WebService using Maven Archetype

Java EE7 web service tutorial
https://docs.oracle.com/javaee/7/tutorial/jaxws.htm

Here is description  for basic webservice implementation in Weblogic 12.2.1 docs
https://docs.oracle.com/middleware/12211/lcm/MAVEN/weblogic_maven.htm#MAVEN8785

Requires configuration of Oracle Maven repository on local host - see here http://danielveselka.blogspot.cz/2016/01/using-maven-on-weblogic-1221-with-java.html

Use Maven  archetype to generate application

mvn archetype:generate -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webservice -DarchetypeVersion=12.2.1-0-0 -DgroupId=org.dave -DartifactId=dave-basic-webservice-project  -Dversion=1.0-SNAPSHOT


[INFO] Archetype repository missing. Using the one from [com.oracle.weblogic.archetype:basic-webservice:12.2.1-0-0] found in catalog local
[INFO] Using property: groupId = org.dave
[INFO] Using property: artifactId = dave-basic-webservice-project
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = org.dave
Confirm properties configuration:
groupId: org.dave
artifactId: dave-basic-webservice-project
version: 1.0-SNAPSHOT
package: org.dave

Generated code https://github.com/dveselka/weblogic

Run mvn compile

META-INF/application.xml

<?xml version='1.0' encoding='UTF-8'?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5">
  <display-name>target</display-name>
  <module>
    <web>
      <web-uri>SayHello</web-uri>
      <context-root>basicWebservice</context-root>
    </web>
  </module>
</application>


Run mvn package

[dave@localhost dave-basic-webservice-project]$ mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building basicWebservice 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webservice-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/dave/git/weblogic/dave-basic-webservice-project/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webservice-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:ws-jwsc (default) @ dave-basic-webservice-project ---
EarFile] Application File : /home/dave/git/weblogic/dave-basic-webservice-project/target/META-INF/application.xml
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webservice-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/dave/git/weblogic/dave-basic-webservice-project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webservice-project ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webservice-project ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webservice-project ---
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webservice-project] in [/home/dave/git/weblogic/dave-basic-webservice-project/target/generated-dave-basic-webservice-project]
[INFO] Processing war project
[INFO] Webapp assembled in [76 msecs]
[INFO] Building war: /home/dave/git/weblogic/dave-basic-webservice-project/target/basicWebservice.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS


Run mvn preintegration-test

INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webservice-project] in [/home/dave/git/weblogic/dave-basic-webservice-project/target/generated-dave-basic-webservice-project]
[INFO] Processing war project
[INFO] Webapp assembled in [206 msecs]
[INFO] Building war: /home/dave/git/weblogic/dave-basic-webservice-project/target/basicWebservice.war
[INFO] 
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:deploy (deployApp) @ dave-basic-webservice-project ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name basicWebservice -source /home/dave/git/weblogic/dave-basic-webservice-project/target/basicWebservice.war -verbose -adminurl t3://localhost:7001
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name basicWebservice -source /home/dave/git/weblogic/dave-basic-webservice-project/target/basicWebservice.war -verbose -adminurl t3://localhost:7001
<Sep 17, 2017 11:48:26 AM CEST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, basicWebservice [archive: /home/dave/git/weblogic/dave-basic-webservice-project/target/basicWebservice.war], to configured targets.> 
Task 0 initiated: [Deployer:149026]deploy application basicWebservice on AdminServer.
Task 0 completed: [Deployer:149026]deploy application basicWebservice on AdminServer.
Target state: deploy completed on Server AdminServer

Target Assignments:
+ basicWebservice  AdminServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS


Test the application http://localhost:7001/basicWebservice/SayHello

Endpoint     Information
Service Name:    {http://example.org}SayHello
Port Name:    {http://example.org}SayHelloPort
    
Address:    http://localhost:7001/basicWebservice/SayHello
WSDL:    http://localhost:7001/basicWebservice/SayHello?wsdlTest
Implementation class:    org.dave.SayHello

WSDL  http://localhost:7001/basicWebservice/SayHello?wsdl

<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.11-b150616.1732 svn-revision#a247ba216861f2c0baac9a3657c5690bce0c744d. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.11-b150616.1732 svn-revision#a247ba216861f2c0baac9a3657c5690bce0c744d. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://example.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://example.org" name="SayHello">
<types>
<xsd:schema>
<xsd:import namespace="http://example.org" schemaLocation="http://localhost:7001/basicWebservice/SayHello?xsd=1"/>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<portType name="SayHello">
<operation name="sayHello">
<input wsam:Action="http://example.org/SayHello/sayHelloRequest" message="tns:sayHello"/>
<output wsam:Action="http://example.org/SayHello/sayHelloResponse" message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="SayHelloPortBinding" type="tns:SayHello">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SayHello">
<port name="SayHelloPort" binding="tns:SayHelloPortBinding">
<soap:address location="http://localhost:7001/basicWebservice/SayHello"/>
</port>
</service>
</definitions>

Test using browser client
http://localhost:7001/ws_utc/?wsdlUrl=http://localhost:7001/basicWebservice/SayHello?wsdl

1 comment:

  1. Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog
    AWS Online Training

    ReplyDelete