jersey-2.0

Spring Boot + Jersey type filter - Bad request 400 for service Consumes MULTIPART_FORM_DATA

懵懂的女人 提交于 2019-11-27 09:46:17
I'm using Spring boot v1.5.10 + Jersey v2.25.1, configured jersey as filter to access static folder files. I'm getting HTTP response 400 Bad Request for a service consuming MULTIPART_FORM_DATA . Props to configure Jersey as filter. spring.jersey.type=filter If I remove above property i.e., using Jersey as Servlet, the service is working, but I'm not able to access static folder. Here is the controller, @POST @Path("/save") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public ResponseBean save( @FormDataParam("fileToUpload") InputStream file, @FormDataParam(

How to handle Spring Boot's redirection to /error?

十年热恋 提交于 2019-11-27 09:42:30
I've encountered the same issue as in this question , using Spring Boot 1.3.0 and not having my controllers annotated with @RestController , just @Path and @Service . As the OP in that question says, this is, to me, anything but sensible I also can't understand why would they have it redirect to /error. And it is very likely that I'm missing something , because I can only give back 404s or 200s to the client. My problem is that his solution doesn't seem to work with 1.3.0, so I have the following request flow: let's say my code throws a NullPointerException . It'll be handled by one of my

Catch all Exceptions and also return custom Errors in Jersey

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 08:19:39
I want to catch all unexpected Exceptions in a jersey rest service. Therefore i wrote an ExceptionMapper: @Provider public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Exception> { private static Logger logger = LogManager.getLogManager().getLogger(ExceptionMapper.class.getName()); @Override public Response toResponse(Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Internal error").type("text/plain").build(); } } The mapper catches really all exceptions. Therefore i can't write: public

Jersey HK2 Dependency Injection

冷暖自知 提交于 2019-11-27 08:18:49
问题 I'm writing a simple microservices that exposes REST API. So I started working with Jersey and of course I need to Inject my object into jersey resources. Basically I have 2 classes that defines a set of resources and some of them need to use another service. So basically I have: public interface MyService { String getServiceName(); void doService(); } 2 implementations of this interface (MyServiceBean and MyAlternativeServiceBean) and, as far as I understood reading jersey docs, I defined an

Jersey ContainerRequestFilter not triggered

本小妞迷上赌 提交于 2019-11-27 07:46:06
I'm trying to use a ContainerRequestFilter to enforce some authentication on a Tomcat based Jersey application. I followed this document . Problem : the filter is never triggered The filter class : @Provider public class AuthFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { // MY AUTHENTICATION CODE GOES HERE } The web.xml file : <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns

Read another parameter within jersey's ParamConverter

霸气de小男生 提交于 2019-11-27 06:58:43
问题 I've made a ParamConverter which provides an Instant (Date) when given a string formatted as either Instant's native ISO-8601, or as an integer number of milliseconds since the epoch. This is working fine, but I also need to be able to support other date formats (the customers are fussy). To avoid the classic dd/mm/yyyy vs mm/dd/yyyy ambiguity, I'd like to have the customer specify their preferred format as part of the request*. e.g: GET http://api.example.com/filter?since=01/02/2000

Optional params in REST API request using Jersey 2.21

两盒软妹~` 提交于 2019-11-27 06:48:30
问题 I'm playing around with Jersey 2.21 and I'd like to know if it's possible to have an "optional" param which can, or not, be present in the request made to the server. I want to successfully access this two methods: http://localhost:8080/my_domain/rest/api/myMethod/1 http://localhost:8080/my_domain/rest/api/myMethod As you can see, I'm trying to make the integer ( id ) param an optional one. I've declared myMethod as follows: @GET @Path("myMethod/{id}") @Produces(MediaType.APPLICATION_JSON + "

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

邮差的信 提交于 2019-11-27 03:52:51
问题 I am unable to find answer through the following links One Two Three Following is my pom.xml dependency <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk</artifactId> <version>1.11.41</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.2</version> <type>jar</type> <

securing rest services in Jersey

我的梦境 提交于 2019-11-27 03:44:17
问题 I am very much new to web services. I have exposed some REST services using Jersey 2 in integration with Spring. Now I need to secure those rest services using authentication with username/password. I am told not to use Spring security. I have no idea of how to do this. I did search on the net but various links show various implementation and I am unable to decide how to proceed with it. I know this is something vague question but please help in this context. 回答1: A common way for

Jersey Services with Tomcat and Eclipse

被刻印的时光 ゝ 提交于 2019-11-27 03:38:09
问题 I'm developing a rest service with Jersey 2.0 (I downloaded from http://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.5/jaxrs-ri-2.5.zip) and I'm using Tomcat 7.0.47. I run Tomcat from Eclipse and my machine is a Mac. I'm using the Eclipse tool to generate a WAR and to deploy the service. This is my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http:/