jax-rs

How do I @Inject a CDI @ApplicationScoped bean into a @RequestScoped JAX-RS bean?

怎甘沉沦 提交于 2020-01-03 13:34:16
问题 I've added the @ApplicationScoped CDI annotation to a simple bean: @ApplicationScoped public class History { And tried to then @Inject this into a JAX-RS (resteasy) bean: @RequestScoped @Path("/history") public class HistoryAPI { @Inject private History history; But history remains null. I've got a beans.xml file in WEB-INF. I've tried a lot of variations on this theme, but while the app server (Wildfly) acknowledges it's starting with CDI I can't get the injection to work. Any ideas what I"m

How to avoid network call when REST client and server are on the same server

喜夏-厌秋 提交于 2020-01-03 11:33:23
问题 I have a web application in which two of the major components are the website (implemented in Groovy and Grails) and a backend RESTful web service (implemented using JAX-RS (Jersey) and Spring). Both of these will be running in Glassfish. The website will make calls to the RESTful web service. In many cases, these components will reside on separate servers, so the website will make calls over the network to the RESTful web service. If, however, I run both applications in the same Glassfish

CXF BusException No DestinationFactory for namespace http://cxf.apache.org/transports/http

耗尽温柔 提交于 2020-01-03 10:59:10
问题 I'm trying to stand up the [basic cxf rs example][1], but with my own service impl which is even simpler and all my methods return strings. When I try to run this server I get this exception I built a clean project so I'm starting fresh.. Master pom http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <name>Tests</name> <groupId>com.crush</groupId> <artifactId>tests</artifactId> <version>1.0</version> <packaging>pom</packaging> <properties> <cxf.version>2.7.11</cxf

@jsonview of jackson not working with jax-rs

自闭症网瘾萝莉.ら 提交于 2020-01-03 08:56:48
问题 I have written following code: class A{ public static class Public { } } // Entity class public class B{ @JsonView({A.Public.class}) int a; int b; } public class C{ @GET @Produces(MediaType.APPLICATION_JSON) @JsonView({A.Public.class}) public Bed getData(){ // return object of B } } I am expecting output as {a: vlaue} but i am recieving {a: value, b: value} Please let me know what is wrong in this code. i am using jackson version 2.4.2 回答1: The reason for this behavior is the MapperFeature

How to read authorization header in JAX-RS service

这一生的挚爱 提交于 2020-01-03 08:07:09
问题 I am new to Authorization header, trying to create authorization(and authentication) using a JAX-RS service My snippet at the javascript looks like this: sUrl = getURL() + "/com.cabRoutePlanner.Login/Login"; var oHeaders = {}; oHeaders['Authorization'] = "Basic " + btoa(getUserName() + ":" + getPassword()); var request = { headers : oHeaders, requestUri : sUrl, data: connectionData, method : "POST" }; OData.request(request, onSuccessForRegister, onRegError); Now, I want to read this

How to read authorization header in JAX-RS service

ぃ、小莉子 提交于 2020-01-03 08:06:28
问题 I am new to Authorization header, trying to create authorization(and authentication) using a JAX-RS service My snippet at the javascript looks like this: sUrl = getURL() + "/com.cabRoutePlanner.Login/Login"; var oHeaders = {}; oHeaders['Authorization'] = "Basic " + btoa(getUserName() + ":" + getPassword()); var request = { headers : oHeaders, requestUri : sUrl, data: connectionData, method : "POST" }; OData.request(request, onSuccessForRegister, onRegError); Now, I want to read this

ExceptionMapper not invoked if receiving invalid JSon

穿精又带淫゛_ 提交于 2020-01-03 04:51:27
问题 I am using Jersey 2.5.1 with Jackson 2.2. for building JSON Rest web services. I kind of got it up and running also with 2 ExceptionMappers but for a "not-json" request the application is not throwing any exception! ExceptionMapper Will be invoked if e.g. a NullPointerException is thrown ExceptionMapper Will be invoked if there s a problem with the JSon Mapping My Problem: 1. Request Body: {} works 2. Request Body: {} with an application side NullPointer invoked the first exception mapper 3.

How to handle unexpected exceptions in JAX-RS

萝らか妹 提交于 2020-01-03 03:01:30
问题 My technology stack is Tomcat (servlet 3.0), Jersey for JAX-RS, Spring and Hibernate. When something unexpect goes wrong like some data conversion error in Hibernate, I do not want the clients to see my stacktrace for those exceptions that the Tomcat tries to print by default. However I would like to log those exceptions so I can find what is wrong and fix things. My first try was using ExceptionMapper from JAX-RS and naively thinking that would solve my problems. But then I noticed that

what is the use of @PersistentContext and @Stateless in JAX-RS?

筅森魡賤 提交于 2020-01-02 23:01:08
问题 I am fairly new to using JAX-RS. The tutorials I went through made it really simple by showing how to make GET/POST/DELETE requests. But did not go through advanced annotations. Now I am reading the Java EE 7 essentials book. I am confused with many new annotations that I see here. I tried to find the utility of these annotations. but I did not understand. I have always found SO answers to be easily understandable for beginners. Here is the code from github: Employee.Java @Entity @Table(name

ajax call to jax-rs with jquery issue

两盒软妹~` 提交于 2020-01-02 10:25:11
问题 I'm trying to call a Webservice that consumes a json object with post method .I did it then It wont work again don't know what is the problem. here is my method @POST @Path("/post") @Consumes("application/json") @Produces("application/json") public Response testClient(Client c) throws IOException { System.out.println(c.getAdresseCl()); ResponseBuilder builder = Response.ok(c.getAdresseCl()); builder.header("Access-Control-Allow-Origin", "*"); builder.header("Access-Control-Max-Age", "3600");