You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by miloslavskacel <mi...@gmail.com> on 2011/12/29 10:50:08 UTC

How to call 2 CXF dynamic clients?

A try to call two CXF-2.5.0 dynamic clients fails with: 
org.apache.cxf.interceptor.Fault: Marshalling Error:
net.webservicex.GetWeather is not known to this context



package my.test;

import javax.xml.namespace.QName;

import org.apache.cxf.endpoint.Client;

import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class TwoDynClients {

    public static void main(String[] args) throws Exception {

        JaxWsDynamicClientFactory dcf =
JaxWsDynamicClientFactory.newInstance();

        Client clientA =
dcf.createClient("http://www.webservicex.net/stockquote.asmx?WSDL");

        Object[] resultA = clientA.invoke(new
QName("http://www.webserviceX.NET/", "GetQuote"), "GOOG");

        System.out.println("resultA: " + resultA[0]);

        Client clientB =
dcf.createClient("http://www.webservicex.net/GlobalWeather.asmx?wsdl");

        Object[] resultB = clientB.invoke(new
QName("http://www.webserviceX.NET", "GetWeather"), new Object[]
{"Stuttgart", "Germany"} );

        System.out.println("resultB: " + resultB[0]);

    }

}



The output of snippet above is:


29.12.2011 9:37:12 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames

INFO: Created classes: net.webservicex.GetQuote,
net.webservicex.GetQuoteResponse, net.webservicex.ObjectFactory

resultA: GOOG639.7012/28/20114:00pm0.00N/AN/AN/A0207.2B639.700.00%473.02 -
645.0029.33721.81Google Inc.

29.12.2011 9:37:22 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames

INFO: Created classes: net.webservicex.GetCitiesByCountry,
net.webservicex.GetCitiesByCountryResponse, net.webservicex.GetWeather,
net.webservicex.GetWeatherResponse, net.webservicex.ObjectFactory

29.12.2011 9:37:24 org.apache.cxf.phase.PhaseInterceptorChain
doDefaultLoggingv
WARNING: Interceptor for
{http://www.webserviceX.NET}GlobalWeather#{http://www.webserviceX.NET}GetWeather
has thrown exception, unwinding now

org.apache.cxf.interceptor.Fault: Marshalling Error:
net.webservicex.GetWeather is not known to this context

    at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:261)





  
When order of clients is changed the second fails.
  
Is it OK to use one JaxWsDynamicClientFactory to create both clients?


Thanks.

--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-call-2-CXF-dynamic-clients-tp5107299p5107299.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to call 2 CXF dynamic clients?

Posted by Miloslav Skacel <mi...@gmail.com>.
Thank you. I've tried it and found:
a) only usage of separate JaxWsDynamicClientFactory per client does not
help. Exception still appears.
b) only setting context class loader helps.
     Is this a correct way on app servers? There is a scary comment
in ClassLoaderUtils:
/**
 * This class is extremely useful for loading resources and classes in a
fault
 * tolerant manner that works across different applications servers. Do not
 * touch this unless you're a grizzled classloading guru veteran who is
going to
 * verify any change on 6 different application servers.
 */

c) a+b together works also

Is passing of classLoader to createClient(), as below, equivalent to
reseting it as you suggested? (it works)

