Making Servlet 2.5 code Servlet 3.0 compatible and vice versa - java

I have a class that implements javax.servlet.Filter and inside that filter, I'm instantiating an instance of InterceptHttpRequestFilter and InterceptHttpResponseFilter (which are used to modify the incoming and outgoing request and response)
Example:
public class InterceptHttpRequestFilter implements HttpServletRequest {
private HttpServletRequest httpReq;
final StringBuffer sb = new StringBuffer();
public InterceptHttpRequestFilter(ServletRequest request) {
this.httpReq = (HttpServletRequest) request;
try {
StringWriter sw = new StringWriter();
IOUtils.copy(request.getInputStream(), sw);
sb.append(sw.getBuffer().toString());
} catch (IOException e) {
e.printStackTrace();
}
}
....
When deploying this project on Tomcat6 using Servlet 2.5, everything works as it should.
Deploy it on Tomcat 7 and I get an AbstractMethodError:
SEVERE: Servlet.service() for servlet [_______] in context with path [/__________-1.0.0] threw exception [Filter execution threw an exception] with root cause
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:225)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.mycee.project.filter.MyFilter.doFilter(MyFilter.java:182)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
The obvious solution is to implement all the missing methods required by Servlet Version 3's HttpRequest / Response interfaces.
The maven dependency on mvnrepository is still in alpha:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
So my question is, does middle ground exist that will allow me to run this project on both Tomcat6 (Servlet 2.5) and Tomcat7 (Servlet 3.0) without having to tinker with my InterceptHttpRequestFilter and InterceptHttpResponseFilter ?

That's why it's recommended to extend HttpServletRequestWrapper instead of implementing HttpServletRequest directly.
HttpServletRequestWrapper has implementations of all required methods, therefore it should solve the problem.

Related

Having a verify error with solrj 5.5.0 and java 1.7

I get a java.lang.VerifyError: Cannot inherit from final class exception when executing HttpSolrClient solr = new HttpSolrClient("http://localhost:8983/solr/mycore");
I use SolrJ 5.5.0 with Java 1.7. Other than that I use commons-httpclient 3.1. This is the detailed error I get:
Handler processing failed; nested exception is java.lang.VerifyError: org/apache/http/params/SyncBasicHttpParams] with root cause
java.lang.VerifyError: org/apache/http/params/SyncBasicHttpParams
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:466)
at org.apache.solr.client.solrj.impl.HttpClientUtil.setFollowRedirects(HttpClientUtil.java:290)
at org.apache.solr.client.solrj.impl.HttpClientConfigurer.configure(HttpClientConfigurer.java:58)
at org.apache.solr.client.solrj.impl.HttpClientUtil.configureClient(HttpClientUtil.java:149)
at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:125)
at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:188)
at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:161)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
There were 2 httpcore libs(httpcore 4.0 from axis2 1.6.2 and httpcore 4.4.1 from solrj 5.5.0) in my .m2 folder. Removing httpcore 4.0 helped me to fix the problem. The reason is org.apache.http.params.BasicHttpParams class in httpcore 4.0 is a final class.

HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception

index.html
<html>
<body>
<h2>Jersey RESTful Web Application!</h2>
<p>Jersey resource
<p>Visit the Project Jersey website
for more information on Jersey!
</body>
</html>
MyResource.java
#Path("/myresource")
public class MyResource {
/** Method processing HTTP GET requests, producing "text/plain" MIME media
* type.
* #return String that will be send back as a response of type "text/plain".
*/
#GET
#Produces("text/plain")
public String getIt() {
return "Hi there!";
}
}
Error is Comming
HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception
--------------------------------------------------------------------------------
type Exception report
message Servlet.init() for servlet Jersey Web Application threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
com.sun.jersey.spi.scanning.AnnotationScannerListener.<init>(AnnotationScannerListener.java:94)
com.sun.jersey.spi.scanning.PathProviderScannerListener.<init>(PathProviderScannerListener.java:59)
com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs.
you would have use correct version if you want proper output latest version number is 1.19.1 use this try onee
May be problem with servelet api dependcy :
use this in your maven pom for exemple:
<!-- servlet api 3 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Its seems a java version issue. compile the code with supporting jar(java version) only

Can't lookup EJB bean from Tomcat

