jax-rs

Getting Response in ContainerResponseFilter's (JAX-RS 2)

梦想与她 提交于 2019-12-21 14:59:30
问题 I am trying to port this CORS filter to JAX-RS 2. However, I do not see how to get the Response object (as in the old code) from the ContainerResponseContext I get passed in the overridden method of ContainerResponseFilter. If there is a more elegant way to do CORS with JAX-RS 2, that would be preferrable of course. Thanks in advance. 回答1: Thre response is directly accessible as the ContainerResponseContext : @Provider public class ResponseCorsFilter implements ContainerResponseFilter{

Why are names returned with @ in JSON using Jersey

大憨熊 提交于 2019-12-21 10:10:12
问题 I am using the JAXB that is part of the Jersey JAX-RS. When I request JSON for my output type, all my attribute names start with an asterisk like this, This object; package com.ups.crd.data.objects; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType; @XmlType public class ResponseDetails { @XmlAttribute public String ReturnCode = ""; @XmlAttribute public String StatusMessage = ""; @XmlAttribute public String TransactionDate =""; } becomes this, {

Is it possible to reuse Java trusted certificates for javax.ws.rs (Resteasy implementation)?

左心房为你撑大大i 提交于 2019-12-21 09:35:02
问题 Suppose we need to trust a self-signed SSL certificate. As an example, let's use https://self-signed.badssl.com/. Since the signer is not a "proper" authority, Java doesn't trust it and refuses to connect to that server. However, after $ cd $JAVA_HOME/jre/lib/security $ keytool -import -trustcacerts -alias ... -file ... -keystore cacerts and restart of the application, the following code works: new URL ("https://self-signed.badssl.com/").openConnection ().getResponseCode () and returns 200

How do I get the URL of a request?

半城伤御伤魂 提交于 2019-12-21 07:22:44
问题 I am using Jeresy Jax-RS to build a web service. Now I need to get the url of the request with the port # if one exist. So if my service runs on http://www.somelocation.com/web/services I want to capture the www.somelocation.com How can I do this ? 回答1: You can add a UriInfo parameter to your operation. From there you can access the URL: @POST @Consumes({"application/xml", "application/json"}) public Response create(@Context UriInfo uriInfo, Customer customer) { ... } 来源: https:/

How do I get the URL of a request?

蓝咒 提交于 2019-12-21 07:22:02
问题 I am using Jeresy Jax-RS to build a web service. Now I need to get the url of the request with the port # if one exist. So if my service runs on http://www.somelocation.com/web/services I want to capture the www.somelocation.com How can I do this ? 回答1: You can add a UriInfo parameter to your operation. From there you can access the URL: @POST @Consumes({"application/xml", "application/json"}) public Response create(@Context UriInfo uriInfo, Customer customer) { ... } 来源: https:/

How do I get the URL of a request?

青春壹個敷衍的年華 提交于 2019-12-21 07:22:02
问题 I am using Jeresy Jax-RS to build a web service. Now I need to get the url of the request with the port # if one exist. So if my service runs on http://www.somelocation.com/web/services I want to capture the www.somelocation.com How can I do this ? 回答1: You can add a UriInfo parameter to your operation. From there you can access the URL: @POST @Consumes({"application/xml", "application/json"}) public Response create(@Context UriInfo uriInfo, Customer customer) { ... } 来源: https:/

Generating Swagger documentation from existing REST api

不打扰是莪最后的温柔 提交于 2019-12-21 06:38:30
问题 Given an existing JAX-RS-annotated API that accepts & returns json, with jackson-annotated types, is there a way that I can generate some YAML Swagger documentation? My plan B is to write some code that uses reflection to find REST-annotated types, make a hashmap of their arguments & returns, and then crawl those classes for Jackson annotations, and generate the documentation that way. I would prefer to use a solution that already exists to writing a one-off thing. I found this Swagger module

How can i create Filter or Handler in REST(Jersey) for wrapping JAX-RS Requests?

时光怂恿深爱的人放手 提交于 2019-12-21 06:06:24
问题 I have some resources in my jax-rs application i want to validate jax-rs request before it enters into the resource annotated by javax.ws.rs.Path. so, how can i create handler or filter for my resources .I have searched so many sites. their suggestions are use proxy or servlet filters . without using proxy or servlet filters can i create handler/ filter ? Just like in JAX-WS SOAPHandler is available for soap request ,in the same way is there any handlers for validating jax-rs request. Here

How do I use a properties file with jax-rs?

大憨熊 提交于 2019-12-21 06:06:07
问题 I've just been getting started setting up a web service with jax-rs running on Tomcat. Is there a way to bundle a properties file with my java project (in eclipse) so that I can read properties out of it at runtime? Also if it's possible, where would be the best location to put it (so that it couldn't be seen via a url), WebContent, WEB-INF, etc? Thanks. 回答1: Several options: Option 1: You can put it under your classpath (in Eclipse put it under and source folder), so you can access it via

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy

纵然是瞬间 提交于 2019-12-21 05:06:33
问题 I'm using a Restful web service (Jersy implementation) with a JSF application and used Json to get the data as follows: carObjectDao = new GenericDAO<carObject>(carObject.class); List<carObject> allCars = carObjectDao.readAll(); Gson gson = new Gson(); String carString = gson.toJson(allCars); System.err.println(carString ); return carString ; i run the application in debug mode and allCars is filled with the data correctly, but after that an exception is thrown : java.lang