jersey

Jersey: The request resource is not available

这一生的挚爱 提交于 2019-12-12 06:14:45
问题 I am trying to get my first Jersey web service project to work but I am getting this error Jersey: The requested resource is not available. I have installed Jersey 2.16 by eclispe Maven and installed Tomcat 8.0.21 I have craeted the MessageResource.java class inside scr/main/java - org.test.messanger I am typing this link: http://localhost:8080/messanger/webapi/messages If I klick this link http://localhost:8080/messanger/webapi/myresource I am getting Got it! I added Jersy with maven with

REST call returning blank XML

别来无恙 提交于 2019-12-12 05:58:02
问题 I am pretty new to REST programming. Below is my class which is intended to return XML/JSON but I am having some difficulties to make it return proper values. I tried returning Response, JsonArray and Object of my POJO class but its not working. I looked several threads but not able to figure out what exactly is the problem. The resource class: public class UserService { UserDBHandler userDBHandler; Friend f; @GET @Path("users/{userId}/friends") // @Produces(MediaType.TEXT_PLAIN) @Produces({

Jersey filters in non-servlet container

本小妞迷上赌 提交于 2019-12-12 05:53:23
问题 I am running Jersey in a non-servlet container (Netty). For servlet-based containers, I can plug in a request filter using : <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> </init-param> But how do I do this programmatically in my case ? 回答1: Here is a completely non-servlet example: Assuming you have created your request and/or response filter(s), you can add

Singleton variables in Jersey web service

十年热恋 提交于 2019-12-12 05:49:56
问题 I have a RESTful web service based on JAX-RS and Jersey . I have a bunch of GET and POST Methods and inside of it i need "global" variables. I have an initialization method with ServletContextListener and it's contextInitialized-Method for write some log files and do other stuff. In this method I want to declare variables wich I can access from anywhere in my application. here are my code: @WebListener public class MyServletContextListener implements ServletContextListener { //these are the

Jersey PathParam with HTTP 405 error

ⅰ亾dé卋堺 提交于 2019-12-12 05:29:15
问题 I'm using jersey for my rest server, and I got a HTTP 405 error, when I try to forward POST request to relative GET resource. @Path("/") public class MyResource { @POST @Path("/{method}") @Produces(MediaType.APPLICATION_JSON) public String postRequest(@PathParam("method") String method, @Context UriInfo uriInfo, String body) throws IOException { JsonParser parser = new JsonParser(); JsonObject root = parser.parse(body).getAsJsonObject(); JsonObject params = root; if (root.has("method")) {

Dropwizard customAuthorizationFilter with DynamicFeature

牧云@^-^@ 提交于 2019-12-12 05:04:48
问题 I have followed all the steps given in Answer by pandadb in below link How to Optionally Protect a Resource with Custom Dropwizard Filter I added my custom annotaion to the resource method but the custom authorisation filter is not being called. can anyone tell me what i might have missed. Update:- I am using dropwizard 1.0 using java8 and building the app using maven. 回答1: First of all check this Dropwizard Feature example and Dropwizard Authorization. Then please provide more details, what

How to get both JSON and XML response in Jersey having root element in both the cases?

安稳与你 提交于 2019-12-12 04:56:18
问题 I want response by using single function like: @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response getVolume(){ ...enter code here return Response.ok().entity(VolDetail).build(); } Output shoulb be like: xml: <volume> <status>available</status> </volume> JSON: {"volume":{"status":"available"}} where volume is a POJO class. The problem is that I am not getting root element in JSON. I tried JSON object binding but its not working properly. 回答1: Assuming you

Genson with Jersey JsonBindingException: Could not deserialize to type class java.lang.String

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:55:00
问题 In my Spring MVC Java application I'm using Jersey REST API. I am using Jackson for JSON processing. I added Genson to my project for filtering some fields for some classes. And I am trying to use Genson only for that and remaining I want to use Jackson. But I am getting exception while using Jersey REST api as Jersey enabled Genson by default when the Jar is in the classpath (Got to know from this link). Here is my code in connect to web service and get data and convert to String using

autowire doesn't work on jpa tomcat and jersey xml based

有些话、适合烂在心里 提交于 2019-12-12 04:48:51
问题 I got stuck right now. Firstly i made Java application that i run from console and is annotation based configuration. CONFIGURATION BELOW WORKS WHEN RUNNING FROM CONSOLE configuration is in config package @Configuration public class JpaConfiguration { @Value("#{dataSource}") private javax.sql.DataSource dataSource; @Bean public Map<String, Object> jpaProperties() { Map<String, Object> props = new HashMap<String, Object>(); props.put("hibernate.dialect", MySQL5Dialect.class.getName()); props

Jersey-Test-Framework - TestContainerException: The default test container factory, null, could not be instantiated

拥有回忆 提交于 2019-12-12 04:46:04
问题 I am writing test for RESTful web service using Jersey-Test-Framework. My REST service code is as follow - package net.vsspl.mycontent.services; import static org.junit.Assert.assertEquals; import java.net.URISyntaxException; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.junit.Test; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.test.framework.AppDescriptor; import com.sun.jersey.test.framework.JerseyTest; import