JaxWsDynamicClientFactory dcfA = JaxWsDynamicClientFactory.newInstance();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
 Client clientA = dcfA.createClient("
http://www.webservicex.net/stockquote.asmx?WSDL");
Object[] resultA = clientA.invoke(new QName("http://www.webserviceX.NET/",
"GetQuote"), "GOOG");
System.out.println("resultA: " + resultA[0]);
Client clientB = dcfA.createClient("
http://www.webservicex.net/GlobalWeather.asmx?wsdl", cl);
Object[] resultB = clientB.invoke(new QName("http://www.webserviceX.NET",
"GetWeather"), new Object[] {"Stuttgart", "Germany"} );
System.out.println("resultB: " + resultB[0]);

Miloslav

On Wed, Jan 4, 2012 at 4:28 PM, Daniel Kulp <dk...@apache.org> wrote:

>
> One thing you can try, before and between the calls to
> JaxWsDynamicClientFactory, reset the context classloader.  Also, use a
> separate JaxWsDynamicClientFactory per client.
>
> aka:
>
> ClassLoader cl = Thread.currentThread().getContextClassloader();
>
>  JaxWsDynamicClientFactory dcf =
>      JaxWsDynamicClientFactory.newInstance();
>  Client clientA =  dcf.createClient(".....");
>
> Thread.currentThread().setContextClassloader(cl);
>
> dcf =
>      JaxWsDynamicClientFactory.newInstance();
>  Client clientb =  dcf.createClient(".....");
>
> etc....
>
>
>
>
>
> On Thursday, December 29, 2011 1:50:08 AM miloslavskacel wrote:
> > A try to call two CXF-2.5.0 dynamic clients fails with:
> > org.apache.cxf.interceptor.Fault: Marshalling Error:
> > net.webservicex.GetWeather is not known to this context
> >
> >
> >
> > package my.test;
> >
> > import javax.xml.namespace.QName;
> >
> > import org.apache.cxf.endpoint.Client;
> >
> > import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
> >
> > public class TwoDynClients {
> >
> >     public static void main(String[] args) throws Exception {
> >
> >         JaxWsDynamicClientFactory dcf =
> > JaxWsDynamicClientFactory.newInstance();
> >
> >         Client clientA =
> > dcf.createClient("http://www.webservicex.net/stockquote.asmx?WSDL");
> >
> >         Object[] resultA = clientA.invoke(new
> > QName("http://www.webserviceX.NET/", "GetQuote"), "GOOG");
> >
> >         System.out.println("resultA: " + resultA[0]);
> >
> >         Client clientB =
> > dcf.createClient("http://www.webservicex.net/GlobalWeather.asmx?wsdl");
> >
> >         Object[] resultB = clientB.invoke(new
> > QName("http://www.webserviceX.NET", "GetWeather"), new Object[]
> > {"Stuttgart", "Germany"} );
> >
> >         System.out.println("resultB: " + resultB[0]);
> >
> >     }
> >
> > }
> >
> >
> >
> > The output of snippet above is:
> >
> >
> > 29.12.2011 9:37:12 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames
> >
> > INFO: Created classes: net.webservicex.GetQuote,
> > net.webservicex.GetQuoteResponse, net.webservicex.ObjectFactory
> >
> > resultA: GOOG639.7012/28/20114:00pm0.00N/AN/AN/A0207.2B639.700.00%473.02
> -
> > 645.0029.33721.81Google Inc.
> >
> > 29.12.2011 9:37:22 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames
> >
> > INFO: Created classes: net.webservicex.GetCitiesByCountry,
> > net.webservicex.GetCitiesByCountryResponse, net.webservicex.GetWeather,
> > net.webservicex.GetWeatherResponse, net.webservicex.ObjectFactory
> >
> > 29.12.2011 9:37:24 org.apache.cxf.phase.PhaseInterceptorChain
> > doDefaultLoggingv
> > WARNING: Interceptor for
> > {http://www.webserviceX.NET}GlobalWeather#{http://www.webserviceX.NET
> }GetWea
> > ther has thrown exception, unwinding now
> >
> > org.apache.cxf.interceptor.Fault: Marshalling Error:
> > net.webservicex.GetWeather is not known to this context
> >
> >     at
> >
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:261)
> >
> >
> >
> >
> >
> >
> > When order of clients is changed the second fails.
> >
> > Is it OK to use one JaxWsDynamicClientFactory to create both clients?
> >
> >
> > Thanks.
> >
> > --
> > View this message in context:
> >
> http://cxf.547215.n5.nabble.com/How-to-call-2-CXF-dynamic-clients-tp5107299
> > p5107299.html Sent from the cxf-user mailing list archive at Nabble.com.
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>

Re: How to call 2 CXF dynamic clients?

Posted by Daniel Kulp <dk...@apache.org>.
One thing you can try, before and between the calls to 
JaxWsDynamicClientFactory, reset the context classloader.  Also, use a 
separate JaxWsDynamicClientFactory per client.

aka:

ClassLoader cl = Thread.currentThread().getContextClassloader();

 JaxWsDynamicClientFactory dcf =
      JaxWsDynamicClientFactory.newInstance();
  Client clientA =  dcf.createClient(".....");

Thread.currentThread().setContextClassloader(cl);

dcf =
      JaxWsDynamicClientFactory.newInstance();
  Client clientb =  dcf.createClient(".....");

etc....





On Thursday, December 29, 2011 1:50:08 AM miloslavskacel wrote:
> A try to call two CXF-2.5.0 dynamic clients fails with:
> org.apache.cxf.interceptor.Fault: Marshalling Error:
> net.webservicex.GetWeather is not known to this context
> 
> 
> 
> package my.test;
> 
> import javax.xml.namespace.QName;
> 
> import org.apache.cxf.endpoint.Client;
> 
> import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
> 
> public class TwoDynClients {
> 
>     public static void main(String[] args) throws Exception {
> 
>         JaxWsDynamicClientFactory dcf =
> JaxWsDynamicClientFactory.newInstance();
> 
>         Client clientA =
> dcf.createClient("http://www.webservicex.net/stockquote.asmx?WSDL");
> 
>         Object[] resultA = clientA.invoke(new
> QName("http://www.webserviceX.NET/", "GetQuote"), "GOOG");
> 
>         System.out.println("resultA: " + resultA[0]);
> 
>         Client clientB =
> dcf.createClient("http://www.webservicex.net/GlobalWeather.asmx?wsdl");
> 
>         Object[] resultB = clientB.invoke(new
> QName("http://www.webserviceX.NET", "GetWeather"), new Object[]
> {"Stuttgart", "Germany"} );
> 
>         System.out.println("resultB: " + resultB[0]);
> 
>     }
> 
> }
> 
> 
> 
> The output of snippet above is:
> 
> 
> 29.12.2011 9:37:12 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames
> 
> INFO: Created classes: net.webservicex.GetQuote,
> net.webservicex.GetQuoteResponse, net.webservicex.ObjectFactory
> 
> resultA: GOOG639.7012/28/20114:00pm0.00N/AN/AN/A0207.2B639.700.00%473.02 -
> 645.0029.33721.81Google Inc.
> 
> 29.12.2011 9:37:22 org.apache.cxf.jaxb.JAXBUtils logGeneratedClassNames
> 
> INFO: Created classes: net.webservicex.GetCitiesByCountry,
> net.webservicex.GetCitiesByCountryResponse, net.webservicex.GetWeather,
> net.webservicex.GetWeatherResponse, net.webservicex.ObjectFactory
> 
> 29.12.2011 9:37:24 org.apache.cxf.phase.PhaseInterceptorChain
> doDefaultLoggingv
> WARNING: Interceptor for
> {http://www.webserviceX.NET}GlobalWeather#{http://www.webserviceX.NET}GetWea
> ther has thrown exception, unwinding now
> 
> org.apache.cxf.interceptor.Fault: Marshalling Error:
> net.webservicex.GetWeather is not known to this context
> 
>     at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:261)
> 
> 
> 
> 
> 
> 
> When order of clients is changed the second fails.
> 
> Is it OK to use one JaxWsDynamicClientFactory to create both clients?
> 
> 
> Thanks.
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-call-2-CXF-dynamic-clients-tp5107299
> p5107299.html Sent from the cxf-user mailing list archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com