天道酬勤,学无止境

jersey-2.0

Parse JSONObject and insert dynamic key/value into database

问题 如何将 JSONObject 中的动态键值插入数据库。 我能够从 Post Request 中提取键值并单独输出它们,但我无法管理它以将它们存储在数据库中。 @POST @Path("/user") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public String keyValueFromJson(String userFormData) throws JSONException { PreparedStatement query = null; Connection conn = null; JSONObject jsOb = new JSONObject(userFormData); JSONArray jaArr = jsOb.getJSONArray("formData"); try { conn = DaoMessenger.PostGresCon().getConnection(); for (int i = 0; i < jaArr.length();) { JSONObject jsonObject = jaArr.getJSONObject(i); Iterator<String> keys = jsonObject.keys(); while

2022-07-11 09:57:52    分类:技术分享    java   json   postgresql   jersey-2.0

Jersey: location header URI not created correctly

问题 我的 POST 方法使用以下代码返回一个 CREATED 响应: URI location = null; try { location = new URI("example"); } catch (URISyntaxException e) { e.printStackTrace(); } return Response.created(location).build(); 我在浏览器/邮递员上响应的位置标头是: base-path-to-my-webapp/example 虽然我期待base-path-to-my-web-app/current-path/example 我试图在网上寻找问题。 我得到了 https://java.net/jira/browse/JERSEY-2838 ,它表示问题已解决,如果我们 POST 到current-path/ (带有斜杠),我们应该得到正确的响应。 这似乎对我不起作用。 我正在使用泽西岛 2.23.2 回答1 查看从 Jersey 2.22 迁移到 2.22.1。 它描述了所做的更改。 如果你想要你期望的行为,设置属性 ServerProperties.LOCATION_HEADER_RELATIVE_URI_RESOLUTION_RFC7231 为true应该可以解决问题。

2022-05-16 18:46:08    分类:技术分享    java   jersey-2.0

Using Jersey's Dependency Injection in a Standalone application

问题 我这里有一个界面 interface Idemo{ public int getDemo(int i); } 这是一种实现 class DemoImpl implements Idemo{ @Override public int getDemo(int i){ return i+10; } } 还有一个类依赖于 Idemo class Sample{ @Inject Idemo demo; public int getSample(int i){ return demo.getDemo(i); } } 现在说我想测试 Sample 类 public class SampleTest extends JerseyTest { @Inject Sample s; @Override protected Application configure() { AbstractBinder binder = new AbstractBinder() { @Override protected void configure() { bind(Demo.class).to(Idemo.class); bind(Sample.class).to(Sample.class); //**doesn't work** } }; ResourceConfig config = new

2022-05-11 09:44:04    分类:技术分享    java   dependency-injection   jersey   jersey-2.0   hk2

Servlet.service() for servlet [Jersey REST Service] java.lang.NullPointerException

问题 谁能帮我解决这个问题。 这是我第一次创建restful api。 web.xml <display-name>1FxAll</display-name> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class> org.glassfish.jersey.servlet.ServletContainer </servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.sample.blitz</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping> 用户控制器.java package com.sample.blitz; @Path("/user") public class UserController

2022-05-09 16:01:22    分类:技术分享    java   servlets   jersey-2.0

Jersey: location header URI not created correctly

My POST method returns a CREATED response using the following code: URI location = null; try { location = new URI("example"); } catch (URISyntaxException e) { e.printStackTrace(); } return Response.created(location).build(); The location header that i get in response on my browser/postman is : base-path-to-my-webapp/example while i am expecting base-path-to-my-web-app/current-path/example I tried to look for the issue online. I got https://java.net/jira/browse/JERSEY-2838 which says that the issue is resolved, and if we POST to current-path/(with a trailing slash) we should get the correct

2022-05-03 05:59:18    分类:问答    java   jersey-2.0

JAX-RS (Jersey) and Jackson does not serialize LocalDate correctly

We recently upgraded to Spring Boot 2.0, and with that, JAX-RS at 2.1 and Jackson at 2.26. The issue now is that the Java object I'm trying to (serialize and) send via POST has a field of type java.time.LocalDate and it's not getting serialized (into JSON) correctly. This is the result after the updates: ... "birthDate": { "year": 1991, "month": "JANUARY", "chronology": { "id": "ISO", "calendarType": "iso8601" }, "monthValue": 1, "dayOfMonth": 1, "dayOfWeek": "TUESDAY", "era": "CE", "dayOfYear": 1, "leapYear": false }, ... ...instead, birthDate should be sent like "birthDate": "1991-01-01" —

2022-05-03 02:29:03    分类:问答    java   spring-boot   jackson   jersey-2.0   jersey-client

Jersey 2.32 IllegalArgumentException jersey.repackaged.org.objectweb.asm.ClassVisitor

I am trying to user Jersey's JSON/bean validation however error occurs when initing servlet occurs. Full stack trace: SEVERE: Servlet.init() for servlet [rest-servlet] threw exception java.lang.IllegalArgumentException at jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79) at jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:64) at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener$AnnotatedClassVisitor.<init>(AnnotationAcceptingListener.java:172) at org.glassfish.jersey.server.internal.scanning

2022-05-02 03:39:26    分类:问答    java   jersey   jersey-2.0

Servlet.service() for servlet [Jersey REST Service] java.lang.NullPointerException

can anyone help me work around with this one. This is my first time to create restful api. web.xml <display-name>1FxAll</display-name> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class> org.glassfish.jersey.servlet.ServletContainer </servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.sample.blitz</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping> UserController.java

2022-05-01 00:04:41    分类:问答    java   servlets   jersey-2.0

java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.create

Error: java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.create(Ljava/lang/String;Lorg/glassfish/hk2/api/ServiceLocator;Lorg/glassfish/hk2/extension/ServiceLocatorGenerator;Lorg/glassfish/hk2/api/ServiceLocatorFactory$CreatePolicy;)Lorg/glassfish/hk2/api/ServiceLocator; org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138) pom.xml <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.22.1</version> </dependency> web.xml <servlet> <servlet-name>jersey-serlvet</servlet-name

2022-04-28 04:24:14    分类:问答    java   maven   jersey-2.0   tomcat8

How does http connection pooling work in work in Jersey?

问题 这是我的代码。 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.JerseyClient; import org.glassfish.jersey.client.JerseyClientBuilder; public class Jersey2HttpClient { private static class InstanceHolder { private static final JerseyClient INSTANCE = createClient(); private static JerseyClient createClient() { ClientConfig clientConfig = new ClientConfig(); clientConfig.property(ClientProperties.READ_TIMEOUT, 20000); clientConfig.property

2022-04-26 20:21:13    分类:技术分享    java   jersey   jersey-2.0