0

I have a problem I really cannot get rid of. I am using Glassfish 4.0 embedded in Eclipse together with JAXB 2.2 and Jersey 2.0. I want to create a REST interface, where the function called by Jersey is expecting two paramters. For example two path parameters or or a mixture of JAXB and one PathParameter. Either way I always get a ModelValidationException with Jersey. Injecting only one parameter into the function works great, but I need at least two and sometimes even more.

I found this thread about this topic Jersey 2 injection source for multipart formdata but I think this is not the solution for me, since I am working with a GET, POST or even PUT and dont want to use form data. In the end I always get the same error no matter if I use PUT, POST or GET. I can of course workaround this problem with using the

@Context UriInfo info;

information and extract the path parameters by using for example

long portID = new Long(uriInfo.getPathParameters().get("portid").get(0));

It seems I have to activate a certain function via Glassfish to activate this function.

Here is an example of my code, which does not workL

@PUT
@Path("/networkelements/{neid: [0-9]+}/ports/clients/{portid: [0-9]+}")
@Consumes(MediaType.APPLICATION_XML)
public Response fullyUpdateClientPort(@PathParam("neid") long neID, @PathParam("portid") long portID, Ports ports){
    // TODO: Implement REST functionality
    return Response.status(Response.Status.OK).entity("Port(s) fully updated").build();
}

An example, which works great:

@GET
@Path("/networkelements/{neid: [0-9]+}/ports/clients/")
@Produces(MediaType.APPLICATION_XML)
public Ports getClientPorts(@PathParam("neid") Long neID){
    // TODO: Implement REST functionality
    Ports ports = new Ports();
    for (AbstractPort port : this.data.getPortList()) {
        DebugLogger.get().log(Level.INFO, port.getPortName());
    }
    ports.setPorts(this.data.getPortList());
    return ports;
}

EDIT: These are the exceptions I get

2014-04-28T17:16:21.811+0200|SEVERE: WebModule[/SDNController]StandardWrapper.Throwable
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:257)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:205)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:435)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:261)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1225)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)

2014-04-28T17:16:21.811+0200|WARNING: StandardWrapperValve[de.dhbw_stuttgart.sdncontroller.core.services.restresources.ApplicationConfig]: Allocate exception for servlet de.dhbw_stuttgart.sdncontroller.core.services.restresources.ApplicationConfig
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:257)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:205)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:435)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:261)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1225)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)

EDIT No. 2:

I have found out now that unfortunately my parameters in the URL are not decoded automitcally. I have searched a lot via Google but I have not found out, if I have to separately activate something that Jersey or Glassfish to this automatically. Getting those parameters via UriInfo works fine and is the only workaround up to now.

Community
  • 1
  • 1
rieni
  • 1
  • 2
  • What's the failure? Does it throw an exception, return a 404, ? – Eric Stein Apr 28 '14 at 14:54
  • Ah sorry... forgot that to post. – rieni Apr 28 '14 at 15:14
  • I added the exceptions now – rieni Apr 28 '14 at 15:22
  • Have you looked at http://stackoverflow.com/questions/22388889/the-resource-configuration-is-not-modifiable-in-this-context-entities-resfutl-se? – Eric Stein Apr 28 '14 at 16:47
  • Hi @EricStein, yes I looked at that, but I think it seems to be not the same problem... Interestingly, I see the same problem, if I do for example a second GET request after I received the former Exceptions. – rieni Apr 29 '14 at 07:20
  • BTW... I get an HTTP 500 error. – rieni Apr 29 '14 at 07:23
  • Is it a problem, if I have added the @Path annotation at class and function level in the same class? I want to have at class level a certain path extension and on each function a path extension to the path extension of the class – rieni Apr 29 '14 at 09:06
  • I have found out so far, that somehow the parameters will not be decoded automatically. Do I need to activate this in the Glassfish Server or in Jersey? – rieni May 01 '14 at 19:07

1 Answers1

0

This exception is usually thrown when there is some problem initializing the API. Not necessarily with the request which causes the exception to pop out.

Try to look at the container general log. Comment as much as the initialization parts until it works. Try to think if there is some code that is executed during initialization.

Community
  • 1
  • 1
sargue
  • 5,695
  • 3
  • 28
  • 43
  • Long time ago, but I try to remember. The problem was that the path somehow was not accepting having more than one parameter on the function. The path is completely ok and I could request the parameter by explicitly requesting it. This is how I worked around it. – rieni Mar 13 '15 at 20:35
  • Unfortunately, my study about this is finished and I will not work on this anymore, but anyhow... It's good to know somebody is looking at it. ;-) – rieni Mar 13 '15 at 20:38