EJB application is deployed to Glassfish 3.1.2.2 on server A and servlet is deployed to Tomcat 7 on server B. Lookup from standalone app works fine, lookup from servlet throws NameNotFoundException.
Set of libraries (from Glassfish modules directory) used in both cases is exactly the same. So we assume some additional configuration for Tomcat is required.
Relevant code from servlet deployed to Tomcat:
InitialContext ctx;
try {
Properties props = new Properties();
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
System.setProperty("java.security.auth.login.config", "jaas.config");
ProgrammaticLogin pl = new ProgrammaticLogin();
pl.login("user", "s3cret".toCharArray(), "file", true);
ctx = new InitialContext(props);
HelloBean helloBean = (HelloBean) ctx.lookup("java:global/HelloApp/HelloBeanImpl!app.hello.HelloBean");
} catch (Exception e) {
e.printStackTrace(System.err);
}
Exception is always the same and there is no usefull information in getCause:
javax.naming.NameNotFoundException: Name [global/HelloApp/HelloBeanImpl!app.hello.HelloBean] is not bound in this Context. Unable to find [global].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at app.servlet.HelloServlet.doGet(HelloServlet.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
OK, we are able to lookup secured beans from Tomcat now. You will need to put a lot of Glassfish specific jars to classpath for this to work. We have used shared loader in catalina.properties to define path to jars from Glassfish modules directory (you will probably need to exclude all servlet and jsp jars to avoid conflict with Tomcat own lib). Also make sure you don't accidentally put two security.jar to classpath. The working config looks like this:
InitialContext ctx;
try {
Properties props = new Properties();
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty(Context.STATE_FACTORIES, "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.enterprise.naming");
System.setProperty("java.security.auth.login.config", "./jaas.config");
ProgrammaticLogin pl = new ProgrammaticLogin();
boolean loginSuccessfull = pl.login("username", "password".toCharArray());
ctx = new InitialContext(props);
HelloBean helloBean = (HelloBean) ctx.lookup("java:global/HelloApp/HelloBeanImpl!app.hello.HelloBean");
resp.getOutputStream().print(helloBean.sayHelloTo("user"));
} catch (Exception e) {
e.printStackTrace(System.err);
}

SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user '<<USERNAME>>'#'SERVERIP' (using password: YES))

I'm having an OpenShift site which is trying to connect to an external MySQL server. Below is the code I have so far.
public class BaseDAO {
static final String DB_DRIVER = "com.mysql.jdbc.Driver";
DataSource datasource;
public BaseDAO() {
System.out.println("+++++ " +Calendar.getInstance().getTime());
try{
InitialContext ic = new InitialContext();
Context initialContext = (Context) ic.lookup("java:comp/env");
datasource = (DataSource) initialContext.lookup("jdbc/MySQLDS");
Class.forName(DB_DRIVER).newInstance();
} catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e.getCause());
}
}
}
All my DAO classes extend the BaseDAO so I won't have to type all of this 5-6 times.
After some configuration, this does work on a local MySQL server. I have created a small application that either sends me to the index.jsp when the array gathered from the database is not null or not empty, and sends me to the about.jsp if it either is empty or null.
Now in both the local and the external database I have create a table with the same name, column 'day' and inserted 1 value. When I run this locally it sends me to the index page, but when I run this via my OpenShift webpage it sends me to the about page.
This is the error found in the SSH/app-root/logs/jbossews.log (username and serverip commented out)
:
NOTE: THE SERVERIP AND LOGINCREDENTIALS ARE PROVIDED BY THE DATASOURCE OF OPENSHIFT
The path to the DAO is: OpeningsTijdenServlet --> (static)ServiceProvider --> OTService --> OpeningsTijdenDAO (extends BaseDAO)
INFO: Server startup in 10894 ms
+++++ Mon Oct 12 16:07:51 EDT 2015
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user '<<USERNAME>>'#'SERVERIP' (using password: YES))
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1551)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1390)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1046)
at main.java.database.OpeningsTijdenDAO.selectTijden(OpeningsTijdenDAO.java:16)
at main.java.database.OTService.getTijden(OTService.java:13)
at main.java.servlets.GetTijdenServlet.doPost(GetTijdenServlet.java:17)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1042)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Access denied for user '<<USERNAME>>'#'SERVERNAME' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
Something wrong with your credential. try to change credential or server configuration.
Any of the hosting server you have to select "localhost"/"127.0.0.1" as your DB Host.

Unable to send Response from Rest method

Here is the rest ws POST method code:
#POST
#Path("/json/saveuser")
#Consumes("application/json")
public ResponseBuilder saveUserJSON(User user) {
if (save(user)) {
return Response.status(HttpStatus.SC_OK);
}
return Response.status(HttpStatus.SC_BAD_REQUEST);
}
User is saved properly in DB.
But the line Response.status(HttpStatus.SC_OK); and Response.status(HttpStatus.SC_BAD_REQUEST);, is throwing below error:
Mar 06, 2015 1:38:49 PM com.sun.jersey.spi.container.ContainerResponse traceException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.sun.jersey.core.spi.factory.ResponseBuilderImpl, and Java type class javax.ws.rs.core.Response$ResponseBuilder, and MIME media type application/octet-stream was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:278)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1326)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class com.sun.jersey.core.spi.factory.ResponseBuilderImpl, and Java type class javax.ws.rs.core.Response$ResponseBuilder, and MIME media type application/octet-stream was not found
... 28 more
Did googling. And according to the posts in SO and other sites, added the jars as listed below (Some additional jars are also added for other dependency):
antlr-2.7.7.jar
com.sun.jersey.jersey-core-1.4.0.jar
com.sun.jersey.jersey-server-1.4.0.jar
dom4j-1.6.1.jar
gcm.server.jar
genson-0.98.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
http-core-4.1.jar
jackson-all-1.9.0.jar
jackson-annotations-2.2.2.jar
jackson-core-2.2.2.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-3.1.4.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jersey-bundle-1.8.jar
jersey-container-servlet-core-2.16.jar
jersey-core-1.15.jar
jersey-json.jar
json_simple-1.1.jar
lucene-core-4.10.4.jar
mysql-connector-java-5.1.31.jar
slf4j-api-1.6.1.jar
xml-apis-1.3.03.jar
Not sure what am I missing? Any suggestion?
You have to return a Response instead of a ResponseBuilder:
#POST
#Path("/json/saveuser")
#Consumes("application/json")
public Response saveUserJSON(User user) {
if (save(user)) {
return Response.status(HttpStatus.SC_OK).build();
}
return Response.status(HttpStatus.SC_BAD_REQUEST).build();
}
Your stacktrace obviously points, that Jersey doesn't know, how to response with ResponseBuilder.
Return Response instead: change resource method signature and return result of build method, called upon builder.

Categories

Resources