jersey-2.0

Jersey Server-Sent Events - write to broken connection does not throw exception

时间秒杀一切 提交于 2019-12-10 15:24:28
问题 We are using Jersey Server-Sent Events (SSE) to allow remote components of our application to listen to events raised by our Jersey/Tomcat server. This works great. However, it is crucial that our server have an accurate list of currently-connected listeners (our remote components). To this end, our server sends a tiny message to each caller (via eventOutput.write) once every five seconds. If our remote component is shut down while SSE-connected, or if the remote computer is powered off while

Registering Dropwizard configuration with Jersey 2 (HK2) DI

倾然丶 夕夏残阳落幕 提交于 2019-12-10 12:22:45
问题 In my Dropwizard (1.2.4) application I'm having trouble injecting my Dropwizard configuration into classes that are instantiated by HK2. What's the best way to achieve this? 回答1: Just bind the configuration instance . @Override public void run(final DummyConfiguration conf, Environment env) { env.jersey().register(new AbstractBinder() { @Override public void configure() { bind(conf).to(DummyConfiguration.class); } }) } Now you can @Inject the DummyConfiguration anywhere you need it. 来源: https

Jersey 2 exception handing

微笑、不失礼 提交于 2019-12-10 12:09:10
问题 I am using Jersey 2.10 exception mapper class for handling exceptions. I want to return error status and JSON body for the error info. I want to get a response similar to this: 400 Bad Request X-Powered-By: Servlet/3.0 Content-Length: 152 Content-Type: application/json Content-Language: en-AU Date: Thu, 21 Aug 2014 07:21:40 GMT {"errors":[{"code":"LKVBS182","type":"ERROR","message":"COUNTRY NAME IS NOT DEFINED IN DATA-BASE"}],"status":"ERROR","errorStatus":"Bad Request","errorCode":400}

Jersey 2 Client java.lang.NoSuchMethodError: org.glassfish.jersey.CommonProperties.getValue

余生长醉 提交于 2019-12-10 11:02:17
问题 I'm trying to setup a very simple Jersey client example. So I started with a pom.xml like this: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>simple-service-webapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simple-service-webapp

Getting MessageBodyWriter not found for media type=application/json

馋奶兔 提交于 2019-12-10 10:03:21
问题 I've tried everything...can't figure out why I'm getting this exception. What's interesting is that in my IDE (Intellij) everything works without a hitch. Can't figure this out...giving up. Do any of you have any suggestions? dependencies { compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.10.27' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7' compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2' compile group: 'ch.qos.logback', name:

Why Jersey doesn't honor the priorities in dynamically bind filters?

戏子无情 提交于 2019-12-10 09:16:01
问题 I am using the DynamicFeature in Jersey to dynamically bind a container request filter to some particular resource methods. In addition to the DynamicFeature , I also have regular filters that apply to all resource methods. However, I found the priorities/orders of these filters not working as expected. For example: public class MyDynamicFeature implements DynamicFeature { @Override public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) { featureContext.register

AbstractMethodError on UriBuilder when upgrading Jersey client 1.x to 2.x

一世执手 提交于 2019-12-10 05:52:54
问题 We're in the process to upgrade our Web application (running on Tomcat7) from Jersey 1.7 to Jersey 2.4.1. I managed to have the server-side working now, but the JUnit tests which are using jersey-client are throwing the AbstractMethodError: java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder; at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119) at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:72) at

What is the Jersey 2.0 equivalent of GZIPContentEncodingFilter

我的未来我决定 提交于 2019-12-10 04:09:59
问题 I am in the progress to migrate a Jerset 1.x client project to Jersey 2.0. I found that GZIPContentEncodingFilter does not exist any longer. Is there something similar? I stumbled over GZIPEncoder but am not sure how to plug it in. In Jersey 1.17 I use: WebResource r = ... r.register(new GZIPContentEncodingFilter()); In Jersey 2.0 I search for somethink like: WebTarget r = ... r.register(new GZIPContentEncodingFilter()); 回答1: Use WebTarget r = ... r.register(GZIPEncoder.class); 回答2: Most of

Jersey 2.0 “Getting Started” guide, mainClass not found

北城以北 提交于 2019-12-09 15:57:04
问题 Hi I am trying to follow the Getting Started guide for Jersey 2.0. I did steps 1.1 and 1.2 as is. No problem there. For step 1.3 I had a problem cause maven could not find the javax-annotation 1.2 but I solved it following the advice of another Stackoverflow user and added a repository to my pom. So mvn clean test passes with no problems, BUT when I try to run mvn clean exec:java I get back [WARNING] java.lang.ClassNotFoundException: com.example.Main at java.net.URLClassLoader$1.run

How to list all registered JAX-RS Entity Providers in Jersey

浪子不回头ぞ 提交于 2019-12-09 13:11:12
问题 Let's suppose i have simple jersey app with embedded jetty Demo project on github and essential code below. Back in the days with jersey1 i had log messages: мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for root resource and provider classes in the packages: ru.varren мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class ru.varren.MyResource мая 07, 2016 5:05:50 AM com.sun.jersey