Runtime exception with jersey - java.lang.AbstractMethodError - web-services

I am trying to execute a RESTful web service deployed on tomcat using Jersey implementation.
Following is the resource class
#Path("/rest")
public class PatientResource {
PatientService patientService;
#GET
#Path("/patient/{patientId}")
#Produces(MediaType.APPLICATION_JSON)
public Patient getPatientDetails(#PathParam("patientId") String patientId) {
//return patientService.getPatientDetails(patientId);
return new PatientService().getPatientDetails(patientId);
}
#GET
#Path("/patients")
#Produces(MediaType.APPLICATION_JSON)
public PatientData<Patient> getAllPatients() {
//return patientService.getAllPatients();
return new PatientService().getAllPatients();
}
}
I have made necessary entries in web.xml and all necessary jars are available in classpath, however when application is started on tomcat and I enter the URL in browser, I get following exception
[Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findSerializer(AnnotationIntrospector.java:1148)
at org.codehaus.jackson.map.ser.BasicSerializerFactory.findSerializerFromAnnotation(BasicSerializerFactory.java:367)
at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:252)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782)
Any idea how to resolve it ?

Probably an inconsistency in the versions of Jersey and Jackson you are using at runtime .
What are your libs versions ?

Related

embedded jetty ignoring classes packaged in my war

I'm trying to run jetty in embedded mode. It appears to be ignoring all the classes bundled in my war file, whether under WFB-INF/classes or WEB-INF/lib.
My startup code:
package rfd;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration;
public class RfdWar
{
public static void main(String[] args) throws Exception
{
System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG");
Server server = new Server(8080);
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
Resource jettyEnv = Resource.newSystemResource("jetty-env.xml");
XmlConfiguration conf = new XmlConfiguration(jettyEnv.getInputStream());
Object obj = conf.configure();
WebAppContext context = (WebAppContext)obj;
context.setWar("/tmp/thewar.war");
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
}
}
My command line:
export JETTYHOME=<my_jetty_home>
JHL=$JETTYHOME/lib
export CLASSPATH=.:$JHL/jetty-server-9.2.10.v20150310.jar:$JHL/jetty-util-9.2.10.v20150310.jar:$JHL/jetty-http-9.2.10.v20150310.jar:$JHL/servlet-api-3.1.jar:$JHL/jetty-io-9.2.10.v20150310.jar:$JHL/jetty-webapp-9.2.10.v20150310.jar:$JHL/jetty-servlet-9.2.10.v20150310.jar:$JHL/jetty-security-9.2.10.v20150310.jar:$JHL/jetty-xml-9.2.10.v20150310.jar:$JHL/jetty-plus-9.2.10.v20150310.jar:$JHL/jetty-jndi-9.2.10.v20150310.jar:$JHL/jsp/javax.servlet.jsp-2.3.2.jar:$JHL/jsp/javax.servlet.jsp-api-2.3.1.jar
java rfd.RfdWar
The server does launch correctly and definitely reads web.xml packaged in the war. But when I try accessing the URL I'm getting an error that my class, that's packaged with the war, is missing.
Is there anything else I need to do to tell jetty to honor the classes packaged in the war?
This command ...
context.setParentLoaderPriority(true);
Basically says that when the webapp is attempting to load a class, the server classpath is checked first, then the webapp's classpath.
So if you happen to have the same classes in both places, the server version will be used, ignoring the one on the webapp.
Set this to false to get honest servlet spec behavior, with all of the WebApp classloader isolation.
Also, this is wrong, in many different ways.
Resource jettyEnv = Resource.newSystemResource("jetty-env.xml");
XmlConfiguration conf = new XmlConfiguration(jettyEnv.getInputStream());
Object obj = conf.configure();
WebAppContext context = (WebAppContext)obj;
The proper way to get jetty-env.xml to be loaded is to use the establish the WebApp and ClassList Configuration that performs this function from within the appropriate classloader and thread scope.
See documentation at https://www.eclipse.org/jetty/documentation/current/jndi-embedded.html
And prior answer at Can't get jetty to read jetty-env.xml

EJB Web Service ClassNotFoundException

Server: JBoss 7.1.1
EJB 3.0
Eclipse Juno
I am working through my first webservice project using ejb 3.0 and am running into a problem on my client. For my client, I made up a servlet. The problem is when I attempt:
CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");
I am getting ClassNotFoundException on the lookup. I got this jndi from my JBoss server.log
[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named CalculatorImp in deployment unit deployment "EJBCalculatorWS.war" are as follows:
java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:app/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:module/CalculatorImp!math.CalculatorOps
I have 2 web projects, WS and Client, both added to the server and WS is in the build path of Client.
-------------CODE------------
Interface
package math;
#Local
public interface CalculatorOps {
public int add(int a, int b);
public int subtract(int a, int b);
}
Class
package math;
#Stateless(mappedName="TheCalc")
#WebService
public class CalculatorImp implements CalculatorOps{
#Override
public int add(int a, int b) {
return a+b;
}
#Override
public int subtract(int a, int b) {
return a-b;
}
}
Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");
}
Fixed: I ended up fixing this problem by placing the client and the ejb packages together in one project, then using the new jndi. I would still like to know tho why across multiple projects, I cant add to build path and then use the jndi to reference the ejbs without a ClassNotFoundException thrown.
If you are using eclipse, you need to add the EJB project to the deployment assembly of your web project to get it working, Build path will only exist for compilation but you get the error during run time if I am right.
RightClick on your web project->Properties->Deployment Assembly->Add

JAVA JAX-WS NullPointerException at javax.xml.ws.Service.getPort(Service.java:188)

I have simple "HelloWorld" web service deployed on jboss under ubuntu.
I have created simple client, but I can't get it to work. I'm getting NullPointerException each time I run the client.
Note that I'm running on Oracle Java 7 under Ubuntu.
Here is the code:
HelloWorldClient.java
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class HelloWorldClient {
public static void main(String[] args){
URL url;
try {
url = new URL("http://localhost:8080/WebServiceProject/helloWorld?wsdl");
QName qname = new QName("http:///", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.sayHello("mkyong"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
HelloWorld.java
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public interface HelloWorld {
#WebMethod
public String sayHello(String name);
}
Stacktrace:
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1407)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:334)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:354)
at javax.xml.ws.Service.getPort(Service.java:188)
at HelloWorldClient.main(HelloWorldClient.java:18)
The exception is thrown at this line:
HelloWorld hello = service.getPort(HelloWorld.class);
I have had the same problem myself for a few days now, because the WSDL-file (and service) I was using was moved to a new URL. I finally found the solution here:
http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/
In short, everything (should have) started working after I re-generated all the auto-generated java and class files with the following command (on Windows/CygWin)
"C:/Program Files/Java/jdk1.8.0_31/bin/wsimport.exe" -keep https://domain.com/path_to_wsdl
I had some extra trouble because some old files were left around and clashing with the newly generated ones, but everything slowly started working after I moved all the old files to the recycle bin.
It can also happen if your web-service's implementation is different than the interface from your project.
If in your project you have HelloWorld.class declaring some methods that are not present on the web-service side, the getPort(HelloWorld.class) call will raise a null pointer exception.
You can double check the HelloWorld.class interface on your application and the one on the web-service itself to make sure they match.

Spring Jax-ws service with JBOSS 5.1.0 giving Introspection Exception

Hi I am developing a Spring -Jaxws web service using JBOSS 5. I am using "SimpleJaxWsServiceExporter" to deploy the service. My service endpoint is :
package com.pb.pts.spring.service;
#Component
#WebService(serviceName="ParcelTrackingService")
public class ParcelTrackingServiceEndpoint {
#Autowired
public ParcelTrackingService trackingService;
#WebMethod
public String createParcelDetails(ParcelDetails details) throws TrackingException{
return trackingService.createParcelDetails(details);
}
#WebMethod
public ParcelTrackingData getParcelTrackingDetails(ParcelTrackingRequestData requestData) throws TrackingException{
return trackingService.getParcelTrackingDetails(requestDa ta);
}
}
The TrackingException class is :
public class TrackingException extends Exception {
private TrackingError[] errors;
public TrackingException() {
super();
this.errors = null;
}
public TrackingError[] getErrors() {
return errors;
}
public void setErrors(TrackingError[] errors) {
this.errors = errors;
}
}
I get the following error while deploying on jboss :
org.jboss.ws.WSException: Property 'errors' not found in fault bean 'com.pb.pts.spring.service.jaxws.TrackingException Bean'
at org.jboss.ws.metadata.umdm.FaultMetaData.initializ eFaultBean(FaultMetaData.java:282)
at org.jboss.ws.metadata.umdm.FaultMetaData.eagerInit ialize(FaultMetaData.java:225)
at org.jboss.ws.metadata.umdm.OperationMetaData.eager Initialize(OperationMetaData.java:468)
at org.jboss.ws.metadata.umdm.EndpointMetaData.eagerI nitializeOperations(EndpointMetaData.java:559)
at org.jboss.ws.metadata.umdm.EndpointMetaData.initia lizeInternal(EndpointMetaData.java:543)
at org.jboss.ws.metadata.umdm.EndpointMetaData.eagerI nitialize(EndpointMetaData.java:533)
at org.jboss.ws.metadata.umdm.ServiceMetaData.eagerIn itialize(ServiceMetaData.java:433)
at org.jboss.ws.metadata.umdm.UnifiedMetaData.eagerIn itialize(UnifiedMetaData.java:194)
at org.jboss.wsf.stack.jbws.EagerInitializeDeployment Aspect.start(EagerInitializeDeploymentAspect.java: 48)
at org.jboss.wsf.framework.deployment.DeploymentAspec tManagerImpl.deploy(DeploymentAspectManagerImpl.ja va:129)
at org.jboss.wsf.container.jboss50.deployer.ArchiveDe ployerHook.deploy(ArchiveDeployerHook.java:76)
at org.jboss.wsf.container.jboss50.deployer.AbstractW ebServiceDeployer.internalDeploy(AbstractWebServic eDeployer.java:60)
at org.jboss.deployers.spi.deployer.helpers.AbstractR ealDeployer.deploy(AbstractRealDeployer.java:55)
at org.jboss.deployers.plugins.deployers.DeployerWrap per.deploy(DeployerWrapper.java:179)
... 29 more
Caused by: java.beans.IntrospectionException: Method not found: isErrors
at java.beans.PropertyDescriptor.<init>(PropertyDescr iptor.java:89)
at java.beans.PropertyDescriptor.<init>(PropertyDescr iptor.java:53)
at org.jboss.ws.metadata.umdm.FaultMetaData.initializ eFaultBean(FaultMetaData.java:271)
It say " Method not found: isErrors" inspite of the fact that errors is not a boolean.
Can you please provide some insight into this problem? Any help would be appreciated.
I found a solution to the problem.. This is the java doc for SimpleJaxwsServiceExporter.
"Note that this exporter will only work if the JAX-WS runtime actually
supports publishing with an address argument, i.e. if the JAX-WS runtime
ships an internal HTTP server. This is the case with the JAX-WS runtime
that's inclued in Sun's JDK 1.6 but not with the standalone JAX-WS 2.1 RI."
So a SimpleJaxwsServiceExporter web service implementation using spring will work on Tomcat but not on JBoss as JBoss has it own implementation of JAX-WS.
So I deployed a pure Jax-ws web service without spring support and that worked.

Missing dependency for method public entities in Netbeans restful web services

I am deploying a restful web services using Netbeans EE6 and jersey libraries with the tutorial http://netbeans.org/kb/docs/websvc/rest.html.
When I create a restful web services from entities that hold composite primary keys in the database, the project gives me an error when I try to test the web services:
SEVERE: Missing dependency for method public entities.RMSchedule service.RMScheduleFacadeREST.find(entities.RMSchedulePK) at parameter at index 0
SEVERE: Method, public entities.RMSchedule service.RMScheduleFacadeREST.find(entities.RMSchedulePK), annotated with GET of resource, class service.RMScheduleFacadeREST, is not recognized as valid resource method.
Is the error due to composite primary keys or is there a step that I should include?
Many thanks in advance.
I think this issue is related to Netbeans bug:
https://netbeans.org/bugzilla/show_bug.cgi?id=208375
When creating entity class which has composite primary keys,
two entity files are created. (ex CustomerEntity.jave, CustomerEntityPK.java)
Then if you choose to create the servlet from the entity class, the servlet comes with automatically generated code such as below:
#DELETE
#Path("{id}")
public void remove(#PathParam("id") CustomerEntityPK id) { //error
super.remove(super.find(id));
}
#GET
#Path("{id}")
#Produces({"application/xml", "application/json"})
public CustomerEntity find(#PathParam("id") CustomerEntityPK id) { //error
return super.find(id);
}
The issue is that argument being passed to the servlet methods is CustomerEntityPK which has composite primary key.
If you change the argument type to something like String then the error went away in my case.
#DELETE
#Path("{id}")
public void remove(#PathParam("id") String id) { //type set to String now
super.remove(super.find(id));
}
But in my project I did not need such auto generated code so I simply choose to create servlet class by hand and has no problem.
Hope that helps.