jersey

ExceptionMapper not work in grizzly

杀马特。学长 韩版系。学妹 提交于 2019-12-06 07:47:08
Sorry for my poor English. I'm using grizzly and jersey to build a web application. And I implement like this ErrorModel errorModel = new ErrorModel("1", "1", "1"); WebApplicationException applicationException = (WebApplicationException) exception; return Response.status(applicationException.getResponse().getStatus()).type(MediaType.APPLICATION_JSON_TYPE).entity(errorModel).build(); When I visited a page which does not exist. I found that it throw a WebApplicationException. So I debug and found this method is being called and return the response above. But finally the http response is a html

Access HttpServletRequest using @Context annotaion in business layer

雨燕双飞 提交于 2019-12-06 07:45:00
I am able to access HttpServletRequest by using @Context annotation in my rest service. But unable to access the same in repository class.I do not want to pass the request form MyService to MyRespository while calling methods. @Path("/someUrl") public MyService{ @Context private HttpServletRequest request; @Get public void someMethod() { myRepository.someMethod(); } } But same annotation not working for my Repository class @Repository public MyRepository { @Context private HttpServletRequest request; public void someMethod() { //need request here } } it injection null request. Not sure why

Jersey (REST) RESPONSE with multipart/mixed with multiple bodyparts

。_饼干妹妹 提交于 2019-12-06 07:40:19
I have a jersey based web service which produces a "multipart/mixed" RESPONSE as follows: The method reads a file, and should return it in octet format. Also, it read the metadata of that file and returns them in json form. Method: @GET @Produces("multipart/mixed") public Multipart getDocumentContents(@Context HttpHeaders header){ .... .... .... os = new ByteArrayOutputStream(); .... .... MultiPart multiPartEntity = new MultiPart() .bodyPart(new BodyPart(os.toByteArray(), MediaType.APPLICATION_OCTET_STREAM_TYPE)); return multiPartEntity; } My problem is that I get the following error which

How do I (un)marshall a Date as a time-stamp with jackson

元气小坏坏 提交于 2019-12-06 07:37:58
问题 I'm having trouble (un)marshalling java.util.Date objects into timestamps. Ideally the timestamps should be in a UTC-0 format and not the server's local time zone. Although I can work around that pretty easily if I need to. NB: I am aware that here are several similar topics on stack overflow but everyone I have come across is either outdated (with respect to the API's being used) or are related to serializing Date objects to strings. Here is an excerpt of my POM file: <dependency> <groupId

Jersey response for empty list is null instead of {}

ぃ、小莉子 提交于 2019-12-06 07:20:13
问题 I have a JAX-RS REST service using Jersey. I use JAXB for JSON marshalling (ie. @XmlRootElement) One of the method returns a list of objects persisted with JPA. When this list contains entries it works as I expect. Example: {"androidDevice":[{"email":"dagfinn.parnas@d2.no","timeCreated":"2012-10-19T 22:41:26.862+02:00"},{"email":"dagfinn.parnas@d1.com","timeCreated":"2012-10- 19T22:41:38.093+02:00"}]} However, if the list is empty (or null) I would expect it to return {}. Instead it returns

How can I put a cookie in Jersey RESTful webservice?

懵懂的女人 提交于 2019-12-06 07:11:05
I would like to put a cookie from "PUT webservice result" to "POST webservice" by Jersey API. Here is my code WebResource service1 = client.resource("http://test.com"); ClientResponse logResponse = service1.accept(MediaType.APPLICATION_XML).put(ClientResponse.class, "<?xml version='1.0'?><test>1</test>"); WebResource service2 = client.resource("http://test.com/post"); WebResource.Builder builder = service2.getRequestBuilder(); for(Cookie c : logResponse.getCookies()) { if(c.getName().equals("SESSID")) builder = builder.cookie(c); } ClientResponse test = builder.accept(MediaType.TEXT_XML).post

Jersey: com.sun.jersey.server.impl.template.ViewableMessageBodyWriter

只谈情不闲聊 提交于 2019-12-06 07:10:14
I'm totally alien to Jersey. I'm trying to run a jar which throws javax.ws.rs.WebApplicationException when I hit the endpoint. The error thrown by the program is as follows: 09-Apr-2011 08:32:20 com.sun.jersey.spi.container.ContainerResponse write SEVERE: A message body writer for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found 09-Apr-2011 08:32:20 com.sun.jersey.spi.container.ContainerResponse write SEVERE: The registered message body writers compatible with the MIME media type are: / -> com.sun.jersey.server.impl.template

ApacheConnector does not process request headers that were set in a WriterInterceptor

久未见 提交于 2019-12-06 06:34:38
问题 I am experiencing problems when configurating my Jersey Client with the ApacheConnector . It seems to ignore all request headers that I define in a WriterInterceptor . I can tell that the WriterInterceptor is called when I set a break point within WriterInterceptor#aroundWriteTo(WriterInterceptorContext) . Contrary to that, I can observe that the modification of an InputStream is preserved. Here is a runnable example demonstrating my problem: public class ApacheConnectorProblemDemonstration

Restful webservices - NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig

蓝咒 提交于 2019-12-06 06:20:10
问题 So I created the webservice in this thread and finally I managed to solve the problem. Now I'm trying to consume this webservice. I've created a new web project on Netbeans and I'm using Apache Tomcat. Here's the code to consume the webservice. I've gone through some tutorials to produce this code. package com.client; import java.net.URI; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import

Java/Jersey - creating own injection resolver with ParamInjectionResolver - strange behavior

南笙酒味 提交于 2019-12-06 06:12:37
I am trying to create an injection resolver. I have a data class: public class MyData { ... } I have the following annotation: @Target({ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MyDataInject { } My injection resolver looks like this: public class MyDataInjectionResolver extends ParamInjectionResolver<MyDataInject> { public MyDataInjectionResolver () { super(MyDataValueFactoryProvider.class); } @Singleton public static class MyDataValueFactoryProvider extends AbstractValueFactoryProvider { @Inject public