resteasy

Using JAXB to pass subclass instances as superclass

巧了我就是萌 提交于 2019-12-18 20:56:42
问题 What I have is a set of Java classes (close to 25) representing message types. They all inherit from a Message class which I'd like to be abstract. Each message type adds a few additional fields to the set provided by the Message superclass. I'm implementing some RESTful web services using RESTeasy and would like to have methods like this: public Response persist(Message msg) { EntityTransaction tx = em.getTransaction(); tx.begin(); try { em.persist(msg); } catch (Exception e) { e

No 'Access-Control-Allow-Origin' header is present on the requested resource - Resteasy

人走茶凉 提交于 2019-12-18 11:48:49
问题 I am working on a webapplication comprises UI-Angular , Server-Java , RestEasy 3.0.9.Final for rest api calls When i tried to access the rest service from another domain am getting below error CANNOT LOAD Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. I configured my server side to respond with the cross domain calls and this is

RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse

霸气de小男生 提交于 2019-12-18 07:39:15
问题 I'm trying to test Keycloak REST API. Instaled the version 2.1.0.Final. I can access the admin through browser with SSL without problems. I'm using the code above: Keycloak keycloakClient = KeycloakBuilder.builder() .serverUrl("https://keycloak.intra.rps.com.br/auth") .realm("testrealm") .username("development") .password("development") .clientId("admin-cli") .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) .build(); List<RealmRepresentation> rr = keycloakClient

failed to lazily initialize a collection of role in ManyToMany relationship despite using JsonIgnore

梦想的初衷 提交于 2019-12-18 07:21:01
问题 I have two business objects having many too many relationships. I am using a REST service to call the DAO method given below and get a list of political indicators for a political event. However though the piList in DAO successfully gives me the list of Political Indicators but it still gives me an exception Failed to lazily intialize a collection of role... through reference chain: org.hibernate.collection.internal.PersistentBag[0]----->PolIndicator.piList.role org.jboss.resteasy.spi

RESTeasy client code for attaching a file

自古美人都是妖i 提交于 2019-12-18 05:14:14
问题 I need to attach a file to my service end-point . I tested the functionality via POSTMAN ( chrome browser plugin to test rest service ) , it is working fine. But I need to test the same with JUNIT . For that case I am using RESTeasy client . I was trying with this code : StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader("C:/Temp/tempfile.txt")); try { String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator

Inserting links into RESTEasy XML results via JAXB

天涯浪子 提交于 2019-12-18 02:53:12
问题 I want to insert links into XML via RESTeasy / JAXB . I tried to use the documentation for my code, but that did not work, so I just coded the given examples in the documentation: it still does not work and I have no idea why. Background: To implement the HATEOAS principles into my JBoss RESTEasy API I have to insert links into my JAXB XML results, so clients can navigate through the API. I am now trying to understand how to do that, but I am not sure if the documentation is full of errors or

Optional @PathParam in Jax-RS

十年热恋 提交于 2019-12-17 16:06:24
问题 I have a service where the last part of the path is optional, the user can both enter /mypath/ and /mypath/param1/ . I tried to use a regular expression to filter the last part of the path: @Path("/mypath{param1: (/param1)?}") I'm using RestEasy as my JAX-RS provider and the code works as expected in Tomcat but when I deploy it in JBoss I get a 405 return code when I do not submit the optional part. Am I doing something wrong here or it's not possible to accomplish this in a portable way? 回答1

RESTEasy client framework authentication credentials

人盡茶涼 提交于 2019-12-17 15:35:56
问题 RESTEasy (a JAX-RS implementation) has a nice client framework, eg: ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri); How do you provide HTTP authentication credentials to this client? 回答1: jnorris's answer uses some deprecated classes. Here is an updated way that uses non-deprecated classes. import org.apache.http.HttpStatus; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.impl.client.DefaultHttpClient

Logging request and response in one place with JAX-RS

三世轮回 提交于 2019-12-17 15:23:25
问题 I have a RESTEasy web server with lot of methods. I want implement logback to track all requests and responses, but I don't want add log.info() to every methods. Maybe there's way to catch requests and responses in one place and log it. Maybe something like a filter on HTTP request process chain on RESTEasy. @Path("/rest") @Produces("application/json") public class CounterRestService { //Don't want use log in controler every method to track requests and responces static final Logger log =

How can I override the decisions made during JAX-RS Content Negotiation?

孤人 提交于 2019-12-14 03:45:42
问题 I'm using RESTEasy 2.2.1.GA as my JAX-RS implementation to create a client to connect to a third party service provider. (Education.com's REST API if it matters) To make sure I haven't missed an important implementation detail here are code samples: Service Interface @Path("/") public interface SchoolSearch { @GET @Produces({MediaType.APPLICATION_XML}) Collection<SchoolType> getSchoolsByZipCode(@QueryParam("postalcode") int postalCode); } Calling Class public class SimpleSchoolSearch { public