0

I'm fairly new to Java and working on my first JPA project while trying to wrap my head around all of the objects that Netbeans created. I created a "User" JPA entity from a database table using the wizard. Then I went to the AbstractFacade.java where the super class exists to add a new method that will find a specific user by their email address.

public T findFromEmail(String mailbox) {
    javax.persistence.Query q = getEntityManager().createNamedQuery("Users.findByEmail").setParameter("email", mailbox);
    return (T)q.getSingleResult();
}

Next I went to UsersFacaceRest.java and added the following method. I'm not sure why I needed the @override in this example as I didn't seem to be overriding any underlying object, but Netbeans gave me an error if I didn't.

@GET
@Path("{mailbox}")
@Produces({"application/xml", "application/json"})
@Override
public Users findFromEmail(@PathParam("mailbox") String mailbox) {
    return super.findFromEmail(mailbox);
}

Now I receive the following error:

    WebModule[/LMSWebService]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:246) 
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:724)

Is there something else I need to do to add a method to the restful service or is my syntax incorrect? Any help would be greatly appreciated.

Thank you in advance.

Trebor
  • 793
  • 3
  • 11
  • 37
  • I think I've found the solution, but I'm not completely sure of the cause. – Trebor Mar 13 '14 at 21:46
  • I think I've found the solution, but I'm only partially sure of the cause. I changed my annotation to @Path("mailbox/{mailbox}") by adding the "mailbox/" in the event that there was a conflict with another endpoint and now it works. I mistakenly thought that because my parameter names were different and my variable datatype was different from my other @GET endpoints that I was okay but neither of those criteria would be known to HTTP. – Trebor Mar 13 '14 at 22:45

2 Answers2

2

Well, you seem to be declaring a RESTful web service using JAX-RS (or Jersey, the reference implementation).

As I've posted on another question this exception usually is thrown when there is an initialization error. The fact that you are using some kind of generator (NetBeans wizard) suggest there is some other code thrown arount to do the initialization.

JAX-RS is an excellent RESTful specification and Jersey is the reference implementation. It's well written and well documented. So I suggest to go and read the documentation, especially the initialization part, so you can trace your problem to its root.

Community
  • 1
  • 1
sargue
  • 5,695
  • 3
  • 28
  • 43
0

In my case, the issue is that the shaded jar did not include the javassist package that Jersey uses to do bytecode manipulation. Make sure to include org.javassist:*. for all scopes.

<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.26.0-GA</version>
</dependency>
Yao Li
  • 2,071
  • 1
  • 25
  • 24