jax-rs

Jersey HK2 Dependency Injection doesn't work after update to v2.27

泪湿孤枕 提交于 2019-12-23 02:53:29
问题 I have a project using Jersey v2.25.1. I was using Jersey's inbuilt HK2 injection to perform dependency injection, and everything worked fine. Fast forward to now, I decided to update to Jersey v2.27. When I ran my project, I got the following exception: java.lang.IllegalStateException: InjectionManagerFactory not found After some googling, I found that I needed to add the jersey-hk2 dependency. Doing so made me get the following exception: org.glassfish.hk2.api.UnsatisfiedDependencyException

Securing with roles annotations not working (Jersey)

自古美人都是妖i 提交于 2019-12-23 01:34:21
问题 I'm new here even though I've found many answers to my problems in here before. Now I'm looking for help with this: I have this little example resource on my little REST API: @Path("/greeting") @PermitAll public class HelloResource { @GET @Produces(MediaType.TEXT_PLAIN) @Path("all") public String sayHelloToAll() { return "Hello, everybody!"; } @GET @Produces(MediaType.TEXT_PLAIN) @RolesAllowed("admin") @Path("admin") public String sayHelloToAdmin() { return "Hello, admin!"; } } In order to

how to map a bean structure to a different schema with jax-rs

大城市里の小女人 提交于 2019-12-23 00:46:31
问题 I have this bean @XmlRootElement class Test { boolean someValue; List<Field> fields; } I would like to serialize it as <fields> <field> <name>someValue</name> <value>...</value> </field> </fields> <fields> <field> <name>otherValue</name> <value>...</value> </field> </fields> (or as json) How should I do that, preferrably using jaxb annotations? I'm using jersey, but the answer doens't have to be specific to it. 回答1: How about the following? Using EclipseLink JAXB (MOXy) you could do the

Jax rs: How can I run a method automatically everytime my server restarts?

丶灬走出姿态 提交于 2019-12-22 18:15:09
问题 I Have made a jax rs jersey web service. I have to load data from database when server restarts. What I am doing now is calling this url http://localhost:8080/jersey-openshift-quickstart2/logisure/load It loads data from database and keeps on updating it in every 20 sec by calling a thread. Based on this data other API functionalities work. Now when I deployed it on cloud I found out server restarts in every 2-3 days so I need my webservice to automatically call http://localhost:8080/jersey

Jersey 2 JSON Jettison unwrapping root element

谁说我不能喝 提交于 2019-12-22 17:56:40
问题 We are migrating from Jersey 1 to Jersey 2. Up until now we were using ContextResolver configured like this: import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.api.json.JSONConfiguration.MappedBuilder; @Provider @Produces("application/json") public class JSONJAXBContextResolver implements ContextResolver<Class<?>> { @Override public JAXBContext getContext(Class<?> objectType) { MappedBuilder mapped = JSONConfiguration.mapped(); mapped.arrays("Property"); //$NON-NLS-1$

feign使用教程

旧街凉风 提交于 2019-12-22 13:54:06
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 简介 Feign是一款java的Restful客户端组件,Feign使得 Java HTTP 客户端编写更方便。Feign 灵感来源于Retrofit, JAXRS-2.0和WebSocket。Feign 最初是为了降低统一绑定Denominator 到 HTTP API 的复杂度,不区分是否支持 ReSTfulness。 为什么选择Feign而不是其他 你可以使用 Jersey 和 CXF 这些来写一个 Rest 或 SOAP 服务的java客服端。你也可以直接使用 Apache HttpClient 来实现。但是 Feign 的目的是尽量的减少资源和代码来实现和 HTTP API 的连接。通过自定义的编码解码器以及错误处理,你可以编写任何基于文本的 HTTP API。 Feign工作机制 Feign 通过注解注入一个模板化请求进行工作。只需在发送之前关闭它,参数就可以被直接的运用到模板中。然而这也限制了 Feign,只支持文本形式的API,它在响应请求等方面极大的简化了系统。同时,它也是十分容易进行单元测试的。 基本用法 基本的使用如下所示,一个对于canonical Retrofit sample的适配。 interface GitHub { @RequestLine("GET /repos/{owner

Cant inject Bean class into Restfull WebService (JAX-RS) [duplicate]

亡梦爱人 提交于 2019-12-22 12:38:15
问题 This question already has answers here : Inject an EJB into JAX-RS (RESTful service) (7 answers) Closed 3 years ago . I'm trying to save data acquired by Rest web service to database using hibernate/persistence. In one of my web modules i implemented that service. Database ejb connector is placed in EJB module. They are parts of EAR application. Every time when i call pb.addDevice() im getting java.lang.NullPointerException when puting proper url with params in browser(worked till i wanted to

Initialize singleton in Java Jersey 2 JAX-RS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 12:31:48
问题 I'm new to Jersey (2.22.2), so bear with me please. I am creating a REST service that interfaces with an LDAP server for storing, removing, and retrieving user data. The service acts as a security intermediary by performing encryption/decryption. There is quite a bit of initialization that must take place before the REST services can be utilized, and I would like to only perform this initialization once (when the application is deployed on the server). So this service would be run as a

HTTP 400 Bad Request : javax.ws.rs.BadRequestException

你。 提交于 2019-12-22 12:23:53
问题 I create a RESTful web service and write a client to use it . but when I run it i take HTTP 400 Bad Request : javax.ws.rs.BadRequestException exeption . this is my client code : String webserviceURI = "http://localhost:8084/fsc-access"; ClientConfig clientConfig = new ClientConfig(); Client client = ClientBuilder.newClient(clientConfig); URI serviceURI = UriBuilder.fromUri(webserviceURI).build(); WebTarget webTarget = client.target(serviceURI); MultivaluedMap formData = new MultivaluedMapImpl

javax.ws.rs.NotFoundException: Could not find resource for full path Error Occures

会有一股神秘感。 提交于 2019-12-22 10:25:17
问题 I found this same question in here few times, but I couldn't find an answer to that. When I run my application, Im getting the following error javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/RemoteQuartzScheduler/rest/TestClass/hello at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker