1
votes

The below code works

@POST
@Path("/{apiId}")
@Consumes(MediaType.APPLICATION_JSON)
public Response postMetricsData(String metricsData) {
    System.out.println(metricsData);
    return Response.ok().build();
}

The below code is throwing error

@POST
@Path("/{apiId}")
@Consumes(MediaType.APPLICATION_JSON)
public Response postMetricsData(String metricsData, @PathParam("apiId") String apiId) {
    System.out.println(metricsData);
    return Response.ok().build();
}

Getting below exception

rg.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.

[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response com.trimble.paas.apicloud.metricscollector.resource.MetricsResource.postMetricsData(java.lang.String,java.lang.String) at index 1.; source='ResourceMethod{httpMethod=POST, consumedTypes=[application/json], producedTypes=[], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.trimble.paas.apicloud.metricscollector.resource.MetricsResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@59916e0f]}, definitionMethod=public javax.ws.rs.core.Response com.trimble.paas.apicloud.metricscollector.resource.MetricsResource.postMetricsData(java.lang.String,java.lang.String), parameters=[Parameter [type=class java.lang.String, source=null, defaultValue=null], Parameter [type=class java.lang.String, source=apiId, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}'] at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:394) at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:316) at org.glassfish.jersey.internal.Errors.process(Errors.java:316) at org.glassfish.jersey.internal.Errors.process(Errors.java:298) at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:256) at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:315) at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:282) at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:335) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:789) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

Any idea on what I am missing?

1
What's the @PathParam import package? It should be javax.ws.rs. If you're using javax.websocket.server (which I've seen some people mistakenly do), you will get this error.Paul Samsotha

1 Answers

0
votes

Would you check the import of the @PathParam. Try to use the import javax.ws.rd;