I'm having some trouble invoking a RESTful webservice using the Client Framework provided by RESTEasy. When I try to register the ResteasyProviderFactory I got a ClassCastException and nothing more works.
Here's the code:
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
LifeGoalClient leClient = ProxyFactory.create(LifeGoalClient.class, "http://localhost:8080/TutorFinanceiro");
List<LifeGoal> lifeGoals = leClient.getLifeGoals();
JOptionPane.showMessageDialog(null, lifeGoals);
return lifeGoals;
And the exception:
java.lang.ClassCastException: com.sun.jersey.server.impl.provider.RuntimeDelegateImpl cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory
I'm using Glassfish 3.0.1 and Resteasy 2.2.1.
I searched through the web but found no solution or no relevant info in respect to this.
If anyone have a solution or an alternative way of doing this, please help me!
Thanks in advance
I did force resteasy over jersey in glassfish by adding a file named javax.ws.rs.ext.RuntimeDelegate in the class path at "META-INF/services", wich contain only the following line :
org.jboss.resteasy.spi.ResteasyProviderFactory
However, for me, all seemed to work fine until I try to use resteasy-cdi. Adding that last artifact to my dependencies and configuring the required context-param did dig up the same classcast problem.
This is caused by conflicting jax-rs implementation - jersey and resteasy.
In order to prevent the error above, you can add
<context-param>
<param-name>resteasy.use.deployment.sensitive.factory</param-name>
<param-value>false</param-value>
</context-param>
in your web.xml.
By doing so, resteasy will choose instance of ResteasyProviderFactory.
Related
I'm trying to build a Java service that other services could call.
This service is not a WS, but is calling a RestfulWS.
I'm really just building a wrapper around this call. This would find the correct data it needs, set up the JSON for the call. Get a response and send it back up.
Was told to use Jersey for this. Trying to set up all the pom.xml to use Jersey.
Building code works fine, it is when the deploy to the server happens that things fail.
I get the error -- "JBAS011232: Only one JAX-RS Application Class allowed. "
I don't have a web.xml, which I guess is used to skip some ResetEasy files.
I do have exclusions in pom.xml and jboss-deployment-structure.xml.
I still get the error when deploy happens. Not really sure what else to check.
It looks like you have a problem with JAX-RS dependencies. JBoss already has its own implementation of JAX-RS and probably that’s causing the issue. Some solutions are already suggested here Jboss error: Only one JAX-RS Application Class allowed
I am trying to follow this post's upvoted answer: Best practice for REST token-based authentication with JAX-RS and Jersey
I'm using the CDI approach and in my filter i have the definition:
#Inject
#AuthenticatedUser
Event<String> userAuthenticatedEvent;
But, when I run tomcat 7, I get the following error:
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=Event<String>,parent=AuthenticationFilter,qualifiers={#com.wink.rest.security.annotation.AuthenticatedUser()},position=-1,optional=false,self=false,unqualified=null,567185196)
at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:945)
at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:979)
at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory$2.getInstance(AbstractCdiBeanHk2Factory.java:142)
at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory._provide(AbstractCdiBeanHk2Factory.java:91)
at org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanHk2Factory.provide(GenericCdiBeanHk2Factory.java:63)
I have tried everything I found on google and stackoverflow to try to resolve this, but none of the solutions worked. So now I'm not sure what else to do. Anyone have any advice?
After struggling with the same exact issue I found a solution to that. I switched from TomCat to Glassfish and updated maven dependencies to match the ones from official Jersey 2 documentation. After that it worked like magic.
I'm new to writing web services, and am struggling with understanding how to specify the context root.
I've got my class annotated with
#Service
#javax.jws.WebService(endpointInterface= "com.domain.clientservices.lendingsimulation.model.v1.LendingSimulationServicePortType", targetNamespace="http://www.domain.com/ClientServices/LendingSimulation/V1.2", serviceName="LendingSimulationService", portName="LendingSimulationServicePort")
but I am not sure how to configure the context-root/path for it. I read that I could configure it as a servlet in web.xml, but that seems to be the case for a web service that is not annotate. Am I wrong? I have tried the following configuration in web.xml:
<servlet>
<description>This is the description for the LendingSimulation Service</description>
<display-name>Lending Simulation Service</display-name>
<servlet-name>LendingSimulationService</servlet-name>
<servlet-class>com.domain.clientservices.lendingsimulation.service.LendingSimulationServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LendingSimulationService</servlet-name>
<url-pattern>/WebService</url-pattern>
</servlet-mapping>
however, when I launch in JBoss, I get an error msg:
17:39:33,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/LendingSimulationService].[LendingSimulationService]] (http--127.0.0.1-8080-2) Allocate exception for servlet LendingSimulationService: java.lang.ClassCastException: com.domain.clientservices.lendingsimulation.service.LendingSimulationServiceImpl incompatible with javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1156) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
... (omitted for brevity)
I've read that I can configure jboss-web.xml specifically, but I assume there is a more generic way of doing this that can be applied to all app servers - isn't there? Or must I configure the service independently, depending on the AS that I am deploying to (ie: one way for Tomcat, one way for GlassFish, one way for JBoss, one way for WebSphere, etc...).
Is there an annotation I can use to specify my path for the web-service? Or a config param in the web.xml file?
Thanks!
Eric
Turns out that the JBoss error I was getting was due to the webservices module not being enabled. In JBoss7.0/7.1, you need to run the standalone-preview.xml config to get webservices for an out-of-box download: ie: standalone.sh --server-config=standalone-preview.xml. That eliminated the ClassCast/Servlet exception. However my question still remains if there is not a better/other way to accomplish this (perhaps via annotations) than declaring it as a servlet in web.xml.
I am trying to get schema validation working for a JAX-WS Web Service deployed on Weblogic 10.3.3.
According to the documentation, this should be as simple as adding the annotation
"#SchemaValidation" to the endpoint class. However when I try this the following exception is thrown when the application is deployed:
Caused by: javax.xml.ws.WebServiceException:
Annotation#com.sun.xml.internal.ws.developer.SchemaValidation
(handler=class com.sun.xml.internal.ws.server.DraconianValidationErrorHandler)
is not recognizable,
atleast one constructor of class com.sun.xml.internal.ws.developer.SchemaValidationFeature
should be marked with #FeatureConstructor
at com.sun.xml.ws.binding.WebServiceFeatureList.getWebServiceFeatureBean(WebServiceFeatureList.java:169)
at com.sun.xml.ws.binding.WebServiceFeatureList.parseAnnotations(WebServiceFeatureList.java:141)
The error message is complaining that "com.sun.xml.internal.ws.developer.SchemaValidationFeature" does not have a constructor annotated with #FeatureConstructor. When I look at that class, it sure seems to have one:
#com.sun.xml.internal.ws.api.FeatureConstructor(value={"handler"})
public SchemaValidationFeature(java.lang.Class arg0);
I have googled around but cannot find any reference to this more than this fellow unfortunate soul who did not get any answers. It would be great if someone could point me in the right direction because at this moment I am stuck.
SchemaValidation annotation is working, but make sure you're importing correct class.
com.sun.xml.ws.developer.SchemaValidation
instead of
com.sun.xml.internal.ws.developer.SchemaValidation
The second class is bundled with JDK by default. The first one (used by weblogic) comes from glassfish.jaxws.rt_XXX.jar, so you may need to add this jar to your classpath explicitly.
I have faced the same problem recently.
To overcome this, I added the tag
<validation-request>true</validation-request>
to the file weblogic-webservices.xml
This enabled SOAP request validation on the app-server.
XML Structure of weblogic-webservices.xml
Note : I have not been able to use the #SchemaValidation tag successfully, but the above way - works as expected.
I have been trying to get Resteasy to work (and not it dose). However I now have another headache with accessing the EJB:s. I have tried injecting them, looking them up with jndi and most other solutions but none of them works.
I get massages like: java.lang.RuntimeException: Class is not a root resource.
Or: java.lang.IllegalArgumentException: Wrong target.
Or just: NullPointer
Using JBoss 5.1.0.GA and Resteasy 1.2.1.GA... Can't find any documentation on how this could be done. Do anybody know?
Have you seen this: EJB Integration?
Resteasy currently only has simple integration with EJBs. To make an EJB a JAX-RS resource, you must annotate an SLSB's #Remote or #Local interface with JAX-RS annotations:
Next, in RESTeasy's web.xml file you must manually register the EJB with RESTeasy using the resteasy.jndi.resources