Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey restful service communication (IncompatibleClassChangeError)

I`ve created a restful service facade based on jersey 1.12 on the JDK 1.6 http server. When I start my application in eclipse everything works fine. I can communicate with the facade without any troubles but when I start my application via the console with my startup script I got an IncompatibleClassChangeError when I access the service.

I was able to narrow down the problem. The problem is by sending the response. Because I can communicate with the service normally (the request is processed) but I don´t get a response. Do you have any clue about this?

startup script

#!/usr/bin/env bash
libpath=
for i in $(ls lib/*|grep ".jar"); do 
    libpath=$( echo "$i:$libpath"); 
done
java -cp "$(echo $libpath)build/jar/myjar.jar" org.....Startup

Exception that will be thrown

WARNUNG: Class org....facade.ServiceFacadeImpl is ignored as an instance is registered in the set of singletons
Call getMutationList: NP_005378
Exception in thread "pool-1-thread-1" java.lang.IncompatibleClassChangeError: Class javax.ws.rs.core.Response$Status does not implement the requested interface javax.ws.rs.core.Response$StatusType

Part of my facade

@GET
@Path("/mutations/{id}/{from}/{size}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public MutationPosContainer getMutationList(@PathParam("id") String id,
        @PathParam("from") Integer from, @PathParam("size") Integer size) {
    ...
    if (posContainer == null)
        throw new BadRequestException();
    else
        return posContainer;
}

Application Handler

public class SnapDbApplication extends Application {
  private ServiceFacade facade;

  public SnapDbApplication(ServiceFacade facade) {
      this.facade = facade;
  }

  @Override
  public Set<Class<?>> getClasses() {
      Set<Class<?>> s = new HashSet<Class<?>>();
      s.add(this.facade.getClass());
      return s;
  }


  @Override
  public Set<Object> getSingletons() {
      Set<Object> s = new HashSet<Object>();
      s.add(this.facade);
      return s;
  } 
}

Edit: classpath

java -cp 
lib/xstream-1.4.2.jar:lib/xmlbeans-2.3.0.jar:lib/xml-resolver-1.2.jar:lib/xalan-2.7.0.jar:
lib/wstx-asl-3.2.9.jar:lib/wsdl4j-1.6.2.jar:lib/woden-impl-dom-1.0M9.jar:lib/woden-impl-commons-1.0M9.jar:
lib/woden-api-1.0M9.jar:lib/tribes-6.0.16.jar:lib/snpxsd.jar:
lib/regexp-1.2.jar:lib/org.springframework.web.struts-sources-3.1.1.RELEASE.jar:
lib/org.springframework.web.struts-3.1.1.RELEASE.jar:
lib/org.springframework.web.servlet-sources-3.1.1.RELEASE.jar:
lib/org.springframework.web.servlet-3.1.1.RELEASE.jar:
...
:lib/jersey-server-1.12.jar:lib/jersey-multipart-1.12.jar:lib/jersey-json-1.12.jar:
lib/jersey-core-1.12.jar:lib/jersey-client-1.12.jar:lib/jaxws-tools-2.1.3.jar:lib/jaxen-1.1.1.jar:lib/jaxb-xjc-2.1.7.jar:
lib/jaxb-impl-2.1.7.jar:lib/jaxb-api-2.1.jar:
lib/jalopy-1.5rc3.jar:lib/httpcore-4.0.jar:
lib/http-20070405.jar:lib/hamcrest-library-1:build/jar/myapp.jar
org.startup.Startup
like image 731
martin s Avatar asked Apr 16 '12 00:04

martin s


1 Answers

You probably have an incompatible version of jsr311 in your classpath (see 1). Remove it and it should run fine.

like image 167
Brutos Avatar answered Oct 19 '22 11:10

Brutos