Java REST ful client code is problem

15,472

I suffered the same problem. I found that using the jersey-bundle-1.8.jar instead of client and server library respectively could solve this problem. you can try it.

Share:
15,472
Mohan
Author by

Mohan

Updated on June 28, 2022

Comments

  • Mohan
    Mohan almost 2 years

    I am trying to create the REST-ful web service in java. This REST-ful web service contains both Hibernate configuration and Rest-ful configuration. Actually the java web service is working perfect. but when i am try to execute the client code for that web service.

    The jar files that am using is

    activation
    antlr-2.7.6
    asm-3.1
    asm-attrs
    cglib-nodep
    commons-collections-2.1.1
    commons-fileupload-1.2.1
    commons-io-1.3.2
    commons-logging-1.1
    dom4j-1.6.1
    ehcache-1.2.3
    ejb3-persistence
    grizzly-servlet-webserver-1.7.3.2
    hibernate-annotations
    hibernate-commons-annotations
    hibernate-entitymanager
    hibernate-tools
    hibernate3
    http
    javassist
    jaxb-api
    jaxb-impl
    jaxb-xjc
    jdbc2_0-stdext
    jdom-1.0
    jersey-core-1.7
    jersey-server-1.7
    jersey-spring
    jersey
    jettison-1.0-RC1
    jsr173_api
    jsr311-api
    jta
    mysql-connector-java-5.1.12-bin
    osgi
    rome-0.9
    wadl2java
    

    My problem is

    Exception in thread "main" java.lang.NoSuchMethodError: com.sun.jersey.spi.inject.InjectableProviderContext.getInjectable(Ljava/lang/Class;Lcom/sun/jersey/spi/service/ComponentContext;Ljava/lang/annotation/Annotation;Ljava/lang/Object;Ljava/util/List;)Lcom/sun/jersey/spi/inject/Injectable;
            at com.sun.jersey.spi.service.ComponentConstructor.getConstructor(ComponentConstructor.java:139)
            at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:177)
            at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:122)
            at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:133)
            at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:107)
            at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:102)
            at com.sun.jersey.api.client.Client.<init>(Client.java:284)
            at com.sun.jersey.api.client.Client.<init>(Client.java:209)
            at com.sun.jersey.api.client.Client.create(Client.java:429)
            at pack1.client.Test.main(Test.java:20)
    

    Client Java code is

    package pack1.client;
    
    import java.net.URI;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.UriBuilder;
    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.ClientResponse;
    import com.sun.jersey.api.client.WebResource;
    import com.sun.jersey.api.client.config.ClientConfig;
    import com.sun.jersey.api.client.config.DefaultClientConfig;
    
    public class Test {
        public static void main(String[] args) {
            ClientConfig config = new DefaultClientConfig();
            Client client = Client.create(config);
            WebResource service = client.resource(getBaseURI());
            System.out.println(service.path("resources").path("hello").path("xml").accept(
                            MediaType.TEXT_PLAIN).get(ClientResponse.class));
        }
        private static URI getBaseURI() {
                return UriBuilder.fromUri("http://localhost/WebServicePgm1").build();
        }
    }
    

    The method that am trying to test in client code which is

        @GET
        @Path("xml")
        @Produces(MediaType.TEXT_XML)
        public String sayXMLHello() {
            return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey </hello>";
        }
    

    After Changing the jar file

    the above problem is solved and new problem gets occured.

    @ gkatkov am using Apache Tomcat 6.0.20 and now. i have updated the jersey jar to jersey 1.8. after updating the jar file am getting another error that is

    Jar file that i put now is

    jersey-server-1.8.jar
    jersey-json-1.8.jar
    jersey-core-1.8.jar
    jersey-client-1.8.jar
    

    Now the problem is

    com.sun.jersey.spi.inject.Errors processErrorMessages
    SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
      SEVERE: Missing dependency for field: javax.ws.rs.core.UriInfo com.sun.jersey.impl.template.ViewableMessageBodyWriter.ui
      SEVERE: Missing dependency for field: com.sun.jersey.spi.template.TemplateContext com.sun.jersey.impl.template.ViewableMessageBodyWriter.tc
    Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException
            at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
            at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
            at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
            at com.sun.jersey.api.client.Client.<init>(Client.java:187)
            at com.sun.jersey.api.client.Client.<init>(Client.java:170)
            at com.sun.jersey.api.client.Client.create(Client.java:679)
            at pack1.client.Test.main(Test.java:20)
    

    do i need to put any other jar files?