jax-rs

RESTeasy and the @MultipartForm , server and client

大憨熊 提交于 2019-12-24 22:28:34
问题 Walking through the RESTEasy Guide 4.4.0-final from jboss. Having the examples to guide be as well. Wanting to create a small service where you post a binary-file with some metadata. In this particular case I would like to post a file + 'the owner of that file'. In my first effort I am using the following construct (1st-attempt-server). @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile(@FormDataParam("file") InputStream is, @FormDataParam("file")

Jax-RS Filter pass object to resource

痞子三分冷 提交于 2019-12-24 19:26:14
问题 I want to pass the user object I use for authentication in a filter to the resource. Is it possible? I'm using wildfly 10 (resteasy 3) @Secured @Provider @Priority(Priorities.AUTHENTICATION) public class AuthenticationFilter implements ContainerRequestFilter { @Inject private UserDao userDao; @Override public void filter(ContainerRequestContext requestContext) throws IOException { logger.warn("Filter"); String uid = requestContext.getHeaderString("Authorization"); User user; if((user =

Which Jersey version runs in Jenkins 2.107.1?

扶醉桌前 提交于 2019-12-24 19:02:07
问题 We are running a Jenkins on Ubuntu. When we try to use a Java library in a Pipeline that uses REST calls, we run into problems. UriBuilder is apparently used in a old version: The method toTemplate is missing and caused a MethodNotFound. This is strange because the Java library depends transitively on <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0.1</version> which contains the new version of UriBuilder. We used Grape and correctly copied the library with

JAX-RS CXF Exception wrapping

丶灬走出姿态 提交于 2019-12-24 18:39:58
问题 I would like to add an ExceptionMapper to CXF (2.6.1) which not only communicates the Response code, but also ships the exception in the payload format (I'm using JSON for now). @Provider public class CustomExceptionMapper implements ExceptionMapper<MyException> { ... @Override public Response toResponse(MyException mex) { //I need something here which can convert mex object to JSON and ship it in response // I want this to be de-serialized on client //the following returns the status code

Validating queryparam values jersey

不羁岁月 提交于 2019-12-24 18:18:46
问题 Are there any other ways besides the one below to validate query parameter values i.e. is there a Jersey way to this by mapping to a schema via a wadl. Thank you @Path("smooth") @GET public Response smooth( @DefaultValue("blue") @QueryParam("min-color") ColorParam minColor, public class ColorParam extends Color { public ColorParam(String s) { super(getRGB(s)); } private static int getRGB(String s) { if (s.charAt(0) == '#') { try { Color c = Color.decode("0x" + s.substring(1)); return c.getRGB

JERSEY-RS showing 405 in POST

给你一囗甜甜゛ 提交于 2019-12-24 18:09:04
问题 I am trying to create a post webservice using jersey. Following is my PostMethod; @POST @Path("getEncodedURL") @Produces(MediaType.TEXT_XML) public String getEncodedURL(@FormParam(value = "url") String url, @FormParam(value = "eventId") int eventId) { //mylogic here to get encoded url. return "<data><eventId>"+eventId+"</eventId><url>"+url+"</url></data>"; } Following is my index.jsp code. <form id="form10" method="post"> Enter URL to Encode: (String) <input type="text" name="testName" id=

JERSEY-RS showing 405 in POST

纵然是瞬间 提交于 2019-12-24 18:08:03
问题 I am trying to create a post webservice using jersey. Following is my PostMethod; @POST @Path("getEncodedURL") @Produces(MediaType.TEXT_XML) public String getEncodedURL(@FormParam(value = "url") String url, @FormParam(value = "eventId") int eventId) { //mylogic here to get encoded url. return "<data><eventId>"+eventId+"</eventId><url>"+url+"</url></data>"; } Following is my index.jsp code. <form id="form10" method="post"> Enter URL to Encode: (String) <input type="text" name="testName" id=

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

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

How can I integrate Jersey with TomEE?

若如初见. 提交于 2019-12-24 13:57:55
问题 I attempt to deploy a very simple RESTful Web Service using Jersey 1.18 within Tomee 1.5.2 WebProfile. My project is fully inspired from the tomee-jersey-eclipselink example that I further simplified by removing the persistence part: the Web Service simply retuns "Hello, World!" @Path("/hello") @RequestScoped public class HelloService { public HelloService() { } @GET public String test() { return "Hello, World!"; } } My dependencies in my POM: <dependencies> <dependency> <groupId>javax<