salesforce-marketingcloud / FuelSDK-Java

Salesforce Marketing Cloud Java SDK
BSD 3-Clause "New" or "Revised" License
73 stars 122 forks source link

seistub cannot be cast to org.apache.cxf.frontend.clientproxy #54

Open cqsapient opened 7 years ago

cqsapient commented 7 years ago

I am trying to use the fuelsdk in an osgi environment. I am getting this error -

java.lang.ClassCastException: com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy

This is because OSGi loads the system bundle before the bundle in which fuelsdk's dependency has been embedded. I have been suggested to create the client using -

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://localhost:9000/helloWorld"); soapClient = (Client) factory.create();

I would like to know which class should I use in factory.setServiceClass();

and

which address should I use in factory.setAddress( ) ; is it the endpoint address ? -- https://webservice.s6.exacttarget.com/Service.asmx

Help is highly appreciated Thanks

amagar088 commented 7 years ago

@cqsapient you are correct about URl. And as for service class, I am not sure what is your requirement. But for starter let me tell you, ET_Client is the base class that is being inherited by all objects which are used for transaction. Please let me know, if that helps and do let me know your requirement for further help.

cqsapient commented 7 years ago

Thanks for your comment. For service class; I want to know what service class should I set in

factory.setServiceClass()

for the API calls(retrieve; add; update) to work properly. It is the normal client creation using JaxWsProxyFactoryBean ; I am looking for the service class which I can set here for client creation.

amagar088 commented 7 years ago

@cqsapient, please correct me if I am wrong, but basically you want to create a client (a single one) through which you can handle all request, right ? If you intend to do the above, use ETSoapObject. Just a tweak, in the code snippet above, you need to replace "(Client)" with "(ETSoapObject)" to make it work

cqsapient commented 7 years ago

When I use ETClient as the service class;

factory.setServiceClass(ETClient.class);

I get the error -

Exception in thread "main" java.lang.IllegalArgumentException: com.exacttarget.fuelsdk.ETClient is not an interface at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:624) at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:592) at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:244) at java.lang.reflect.WeakCache.get(WeakCache.java:141) at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:455) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:738) at org.apache.cxf.common.util.ProxyHelper.getProxyInternal(ProxyHelper.java:47) at org.apache.cxf.common.util.ProxyHelper.getProxy(ProxyHelper.java:96) at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:175) at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:98) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:153) at com.exacttarget.fuelsdk.ETClient.(ETClient.java:168) at com.exacttarget.fuelsdk.ETClient.(ETClient.java:110) at com.exacttarget.fuelsdk.ClientTesting.main(ClientTesting.java:11)

cqsapient commented 7 years ago

Hi @amagar088 ,

When I set ETSoapObject in factory.setServiceClass(ETSoapObject.class);

I get the same error --

Exception in thread "main" java.lang.IllegalArgumentException: com.exacttarget.fuelsdk.ETSoapObject is not an interface at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:624) at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:592) at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:244) at java.lang.reflect.WeakCache.get(WeakCache.java:141) at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:455) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:738) at org.apache.cxf.common.util.ProxyHelper.getProxyInternal(ProxyHelper.java:47) at org.apache.cxf.common.util.ProxyHelper.getProxy(ProxyHelper.java:96) at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:175) at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:98) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:153) at com.exacttarget.fuelsdk.ETClient.(ETClient.java:168) at com.exacttarget.fuelsdk.ETClient.(ETClient.java:110) at com.exacttarget.fuelsdk.ClientTesting.main(ClientTesting.java:11)

When I use ETSoapObject in place of client;

soapClient = (ETSoapObject) factory.create();

I get compilation Error --

Type mismatch: cannot convert from ETSoapObject to Client

gharperhs2 commented 7 years ago

Same. It's really annoying trying to work with this API - documentation is awful. So assuming I haven't missed something, here's what I've tried: You can look up tips from people on StackExchange who suggest: 1) use a different version, it might magically work 2) set XML options in META-INF directory, so as to stop the conflict. None of this has worked for me.

I was getting:

Exception processing SF export: null java.lang.NullPointerException at org.apache.cxf.wsdl11.WSDLServiceFactory.(WSDLServiceFactory.java:85) at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:218) at org.apache.cxf.jaxws.ServiceImpl.initialize(ServiceImpl.java:161) at org.apache.cxf.jaxws.ServiceImpl.(ServiceImpl.java:129) at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:82) at javax.xml.ws.Service.(Service.java:77) at com.exacttarget.fuelsdk.internal.PartnerAPI.(PartnerAPI.java:49) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:88) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:178) at com.exacttarget.fuelsdk.ETClient.(ETClient.java:158)

