jax-rs

Maven shade + resteasy Could find writer for content-type

帅比萌擦擦* 提交于 2019-12-31 04:01:07
问题 I have a project that works fine with maven managed dependencies. But I have a requirement for giving my jar files as one. For this I use maven-shade plugin (http://maven.apache.org/plugins/maven-shade-plugin/). All class files are exported correctly but when I try to run my application I get an error as: Could find writer for content-type multipart/form-data type: org.jboss.reasteasy.plugins.provider.multipart.MultipartFormDataOutput Any help would be great, thanks. Note: I had a similar

How to customize error response when deserializing failed

隐身守侯 提交于 2019-12-31 03:51:13
问题 I have a jaxrs endpoint service, in my own ResourceConfig I register an ExceptionMapper , so when somewhere wrong happened, it will return a JSON { errorEnum: "something" } . The service class looks like this. @POST @Path("/query") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response query(final QueryDefinition queryDefinition) { ... } However, in my payload, there is a field which is Enum. If any user made a typo in that field, the error message will be

MessageBodyWriter not found vogella tutorial

早过忘川 提交于 2019-12-31 00:05:32
问题 I am attempting to recreate the most excellent vogella tutorial for create REST with java, JAX-RS and Jersey. I'm using eclipse Kepler with Java-EE perspective, tomcat 7.0. I have create the Todo class, the TodoResource class with the appropriate annotations and deployed on tomcat 7. I have imported the jaxrs-ri libs into the WEB-INF/lib folder as instructed. Todo class: package com.vogella.jersey.jaxb.model; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Todo {

JAXB or JAX-RS is wrapping numbers in my JSON responses with quotes, turning them into strings. Why this is the default behavior, and how to fix it?

时光毁灭记忆、已成空白 提交于 2019-12-30 21:05:09
问题 I am currently working on a RESTful API. I have an Employee class and an EmployeeResource class. I also have a custom DateAdapter, which changes my Date properties to Long timestamps. However, my JSON responses are showing the timestamps as strings (wrapped in double quotes) rather than numbers (without double quotes). Here is an abbreviated version of my code and captured JSON response... Custom DateAdapter public class DateAdapter extends XmlAdapter<Long, Date> { @Override public Date

Equivalent of Servlet Filter for Jersey / JAX-RS / REST resources?

允我心安 提交于 2019-12-30 18:26:25
问题 In a regular Web Application, I can assign a chain of Filters to various paths for aspects such as Authentication, Authorization, Errors, Logging and more. The advantage is that I write servlets to focus on core functionality without worrying about infrastructure aspects. I can write orthogonal, cross-cutting Filters to authenticate, authorize, etc. Then I can weave them in web.xml. Looking at web.xml is enough to assure me that there are no holes in my application. Is this possible in JAX-RS

Return exception from JAX-RS Rest Service as JSON

本小妞迷上赌 提交于 2019-12-30 11:34:33
问题 Is it in some way possible that an exception thrown from a rest service is returned as JSON? I have a JAX-RS Rest Service where I would like to achieve this. When I throw it now, it's mapped to an HTML response, which is not what i want. From what I have understood an ExceptionMapper will also map it to HTML? Is there any other alternative or libraries that allows the exception to be returned in JSON format? 回答1: It will respond as JSON. @Provider @Singleton public class

Multiple endpoints with Resteasy

浪子不回头ぞ 提交于 2019-12-30 08:14:29
问题 I have two separate handfuls of REST services in one application. Let's say a main "people" service and a secondary "management" service. What I want is to expose them in separate paths on the server. I am using JAX-RS, RESTEasy and Spring. Example: @Path("/people") public interface PeopleService { // Stuff } @Path("/management") public interface ManagementService { // Stuff } In web.xml I currently have the following set-up: <listener> <listener-class>org.jboss.resteasy.plugins.server

How to use JAX-RS and Angular 2+ to download a zip file

試著忘記壹切 提交于 2019-12-30 07:53:19
问题 How to download a zip file exposed by a JAX-RS resource and serve it to the user with Angular2 final? 回答1: Given a JAX-RS resource as: @Produces({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON}) @Path("/myresource") public class MyResource { @Inject MyFacade myFacade; @POST @Path("/download") @Produces({"application/zip"}) public Response download(@NotNull Request req) { byte[] zipFileContent = myFacade.download(req); return Response .ok(zipFileContent) .type("application

Path segment sequence to vararg array in JAX-RS / Jersey?

假如想象 提交于 2019-12-30 07:03:12
问题 JAX-RS/Jersey allows URL path elements to be converted to Java method arguments using @PathParam annotations. Is there a way to convert an unknown number of path elements into arguments to a vararg Java method? I. e. /foo/bar/x/y/z should go to method: foo(@PathParam(...) String [] params) { ... } where params[0] is x , params[1] is y and params[2] is z Can I do this in Jersey/JAX-RS or some convenient way? 回答1: Not sure if this is exactly what you were looking for but you could do something

How to create a Restful web service with input parameters?

点点圈 提交于 2019-12-29 14:15:32
问题 I am creating restful web service and i wanted to know how do we create a service with input parameters and also how to invoke it from a web browser. For example @Path("/todo") public class TodoResource { // This method is called if XMLis request @PUT @Produces( {MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) public Todo getXML() { Todo todo = new Todo(); todo.setSummary("This is my first todo"); todo.setDescription("This is my first todo"); return todo; } and i can invoke it using