Date Created: Fri 24-Sep-2010

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Creating my first CXF project - Part 1, covers porting the client component of a bottom up approach built using Apache CFX. the sample has a client package and server package. You run the ant build to run the server package and you get a web service within a command line JVM. You then run the ant client target and you get a client which calls the web service. This is all nice an dandy, however the real world is that we build in Eclipse and one wants to see how I take this code and make it work both as a client and as a server all from Eclipse so that we can deploy the webservice to any Java Web Container.

Part 1: Address one way of porting the "client sample" to an Eclipse set-up, Part 2 will cover the more difficult server build. but is starts to show how cool ANT can be in making stand alone Eclipse projects work even with new Eclipse versions. You see using the default Eclipse IDE often causes learning to be masked about what is really happening and the tools plugins keep changing as API's are released , so you never get to understand the actual implementation. I think you need to do this manual task with all new APIS and then once working you can install the plugins as you will understand what they re doing and what the tooling options provide (are doing at the low level) remember the plugins are only a wrapper to command line java commands at the end of the day.

Note: Once again this demo reiterates, that plugins are great for rapid development once you know what is going on, but the truth is they are no excuse for understanding what's under the covers.

===========================

JAVA_HOME=C:\Java\jdk1.6.0_20

My first trial at Apache CXF

Dowloaded

apache-cxf-2.2.7.tar


Downloaded CXF then created a COMSPEC dos folder in the location of the sample.




this allows me to gain access to the samples from a command lime as this is how they are distributed




I am using ANT for my test to make the solution actually work, then have a look a the code.

ant

automatically finds build.xmk and builds both projects. The build.xml file has multiple targets and allows me to run each client and server ads required.

I typed ant client and got an error, this is because I have started the server first.

ant server




then in a new DOS window type

ant client





===============


Lets set things up in eclipse to read the build file before we go any further. What Eclipse will allow us to do us link to the file-system and use the samples inline. I often back then up first before I do this or ensure I have the samples to re-install as required




I decided to leave the project on disk and create a new eclipse project as this would show how to take an downloaded command line application and how we can import it into eclipse




import into src folder of eclipse project










Result:





I then tried to run the Client application from Eclipse with the server not running

Exception in thread "main" javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service instance or ServiceEndpointInterface demo.hw.server.HelloWorld should have WSDL information
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at demo.hw.client.Client.main(Client.java:52)

I then started the server (Service)


We need to ensure that the client can see the WSDL


Select Project in project explorer

import wsdl



Result:





Result the WSDL is in the project, lets see if it will resolve?

No, lets import the build.xml file and see what classpath has been set on the local samples.



once imported build file it couls not find the command build.xml I will add it

<import file="../common_build.xml"/>



Tried to run client class, still same error


WSDL Metadata not available to create the proxy, either Service instance or ServiceEndpointInterface



<target name="client" description="run demo client" depends="build">
<property name="param" value=""/>
<cxfrun classname="demo.hw.client.Client"
param1=""
param2="${op}"
param3="${param}"/>
</target>

Not sure what cxfrun is part of?

Answer:cxfrun is a macro in ANT see in common_build.xml

Note: The use of fork: Whether to execute javac using the JDK compiler externally; defaults to no.
Note: classname the Java class to execute. Either jar or classname the use of @{} notation is used for parameter substition ie the substitute the class path as passed to the macro and use in the command line you wish to run. the example below allows the custom command line as defined by the macro to take the classnane sent as a input param and used in the internal java call.

<macrodef name="cxfrun">
<attribute name="logging-properties-file" default="${cxf.etc.dir}/logging.properties"/>
<attribute name="classname"/>
<attribute name="param1" default=""/>
<attribute name="param2" default=""/>
<attribute name="param3" default=""/>
<attribute name="param4" default=""/>
<attribute name="param5" default=""/>
<attribute name="jvmarg1" default="-D' '"/>
<attribute name="jvmarg2" default="-D' '"/>
<attribute name="jvmarg3" default="-D' '"/>
<attribute name="jvmarg4" default="-D' '"/>
<attribute name="jvmarg5" default="-D' '"/>
<sequential>
<java classname="@{classname}" fork="yes">
<classpath>
<path refid="cxf.classpath"/>
<pathelement path="${thirdparty.classpath}"/>
<path refid="jdk.tools.classpath"/>
</classpath>
<arg value="@{param1}"/>
<arg value="@{param2}"/>
<arg value="@{param3}"/>
<arg value="@{param4}"/>
<arg value="@{param5}"/>
<jvmarg value="-Dcxf.home=${cxf.home}"/>
<jvmarg value="@{jvmarg1}"/>
<jvmarg value="@{jvmarg2}"/>
<jvmarg value="@{jvmarg3}"/>
<jvmarg value="@{jvmarg4}"/>
<jvmarg value="@{jvmarg5}"/>
<!--assertions>
<enable package="org.apache.cxf"/>
</assertions-->
<sysproperty key="java.util.logging.config.file" value="@{logging-properties-file}"/>
</java>
</sequential>
</macrodef>



