java - AbstractMethodError using UriBuilder on JAX-RS -
i trying build rest webservice using asynchronous response.
i have looked around error on web, however, none of solutions have worked me. not sure on how go it.
this code rest service, has asyncresponse, , @suspended
taken jar file specified in pom.xml
, provide below. problem is, on deploying war, exception:
java.lang.abstractmethoderror: javax.ws.rs.core.uribuilder.uri(ljava/lang/string;)ljavax/ws/rs/core/uribuilder; javax.ws.rs.core.uribuilder.fromuri(uribuilder.java:119) com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:651) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) note full stack trace of root cause available in apache tomcat/7.0.50 logs
my class follows:
package com.crudapp; import java.util.arraylist; import java.util.list; import java.util.concurrent.callable; import java.util.concurrent.executorservice; import java.util.concurrent.executors; import java.util.concurrent.future; import javax.annotation.generated; import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.produces; import javax.ws.rs.queryparam; import javax.ws.rs.core.response; //import javax.ws.rs.core.uribuilder; import org.json.jsonarray; import org.json.jsonobject; import org.springframework.context.support.classpathxmlapplicationcontext; import com.google.gson.gson; import com.mysql.jdbc.stringutils; import dao.user; import dao.userdao; import dao.userdaoimpl; import javax.ws.rs.container.asyncresponse; import javax.ws.rs.container.suspended; @path("/crudpath") public class entityresource { private final classpathxmlapplicationcontext ctx = new classpathxmlapplicationcontext("/spring.xml"); userdao userdao = null; private final int numofthreads = 10; private final executorservice executorservice = executors.newfixedthreadpool(numofthreads); // userdao.getusers("118"); //ctx.close(); @get @produces("application/json") public response gettuplefromdbasjson(@queryparam("param1") string userid, @suspended final asyncresponse asyncresponse ){ if(stringutils.isnullorempty(userid)) throw new serviceexception("userid passed rest service /crudpath null or empty"); userdao = (userdao==null)? ctx.getbean("userdao", userdaoimpl.class) : userdao; gson gson = new gson(); future<list<user>> futures = executorservice.submit(new daotaskhandlerthread(userid)); list <user> users = new arraylist<user>(); if(futures.isdone()) { try{ users = futures.get(); if(users!= null) return response.status(200).entity( gson.tojson(users).tostring()).build(); } catch(exception ex) { throw new serviceexception(ex); } } return response.status(200).entity(new arraylist<user>().tostring()).build(); /*// crrate new thread.. call dao .. returns result here. jsonobject jsonobject = new jsonobject(); jsonobject.put("key", "value"); return response.status(200).entity( jsonobject.tostring()).build();*/ } private class daotaskhandlerthread implements callable<list<user>>{ //private userdao userdao; private string userid; private daotaskhandlerthread(//userdao userdao, string useridpassed){ ///this.userdao= userdao; userid= useridpassed; } @override public list<user> call() throws exception { // todo auto-generated method stub return userdao.getusers(userid); } } }
my pom.xml
file maven follow:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>restjerseyexample</groupid> <artifactid>restjerseyexample</artifactid> <version>0.0.1-snapshot</version> <packaging>war</packaging> <build> <sourcedirectory>src</sourcedirectory> <plugins> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.4</version> <configuration> <warsourcedirectory>webcontent</warsourcedirectory> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <!-- spring framework added --> <properties> <java-version>1.7</java-version> <org.springframework-version>4.0.3.release</org.springframework-version> </properties> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${org.springframework-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${org.springframework-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${org.springframework-version}</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- spring framework added ends here --> <dependency> <groupid>asm</groupid> <artifactid>asm</artifactid> <version>3.3.1</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-bundle</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>org.json</groupid> <artifactid>json</artifactid> <version>20140107</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-server</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-core</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>org.apache.commons</groupid> <artifactid>commons-dbcp2</artifactid> <version>2.0</version> </dependency> <!-- used httpclient library --> <dependency> <groupid>commons-io</groupid> <artifactid>commons-io</artifactid> <version>2.4</version> </dependency> <dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.3.2</version> </dependency> <!-- async response --> <dependency> <groupid>javax.ws.rs</groupid> <artifactid>javax.ws.rs-api</artifactid> <version>2.0-m12</version> </dependency> </dependencies> </project>
abstractmethoderror
thrown when application tries call abstract method.
uri
abstract method in uribuilder
, need implementation of this. method (with string
parameter) version 2.0
of jax-rs specification.
you're trying use jax-rs 2.0 jersey 1.*. instead, need use jersey 2.* implements jax-rs 2.0 , contains implementation uri
method.
in pom.xml
may remove these dependencies:
<dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-bundle</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-server</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-core</artifactid> <version>1.19</version> </dependency> <dependency> <groupid>javax.ws.rs</groupid> <artifactid>javax.ws.rs-api</artifactid> <version>2.0-m12</version> </dependency>
and use these dependencies:
<dependency> <groupid>org.glassfish.jersey.core</groupid> <artifactid>jersey-server</artifactid> <version>2.17</version> </dependency> <dependency> <groupid>org.glassfish.jersey.containers</groupid> <artifactid>jersey-container-servlet-core</artifactid> <version>2.17</version> </dependency>
using this, uri
method implemented in jerseyuribuilder
class jersey-common
.
edit:
you need change, in web.xml
, servlet com.sun.jersey.spi.container.servlet.servletcontainer
org.glassfish.jersey.servlet.servletcontainer
, init-param
com.sun.jersey.config.property.packages
jersey.config.server.provider.packages
Comments
Post a Comment