users@jersey.java.net

Re: [Jersey] Jersey + Spring + Scheduler - ClassCastException

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 22 Sep 2010 14:43:45 -0700

Hi,

Jersey 1.3 or greater only supports Java SE 6 or greater.


On Sep 22, 2010, at 1:57 AM, premtech11 wrote:

>
> Halo,
>
> i am using spring (with quartz) scheduler and calling my rest
> resource using
> Jersey Client like this
>
> Jersey Versions:jersey-client-1.0.2.jar, jersey-core-1.0.3.1.jar,
> jersey-server-1.0.3.1.jar, jersey-spring-1.0.2.jar
>

You need to ensure that all Jersey jars use the same version and you
should not mix the versions so use either *-1.0.2.jar or -*.1.0.3.1.jar

Paul.

> Web.xml:
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>
> classpath:applicationContext.xml
> classpath:mdm-scheduler-config.xml
> </param-value>
> </context-param>
> <listener>
>
> <listener-
> class>org.springframework.web.context.ContextLoaderListener</
> listener-class>
> </listener>
> <listener>
>
> <listener-class>org.springframework.web.context.request.RequestContextListener
> </listener-class>
> </listener>
> <servlet>
> <servlet-name>MDM RemoteService Application</servlet-name>
>
> <servlet-
> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
> servlet-class>
> <init-param>
> <param-name>com.sun.jersey.config.property.packages</param-name>
> <param-value>de.ckc.sva.mdm</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>MDM RemoteService Application</servlet-name>
> <url-pattern>/webresources/*</url-pattern>
> </servlet-mapping>
> ----------------------
> Client:
> public class ScheduleTimer {
> public void executeJob() {
> System.out.println("Job started at: " + new Date());
> ClientConfig config = new DefaultClientConfig();
> Client client = Client.create(config);
> WebResource service = client.resource("http://localhost:10040/AppContext
> ");
>
> System
> .out
> .println
> (service
> .path("webresources").path("callmpptosendreplymessage").accept(
> MediaType.TEXT_PLAIN).post(String.class));
> -------------
> @Path("receivereplymessage")
> @Component
> @Singleton
> public class MDMRemoteReceiveReplyMessage {
>
> @POST
> @Produces("text/plain")
> public String callMPPtoSendReplyMessage() {
> }
> -----------
> Error:
> 000000ce SystemErr R java.lang.ClassCastException: Cannot cast
> class
> com.sun.jersey.core.impl.provider.entity.StringProvider to interface
> javax.ws.rs.ext.MessageBodyReader
> [21.09.10 18:05:19:657 CEST] 000000ce SystemErr R at
> java.lang.Class.cast(Class.java:1711)
> [21.09.10 18:05:19:657 CEST] 000000ce SystemErr R at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ProviderServices.getProvidersAndServices(ProviderServices.java:122)
> [21.09.10 18:05:19:657 CEST] 000000ce SystemErr R at
> com
> .sun
> .jersey
> .core
> .spi
> .factory.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:
> 136)
> [21.09.10 18:05:19:658 CEST] 000000ce SystemErr R at
> com
> .sun
> .jersey
> .core
> .spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:
> 110)
> [21.09.10 18:05:19:658 CEST] 000000ce SystemErr R at
> com
> .sun
> .jersey
> .core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:105)
> [21.09.10 18:05:19:658 CEST] 000000ce SystemErr R at
> com.sun.jersey.api.client.Client.<init>(Client.java:208)
> [21.09.10 18:05:19:658 CEST] 000000ce SystemErr R at
> com.sun.jersey.api.client.Client.<init>(Client.java:124)
> [21.09.10 18:05:19:659 CEST] 000000ce SystemErr R at
> com.sun.jersey.api.client.Client.create(Client.java:374)
>
> -------------------
>
> Comments:
> When i upgrade all JARs to latest version (1.4), i am getting
> ---
> java.lang.UnsupportedClassVersionError:
> (com/sun/jersey/spi/container/servlet/ServletContainer) bad major
> version at
> offset=6
> ---
> eventhough i build the war file with target="1.5" and source="1.5"
>
> Please help me to fix this problem.
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Jersey-Spring-Scheduler-ClassCastException-tp5558209p5558209.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>