jersey

How do I override all 404 pages without defining default handlers for every resource?

孤街醉人 提交于 2019-12-24 16:36:56
问题 In my Dropwizard project, I'm defining a generic ExceptionMapper<WebApplicationException> : environment.jersey().register(new WebApplicationExceptionMapper()); ...but this doesn't seem to catch any of the 404 errors for unmatched paths. Without defining five defaultHandler() methods for every single resource, how do I catch all 404s so I can return my own error page or some JSON? So, if I had a service with one resrouce, say, /docs , this is the situtation: /myservice/docs/helloworld doesn't

Refer to a web page inside a jar file

社会主义新天地 提交于 2019-12-24 16:35:44
问题 I have a working project. It includes another project which deals with REST as a rest-api.jar. Now I have done an one-page UI for this REST API on AngularJS and provided it for the main app. The problem is that I cannot find a way to refer to this page from the main project because this page MUST be within the rest_api.jar This is a way I solved it. Simply redirecting to a page: @GET @Produces(MediaType.TEXT_HTML) public void doGetAsHtml(@Context UriInfo info, @Context HttpServletResponse

how to avoid JAXB extracting element's namespace and put it at the place of root element

限于喜欢 提交于 2019-12-24 16:22:00
问题 please help me with following question: I am using Jersey and I have one XML, this XML comes with a class named "Definition" with well XML annotation annotated, the XML looks like: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <tosca:Definitions xmlns:tosca="http://docs.oasis-open.org/tosca/ns/2011/12" targetNamespace="http://www.example.org/" id="winery-defs-for_ex1-MediaWiki"> <tosca:ServiceTemplate targetNamespace="http://www.example.org/" name="MediaWiki" id="MediaWiki"> <ns3

Jersey Exception when trying to convert a custom object to json

…衆ロ難τιáo~ 提交于 2019-12-24 16:01:06
问题 Before you guys mark this question a duplicate, I would like to tell you guys that I have already tried the solutions from A message body writer for Java class not found javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: JSON support in Java REST Webservices with Jersey https://www.nabisoft.com/tutorials/java-ee/producing-and-consuming-json-or-xml-in-java-rest-services-with-jersey-and-jackson And I am still stuck. Here is the exception that I am having. 24-Apr-2016 02

Returning both image and JSON in multipart response with Jersey

牧云@^-^@ 提交于 2019-12-24 15:46:10
问题 I'm learning Jersey by trying to create a Rest service that receives an image from client, processes the image and returns a new image with additional information (i.e., about processing details). So far, the uploading works fine. I'm now concerned with creating the response. I'm thinking of creating a multipart response that contains the new image in 1 bodypart while adding a JSON string (that contains the additional info) into another body part. However I wasn't successful. The code is as

How to get @interface parameter in jersey WriterInterceptor Implementation

廉价感情. 提交于 2019-12-24 15:23:18
问题 I have an interface, for example @NameBinding @Retention(RetentionPolicy.RUNTIME) public @interface AutoLogged { boolean query() default false; } How can I get query parameter in interceptor implementation? @Provider @AutoLogged public class AutoLoggedInterceptor implements WriterInterceptor { @Context private ResourceInfo resourceInfo; @Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { try { final String methodName = this

Using SelectableEntityFiltering in Jersey 2.17

為{幸葍}努か 提交于 2019-12-24 15:07:23
问题 I am new in Jersey and i try to use the SelectableEntityFilteringFeature from the example: http://blog.dejavu.sk/2015/02/04/jerseys-entity-filtering-meets-jackson/#selectable I create a small service with the following classes/files: a resource file called PersonResource.java import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.message.filtering.SelectableEntityFilteringFeature; import org

restful webservices jax-rs post method not working

我们两清 提交于 2019-12-24 14:48:45
问题 I am new to restful web services ..when a post request is made to "/adduser" ,like with request data as {"iduser":5,"name":"bob"} , the rest client gives 500 error and eclipse console gives MySqlSyntaxErrorException: Unknown column 'bob' in 'field list' DbConnection.java package com.dbproject; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DbConnection { public static Connection getConnection(){ Connection con=null; try { Class.forName(

Jersey invoking sub resource wrongly

喜你入骨 提交于 2019-12-24 14:47:51
问题 I am learning RESTful web services using JAX-RS. I have a MessageResource and a sub resource CommentResource . In my MessageResource I mapped comment sub resource with test method, which I commented in the MessageResource class because I don't want CommentResource to be invoked. package org.kaushik.javabrains.messenger.resource; import java.net.URI; import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws

Access object created in ContainerRequestFilter in Resources

≯℡__Kan透↙ 提交于 2019-12-24 14:27:46
问题 How to make user object available for further processing in a Resource @Priority(Priorities.AUTHENTICATION) public static class ResourceAllowedRequestFilter implements ContainerRequestFilter { private AuthorizationValidation authorizationValidation; public ResourceAllowedRequestFilter() { try { authorizationValidation = new AuthorizationValidation(); } catch (Exception e) { } } @Override public void filter(ContainerRequestContext requestContext) throws IOException { if (userHeader == null) {