Get ServletContext in JAX-RS resource

Furthermore, @Resource annotation might not work. Try this @javax.ws.rs.core.Context ServletContext context; The injection doesn’t happen until you hit the service method public class MyService { @Context ServletContext context; public MyService() { print(“Constructor ” + context); // null here } @GET @Path(“/thing”) { print(“in wizard service ” + context); // available here

javax.xml.bind.JAXBException: Class *** nor any of its super class is known to this context

JAX-RS implementations automatically support marshalling/unmarshalling of classes based on discoverable JAXB annotations, but because your payload is declared as Object, I think the created JAXBContext misses the Department class and when it’s time to marshall it it doesn’t know how. A quick and dirty fix would be to add a XmlSeeAlso annotation to your response … Read more

Inject an EJB into JAX-RS (RESTful service)

I am not sure this is supposed to work. So either: Option 1: Use the injection provider SPI Implement a provider that will do the lookup and inject the EJB. See: @EJB injection. Example for com.sun.jersey:jersey-server:1.17 : import com.sun.jersey.core.spi.component.ComponentContext; import com.sun.jersey.core.spi.component.ComponentScope; import com.sun.jersey.spi.inject.Injectable; import com.sun.jersey.spi.inject.InjectableProvider; import javax.ejb.EJB; import javax.naming.Context; import javax.naming.InitialContext; import javax.ws.rs.ext.Provider; import java.lang.reflect.Type; … Read more

How to choose between Jersey, Apache Wink and JBoss RESTEasy? [closed]

JAX-RS Implementations Jersey Reference Implementation Usually the most cutting edge Supports true asynchronous (ie web sockets etc…) connections through either Atmosphere or 2.0 version. Has support for Spring and standard injection containers (ie @Inject). Glassfish bundles it. Its much more modular than the other JAX-RS projects. It has a kick ass URI Builder Does not … Read more

How to have a @PATCH annotation for JAX-RS?

I got answer here. One will just have to define a custom Patch annotation, what that means is that you will have to write a PATCH.java file with following code: @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @HttpMethod(“PATCH”) public @interface PATCH { } Import the package containing PATCH.java and then you can use it like other HTTP method annotations: @PATCH … Read more

File upload along with other object in Jersey restful web service

You can’t have two Content-Types (well technically that’s what we’re doing below, but they are separated with each part of the multipart, but the main type is multipart). That’s basically what you are expecting with your method. You are expecting mutlipart and json together as the main media type. The Employee data needs to be … Read more