So I tried: http://stackoverflow.com/questions/6364333/jax-ws-when-apache-cxf-is-installed-it-steals-default-jdk-jax-ws-implementat/

Which says to: Create a file in: /src/main/resources/META-INF/services/javax.xml.ws.spi.Provider with contents: org.apache.cxf.jaxws.spi.ProviderImpl

On building:

Exception processing SF export: com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy

amagar088 commented 7 years ago

I will work and provide you the working example by Tuesday.

gharperhs2 commented 7 years ago

Should be obvious but- A toy project with no conflicting dependencies works just fine for me. This problem is only cropping up in a multi-module project where we're using maven-shade's automatic dependency detection to create one JAR file. It seems like using Jersey / glassfish in another part of your project is one common way to cause this issue.

amagar088 commented 7 years ago

It would be great, if you can point out some cross cutting points, that I should integrate in a sample project. I can work on that and provide you with a sample project

gharperhs2 commented 7 years ago

I don't know enough about Maven's internals, I have another dev looking into the issue and I'll see if he can post what he has discovered.

This issue has been posted on StackOverflow, as in the example I posted, which leads to some examples. I got here by googling "SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy" it seems to be a common problem, lots of examples out there.

Several of those examples mention Jersey/glassfish, which our project uses, so I suspect that's a contributor but I'm not 100%.

I also tried telling Glassfish or Sun not to interfere as per: http://stackoverflow.com/questions/2064068/how-to-pick-cxf-over-metro-on-glassfish ...but neither of those seemed to do anything.

amagar088 commented 7 years ago

Thanks for the input, i will try to implement a project taking into consideration on all the above mentioned points.

amagar088 commented 7 years ago

I am trying to complete the project ASAP but, due to unavoidable circumstances it might get a bit delay. Will post here once done with the project.

gharperhs2 commented 7 years ago

Our maven guru says: "following the second answer on here I got the SF job to run without throwing a nullpointerexcetpion" http://stackoverflow.com/questions/9069138/apache-cxf-client-loads-fine-in-eclipse-but-standalone-jar-throws-nullpointerexc

"The fix was adding the 'transformer' sections for the CFX configuration files in as part of the shade plugin settings"

...however I just found that ETSubscriber doesn't implement Attributes, which my client has to have, so Fuel SDK may be unusable for me anyway.

amagar088 commented 7 years ago

Attributes are being implemented in the objects in the sdk. Same has been to be done in java.

amagar088 commented 7 years ago

This will be built in near future.

amagar088 commented 7 years ago

Can you please try this code and let me know if that works.

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(Soap.class);
    factory.setAddress("https://webservice.exacttarget.com/Service.asmx");
    factory.setWsdlLocation("https://webservice.exacttarget.com/etframework.wsdl");
    Soap soapClient = (Soap)factory.create();
mariogalic commented 7 years ago

Using latest release 1.1.0 I get the same error when instantiating new ETClient(etConf):

com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy: java.lang.ClassCastException
java.lang.ClassCastException: com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy
    at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:128)
    at com.exacttarget.fuelsdk.ETSoapConnection.<init>(ETSoapConnection.java:90)
    at com.exacttarget.fuelsdk.ETSoapConnection.<init>(ETSoapConnection.java:179)
    at com.exacttarget.fuelsdk.ETClient.<init>(ETClient.java:158)
ratneshjd commented 7 years ago

This solution will help, though need to migrate to cxf from jaxws. https://stackoverflow.com/questions/6364333/jax-ws-when-apache-cxf-is-installed-it-steals-default-jdk-jax-ws-implementat

akshaymalik03 commented 6 years ago

I am facing the same issue. Neither of the solution helps. Any suggestions would be appreciated ?

Srikanth-GitHub commented 3 years ago

Using fuelsdk 1.5.0, facing the same issue. Anyone has a resolution for this? highly appreciated your help! - Thanks java.lang.ClassCastException: com.sun.xml.internal.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:127) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:103) at com.exacttarget.fuelsdk.ETSoapConnection.(ETSoapConnection.java:210) at com.exacttarget.fuelsdk.ETClient.buildClients(ETClient.java:219)

Ionut-Mihai-Vladasel commented 1 year ago

Hi, any news on this issue?