jax-rs

JAX-RS and Apache CXF

安稳与你 提交于 2021-01-29 03:40:14
问题 I am new to Webservices, I am confused about the JAX-RS and apache CXF What i read is that JAX-RS is API and Apache CXF is implementation of JAX-RS JAX-RS is not specification , Is it possible to direclty use JAX-RS to build REST services? Please correct me if I am wrong Regards 回答1: JAX-RS is a specification. The binaries provided by it only contain Interface definitions but no implementations. The default implementation of JAX-RS is Jersey. It provides implementations plus additional

Obtain the request in Resteasy JAX-RS method

夙愿已清 提交于 2021-01-28 19:21:11
问题 I have a Jax-Rs service that I run with Resteasy, and in the implementation of the methods I want to access the request data. I know of the existence of the @Context annotation but this requires me to modify the service interface which is not practical (or even possible with Java Jax-Rs clients) that use the same interface for client proxy creation. So to make it cleaner, I have this interface which I can't modify. @POST @Path("/ping") @Consumes({ javax.ws.rs.core.MediaType.APPLICATION_JSON,

How to make post ajax call with JSON data to Jersey rest service?

你离开我真会死。 提交于 2021-01-28 07:00:30
问题 I have been through this link. but this did not helped me out. I am using jersey lib v1.17.1. My jersey rest service: @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) @Path("/post1") public ResponseBean post1(@QueryParam("param1")String param1) { return ResponseFactory.createResponse(param1, "TEST", "TEST", null, true); } url is: /test/post1 My ajax call: var d = {"param1":"just a dummy data"}; $.ajax({ type : "POST", url : "http://localhost:7070/scl/rs

How to write a REST API method for which consume json format for list of objects

回眸只為那壹抹淺笑 提交于 2021-01-28 06:17:50
问题 I have written a method as following. @POST @Path("/add") @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8") public boolean createMeasurement(List<MeasurementBean> list ,@HeaderParam(AUTHORIZATION) String authString){ Gson gson = new Gson(); LoginSession loginSession=null; try{ loginSession = LoginUtility.validateKey(authString); ResultRO<List<HashMap<String, Object>>> resultRO = loginSession .execute(new Callable<ResultRO<List

GET request fails with JAX-RS: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: text/html

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 05:55:22
问题 I'm building a sample client-server with JAX-RS using JEE7. I'm using Wildfly 10.1 I followed the guy in this video. Here is the code of the war that runs on the application server: boundary package contains the service package pl.devcrowd.virtual.business.chickens.boundary; import java.util.List; import javax.ejb.Stateless; import javax.inject.Inject; import pl.devcrowd.virtual.business.chickens.controls.ChickenStore; import pl.devcrowd.virtual.business.chickens.entity.Chicken; @Stateless

How to return HTTP 404 instead of HTTP 204 response code for null values in jersey

﹥>﹥吖頭↗ 提交于 2021-01-28 05:04:17
问题 I have a Jersey REST API that returns 204 No content instead of 404 when the entity to be returned back is null . To address this issue, I'm currently planning to throw an exception within the resource method so that it could force Jersey to return 404 like below. if (feature == null) throw new WebApplicationException(404); But I have various REST URIs that suffer from the same problem. Is there a way to address all of them without touching each and every resource method? My resource methods

Configure JettyTestContainer with SSL for JerseyTest

拥有回忆 提交于 2021-01-27 21:11:19
问题 I've been tasked with setting up integration tests for my team's code. These tests will require performing HTTPS requests to REST endpoints implemented in Jersey 2.27. In my search for how to perform this kind of test, I stumbled upon this article from Baeldung that pointed me to the Jersey Test Framework and the provider containers they've implemented for this purpose. I chose the Jetty container, as our code was using a 'roll your own' Jetty instance to do all this. I began the

Jersey web service proxy

不羁岁月 提交于 2021-01-27 06:58:48
问题 I am trying to implement a web service that proxies another service that I want to hide from external users of the API. Basically I want to play the middle man to have ability to add functionality to the hidden api which is solr. I have to following code: @POST @Path("/update/{collection}") public Response update(@PathParam("collection") String collection, @Context Request request) { //extract URL params //update URL to target internal web service //put body from incoming request to outgoing

How to get the client IP address in a JAX-RS resource class without injecting the HttpServletRequest?

岁酱吖の 提交于 2021-01-24 12:09:40
问题 We are using JAX-RS 1.0 and I want to get the client IP address in my resource class. Currently I inject the HttpServletRequest as a method parameter and then get the IP address. I want to make my code cleaner. I am thinking if I can use a MessageBodyReader class and set the IP address. But if I use a MessageBodyReader I have to unmarshall the XML to a Java object which is additional logic as far as I believe. Can anyone please let me know how to get the client IP address without having to

How to get the client IP address in a JAX-RS resource class without injecting the HttpServletRequest?

守給你的承諾、 提交于 2021-01-24 12:07:55
问题 We are using JAX-RS 1.0 and I want to get the client IP address in my resource class. Currently I inject the HttpServletRequest as a method parameter and then get the IP address. I want to make my code cleaner. I am thinking if I can use a MessageBodyReader class and set the IP address. But if I use a MessageBodyReader I have to unmarshall the XML to a Java object which is additional logic as far as I believe. Can anyone please let me know how to get the client IP address without having to