How do you map multiple query parameters to the fields of a bean on Jersey GET request?

In Jersey 2.0, you’ll want to use BeanParam to seamlessly provide what you’re looking for in the normal Jersey style. From the above linked doc page, you can use BeanParam to do something like: @GET @Path(“find”) @Produces(MediaType.APPLICATION_XML) public FindResponse find(@BeanParam ParameterBean paramBean) { String prop1 = paramBean.prop1; String prop2 = paramBean.prop2; String prop3 = paramBean.prop3; … Read more

Ignore self-signed ssl cert using Jersey Client [duplicate]

After some searching and trawling through some old stackoverflow questions I’ve found a solution in a previously asked SO question: Question: Java client certificates over HTTPS/SSL Answer Java client certificates over HTTPS/SSL Here’s the code that I ended up using. // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new … Read more

What does Provider in JAX-RS mean?

Providers are a simply a way of extending and customizing the JAX-RS runtime. You can think of them as plugins that (potentially) alter the behavior of the runtime, in order to accomplish a set of (program defined) goals. Providers are not the same as resources classes, they exist, conceptually, at a level in-between resources classes … Read more

HK2 is not injecting the HttpServletRequest with jersey

You should @Override protected DeploymentContext configureDeployment() in the JerseyTest to return a ServletDeploymentContext. For example import javax.inject.Inject; import javax.inject.Provider; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.glassfish.jersey.test.DeploymentContext; import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.ServletDeploymentContext; import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; import org.glassfish.jersey.test.spi.TestContainerException; import org.glassfish.jersey.test.spi.TestContainerFactory; import org.junit.Test; public class ServletTest extends … Read more

Jersey: Return a list of strings

Okay, I could fix it by searching the samples This does work, but it can only be used for JSON and not for XML @GET @Produces({MediaType.APPLICATION_JSON}) @Path(“/get”) public JSONArray get() {; return new JSONArray(dao.getStringList()); } Fixes problem, but is there also a generic approach?

How to test a Jersey REST web service?

If you want to test using the URL, then you will need to start a server from your test. You can explicitly start an embedded server, which is pretty common for tests. Something like public class MyResourceTest { public static final String BASE_URI = “http://localhost:8080/api/”; private HttpServer server; @Before public void setUp() throws Exception { … Read more