jersey

Custom Jersey Error Handling, how to catch response at client side?

冷暖自知 提交于 2019-12-05 19:17:54
I'm trying out some custom error handling on my webservice. In my webservice, I created a custom Exception class extending WebApplicationException as described in JAX-RS / Jersey how to customize error handling? : public class InternalServerErrorException extends WebApplicationException { public InternalServerErrorException(String message) { super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) .header("errorMessage", message).type(MediaType.TEXT_PLAIN).build()); System.out.println(message); } } For testing, I have a simple Country service that gives a list of countries. I made sure

How to implement jaxrs Application without web.xml [duplicate]

做~自己de王妃 提交于 2019-12-05 18:09:19
This question already has answers here : How to set up JAX-RS Application using annotations only (no web.xml)? (6 answers) Closed 6 years ago . I am trying to deploy a really simple jaxrs application with without a web.xml config and cannot get it working. My URL I'd expect to access is serverandport/{appname}/rest/welcomes/hello and I think I must be missing something dead obvious. Application @ApplicationPath("/rest") public class EngineApp extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> s = new HashSet<Class<?>>(); s.add(RestTestImpl.class); return s; } }

Spring 3, Jersey (JSR-311) and Maven dependencies

做~自己de王妃 提交于 2019-12-05 17:58:31
问题 im currently struggling to integrate a REST Service based on Jersey and Spring. I'm using Spring 3.0.2-RELEASE and jersey-spring 1.2. But jersey-spring adds a dependency to Spring 2.5.6 to my project which of cause conflicts with the 3.0.2-RELEASE to give me thefollwing error: 11:58:25,409 ERROR org.springframework.web.context.ContextLoader:215 - Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class

Loading properties file in a Java Jersey RESTful web app, to persist throughout the app?

自古美人都是妖i 提交于 2019-12-05 17:50:16
I'm currently building a RESTful API using Jersey. So far, all has been going well, however, all of the configuration entries have been hard coded in. (i.e. Database Host , Database Username , etc...). I'd like to be able to setup a config.properties file that exists in my WEB-INF folder to contain all of these configuration specs. I'm concerned that if I do it the "classic" way of reading the file on the Classpath, I'm performing file I/O for every request. I want to be able to read once on startup (which I know involves a ServletListener in my web.xml file. Here's what I have below: web.xml

reading JSON response as string using jersey client

烈酒焚心 提交于 2019-12-05 17:42:54
问题 I am using jersey client to post a file to a REST URI that returns response as json. My requirement is to read the response as is(json) to a string. Here is the piece of code that posts the data to web service. final ClientResponse clientResp = resource.type( MediaType.MULTIPART_FORM_DATA_TYPE). accept(MediaType.APPLICATION_JSON). post(ClientResponse.class, inputData); System.out.println("Response from news Rest Resource : " + clientResp.getEntity(String.class)); // This doesnt work.Displays

Jersey rest api security

。_饼干妹妹 提交于 2019-12-05 17:30:18
I see the following link that explains how rest api needs to be secured. (Using public key and a HMAC(hash) of request parameters and private key). http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ I also see this link in stackoverflow which talks about rest api security using spring combining spring security 3 with jersey rest api I see this link in oracle weblogic website that talks about restful api security using web.xml or security context etc http://docs.oracle.com/cd/E24329_01/web.1211/e24983/secure.htm Are these approaches distinct or related? I also

Appengine java - Jersey/Jackson JaxbAnnotationIntrospector NoClassDefFoundError

吃可爱长大的小学妹 提交于 2019-12-05 17:29:59
问题 I'm re-asking an unanswered question from the now read-only google groups App Engine for Java because I have the exact same problem. (original) I have put together a simple json REST service using jersey, jaxb and jackson. It works almost fine, however the first request to the server always ends up with the exception: java.lang.NoClassDefFoundError: org/codehaus/jackson/xc/JaxbAnnotationIntrospector For some reason gae/jersey cannot find this class on the initial request. However, all

Why is injecting a SecurityContext into a Jersey Singleton thread safe?

99封情书 提交于 2019-12-05 17:22:19
In the Jersey documentation, Example 16.2 shows an example of injecting a SecurityContext into a Jersey resource singleton. Surely the docs are correct, and the example given is indeed thread safe. I suspect that the injection of the SecurityContext happens exactly once, and when getUserPrincipal() is called, perhaps it picks up user data from some structure that is attached to the thread itself (maybe a ThreadLocal object?). That's the only way I can see that the correct user info be served to the end user when there are a ton of threads competing. Can anyone confirm this behavior, or

Jax-rs(Jersey) to Consumes Array of Json object in POST request

一个人想着一个人 提交于 2019-12-05 17:14:26
问题 Using the jax-rs(Jersey) I am try to implement a POST request that take a list of JSON object //The resource look like this @Path("/path") @POST @Consumes(MediaType.APPLICATION_JSON) public void setJsonl(List<SomeObj> test) { //do work System.out.println(test); } //The class to define the json structure @XmlRootElement public class SomeObj{ private String tag; private String value; public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } public String getValue

Access Jersey based RESTful service using jQuery

£可爱£侵袭症+ 提交于 2019-12-05 17:12:44
I am trying to access RESTful service, created on Java and deployed with help of Jersey using jQuery. If I access it using browser I will get the result, but from jQuery, I am getting an error and can not see any results on the page. Page with the script is hosting on local Apache server and the Service is running separately using Jersey/Grizzly on the same machine. I can see that service is sending the response and it has 200 code, but I keep getting error from .ajax, without any details and Any suggestions what is wrong? Service: @Path("/helloworld") public class HelloWorldResource { @GET