Using this intelligence I am able to set up a run configuration in eclipse, I could use ant and create a build file that serves both as a local CMD line build and an eclipse build, but to be honest I want to try the Eclipse run config, then try and make my own client ant file superficially to run the client.



For the client to bind to the web service it needs to know the WSDL location as defined by the service as we are using dynamic binding. What I mean by dynamic binding is that I am not using any local stubs or require any other class help files etc









Still getting

Exception in thread "main" javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service instance or ServiceEndpointInterface demo.hw.server.HelloWorld should have WSDL information
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at demo.hw.client.Client.main(Client.java:52)




I then ran from Eclipse and it worked

29-Apr-2010 20:24:41 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.apache.cxf.bus.spring.BusApplicationContext@1f20eeb: display name [org.apache.cxf.bus.spring.BusApplicationContext@1f20eeb]; startup date [Thu Apr 29 20:24:41 BST 2010]; root of context hierarchy
29-Apr-2010 20:24:42 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder': replacing [Generic bean: class [org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]] with [Generic bean: class [org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]]
29-Apr-2010 20:24:42 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder': replacing [Generic bean: class [org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]] with [Generic bean: class [org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]]
29-Apr-2010 20:24:42 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider': replacing [Generic bean: class [org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]] with [Generic bean: class [org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]]
29-Apr-2010 20:24:42 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory': replacing [Generic bean: class [org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory]; scope=singleton; abstract=false; lazyInit=true; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]] with [Generic bean: class [org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory]; scope=singleton; abstract=false; lazyInit=true; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/C:/apache-cxf-2.2.7/lib/cxf-2.2.7.jar!/META-INF/cxf/cxf-extension-http.fixml]]
29-Apr-2010 20:24:42 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.apache.cxf.bus.spring.BusApplicationContext@1f20eeb]: org.springframework.beans.factory.support.DefaultListableBeanFactory@17471e0
29-Apr-2010 20:24:42 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17471e0: defining beans [cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.corba.CorbaBindingFactory,org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister#0,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxws.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding.xml.XMLBindingFactory,org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder,org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider,org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder,org.apache.cxf.javascript.JavascriptQueryHandlerRegistry,org.apache.cxf.transport.local.LocalTransportFactory,org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory,org.apache.cxf.management.InstrumentationManager,org.apache.cxf.transport.http_jetty.JettyHTTPTransportFactory,org.apache.cxf.transport.jms.JMSTransportFactory,org.apache.cxf.binding.object.ObjectBindingFactory,org.apache.cxf.binding.http.HttpBindingFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,org.apache.cxf.ws.security.policy.WSSecurityPolicyLoader,org.apache.cxf.ws.policy.AssertionBuilderRegistry,org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry,org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry,org.apache.cxf.ws.policy.attachment.external.EndpointReferenceDomainExpressionBuilder,org.apache.cxf.ws.policy.PolicyBuilder,org.apache.cxf.ws.policy.PolicyEngine,org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider,org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider,org.apache.cxf.ws.policy.mtom.MTOMAssertionBuilder,org.apache.cxf.ws.policy.mtom.MTOMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMManager,org.apache.cxf.ws.rm.policy.RMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMAssertionBuilder]; root of factory hierarchy
29-Apr-2010 20:24:43 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://server.hw.demo/}HelloWorld from class demo.hw.server.HelloWorld
29-Apr-2010 20:24:44 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://server.hw.demo/}HelloWorld from class demo.hw.server.HelloWorld
Hello World
Hello World
Hello Galaxy
Hello Universe

Users:
1: World
2: Galaxy
3: Universe


I now have to add a log4j.properties or log4j.xml to the class path. i was wrong they are using common logging form Apache.



I added a folder called etc and added the logging.properties file




I then changed the Eclipse run configuration.



Now the login properties is found the default commons logging is enforced and we see not logging. Yippe. We can change this thought if we wish to see more logging

There are PROS and cons about this method and it requires eclipse to have the environment set up each time. This is why you should use and ANT build file which can be shipped with your Eclipse project so that other People can import into Eclipse easily and don't need to know the "Environment and JVM params and JAR class paths" to figure out how to set up the Eclipse environment.

Task: Commons Loggin vs Log4j


Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories