Java – learn rest and get stuck on the IllegalStateException
•
Java
I'm trying to learn from rest. I'm trying to make a simple test project to act as a smoke test I did four classes
@ApplicationPath("/rest") public class RestApplication extends Application { }
…
@Path("/testClassURL") @Stateless public class TestClass { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/testMethodNoParamURL") public TestBean testMethod() { TestBean ret = new TestBean(); ret.setNum(5); ret.setStr("9087".concat("1234")); return ret; } }
The other two are simple classes that contain only getters and setters You can see them there According to the path comment I set, I should be able to enter this URL
localhost:8080/TestWebRest/testClassURL/testMethodNoParamURL
Which should give me a JSON response Unfortunately, I got the following 500 errors
[2014-10-01T20:00:02.360-0400] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=24 _ThreadName=http-listener-1(4)] [timeMillis: 1412208002360] [levelValue: 900] [[ StandardWrapperValve[testyTest.RestApplication]: Allocate exception for servlet testyTest.RestApplication 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)
Does this look familiar?
Solution
The reason is that you have two or more mappings that apply to the URL call
For example:
@Path("/{myParam}")
Elsewhere:
@Path("/{differentParam}")
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码