You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Arul Dhesiaseelan <ar...@fluxcorp.com> on 2008/05/02 01:48:36 UTC

Self-contained web services

Hi,

I have the following scenario. ProfileManager is a web service contained 
within CampaignManager web service. I can access the profile manager 
only through campaign manager.

@WebService
public class CampaignManagerImpl implements CampaignManager {
private String name;
private ProfileManager profileMgr;

@WebMethod
public String getName() {
  return name;
}

@WebMethod
public ProfileManager getProfileManager() {
    if (profileMgr != null)
        profileMgr  = new ProfileManagerImpl();
     return profileMgr;
}

}


@WebService
public class ProfileManagerImpl implements ProfileManager {
private String username;
private String password;
private ProfileManager manager;

public ProfileManagerImpl(ProfileManager mgr) {
    this.manager = mgr;
}
@WebMethod
public String getUsername() {
    return mgr.getUsername();
}

@WebMethod
public String getPassword() {
     return mgr.getPassword();
}
}

When I actually create the campaign service, I  am thinking to do 
something like this:.

    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(CampaignManager.class);
    sf.getServiceFactory().setWrapped(true);
    sf.setServiceName(new QName(NAMESPACE_URI, localPart, ""));
    sf.setAddress("http://localhost:8080/campaignservice");

    CampaignManager campaignService = new CampaignManagerImpl();
    ProfileManager profileService = new 
ProfileManagerImpl(campaignService.getProfileManager());//getting the 
profile mgr from campaign mgr and creating the profile mgr service.
    sf.getServiceFactory().setInvoker(new BeanInvoker(campaignService));
    sf.create();

How do I invoke these services from the CXF client? Is it a valid use 
case that can be implemented in CXF?

Cheers,
Arul


Re: Self-contained web services - CampaignManagerPort.http-destination - no injection will be performed. ?

Posted by Arul Dhesiaseelan <ar...@fluxcorp.com>.
I implemented the below logic to see if it works in CXF. I started both 
campaign and profile services and was able to access the WSDL. But, the 
client failed in error when invoking the profile service.
I suspect if the profile service within campaign service is not injected 
by CXF. I get a 500 response on the server when I run the client. Can 
someone shed some light on this? I am using CXF 2.1.

*I am getting the following message when I start my web services.*

FINE: Wrigin XML Schema for 
com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator@1c293f8[http://testing.services.fluximpl/=com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator$Namespace@fe0fd9]
com.sun.xml.bind.v2.util.StackRecorder
    at 
com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator.write(XmlSchemaGenerator.java:422)
    at 
com.sun.xml.bind.v2.runtime.JAXBContextImpl.generateSchema(JAXBContextImpl.java:788)
    at 
org.apache.cxf.jaxb.JAXBDataBinding.generateJaxbSchemas(JAXBDataBinding.java:384)
    at 
org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:337)
    at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:343)
    at 
org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:512)
    at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:394)
    at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:180)
    at 
org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:163)
    at 
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:79)
    at 
org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:114)
    at 
org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:160)
    at fluximpl.services.testing.CXFServer.main(CXFServer.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
May 2, 2008 11:55:18 AM 
org.apache.cxf.configuration.spring.ConfigurerImpl configureBean
FINE: Could not find a definition for bean with id 
{http://testing.services.fluximpl/}CampaignManagerPort.http-destination 
- no injection will be performed.
May 2, 2008 11:55:18 AM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be 
http://localhost:8080/campaignservice

*I am getting the following error on the server side when I invoke the 
profile service.*

FINE: Application has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
    at 
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:110)
    at 
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:98)
    at 
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:68)
    at 
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
    at 
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at 
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
    at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at 
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
    at 
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:280)
    at 
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:254)
    at 
org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
    at 
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
    at 
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
    at 
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:320)
    at 
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at 
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:730)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at 
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at 
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
Caused by: java.lang.NullPointerException
    at 
fluximpl.services.testing.RemoteProfileManagerImpl.getUsername(RemoteProfileManagerImpl.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at 
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:127)
    at 
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82)
    ... 20 more

*FINE: RESPONSE /profileservice  500*
May 2, 2008 12:25:24 PM sun.reflect.NativeMethodAccessorImpl invoke0
FINE: EXCEPTION
java.io.IOException: An existing connection was forcibly closed by the 
remote host
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)
    at sun.nio.ch.IOUtil.read(IOUtil.java:206)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:207)
    at org.mortbay.io.nio.ChannelEndPoint.fill(ChannelEndPoint.java:128)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:282)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at 
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at 
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
May 2, 2008 12:12:32 PM sun.reflect.GeneratedMethodAccessor3 invoke
FINE: EOF

*On the Client side, I see the following error:*

May 2, 2008 12:12:30 PM 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean 
buildServiceFromClass
INFO: Creating Service ProfileService from class 
fluximpl.services.testing.ProfileManager
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault 
occurred while processing.
    at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:218)
    at $Proxy28.getUsername(Unknown Source)
    at fluximpl.services.testing.CXFClient.getUsername(CXFClient.java:69)
    at fluximpl.services.testing.TestClient.main(TestClient.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while 
processing.
    at 
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:70)
    at 
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
    at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at 
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
    at 
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:65)
    at 
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:429)
    at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1988)
    at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1824)
    at 
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:583)
    at 
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:177)
    ... 8 more

Thank you,
Arul

Arul Dhesiaseelan wrote:
> Hi,
>
> I have the following scenario. ProfileManager is a web service 
> contained within CampaignManager web service. I can access the profile 
> manager only through campaign manager.
>
> @WebService
> public class CampaignManagerImpl implements CampaignManager {
> private String name;
> private ProfileManager profileMgr;
>
> @WebMethod
> public String getName() {
>  return name;
> }
>
> @WebMethod
> public ProfileManager getProfileManager() {
>    if (profileMgr != null)
>        profileMgr  = new ProfileManagerImpl();
>     return profileMgr;
> }
>
> }
>
>
> @WebService
> public class ProfileManagerImpl implements ProfileManager {
> private String username;
> private String password;
> private ProfileManager manager;
>
> public ProfileManagerImpl(ProfileManager mgr) {
>    this.manager = mgr;
> }
> @WebMethod
> public String getUsername() {
>    return mgr.getUsername();
> }
>
> @WebMethod
> public String getPassword() {
>     return mgr.getPassword();
> }
> }
>
> When I actually create the campaign service, I  am thinking to do 
> something like this:.
>
>    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
>    sf.setServiceClass(CampaignManager.class);
>    sf.getServiceFactory().setWrapped(true);
>    sf.setServiceName(new QName(NAMESPACE_URI, localPart, ""));
>    sf.setAddress("http://localhost:8080/campaignservice");
>
>    CampaignManager campaignService = new CampaignManagerImpl();
>    ProfileManager profileService = new 
> ProfileManagerImpl(campaignService.getProfileManager());//getting the 
> profile mgr from campaign mgr and creating the profile mgr service.
>    sf.getServiceFactory().setInvoker(new BeanInvoker(campaignService));
>    sf.create();
>
> How do I invoke these services from the CXF client? Is it a valid use 
> case that can be implemented in CXF?
>
> Cheers,
> Arul
>
>
> ________________________________
> Scanned by MessageLabs for Flux
> ________________________________