Client client = ClientBuilder.newClient(); WebTarget target=client.target(url) Invocation.Builder builder = target.request(); String result = builder.get(String.Class);
サーブレットへの接続で以下のようなエラーが出ます。
javax.ws.rs.ProcessingException: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family; at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:261) at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:228) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444) at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420) at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
ググってみて原因はおそらくpom.xmlに記述している
jsr311-apiだと推測しました。
pom.xml
<dependencies> <!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.19.1</version> </dependency> --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-bundle</artifactId> <version>1.19.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.19.2</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19.1</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.23.1</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.23.1</version> </dependency> <dependency> <groupId>org.jboss</groupId> <artifactId>jnpserver</artifactId> <version>4.2.2.GA</version> </dependency> <dependency> <groupId>jboss</groupId> <artifactId>jnp-client</artifactId> <version>4.2.2.GA</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.9</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.7</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-jaxrs</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-xc</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> <version>1.3.7</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.2</version> </dependency> <dependency> <groupId>net.arnx</groupId> <artifactId>jsonic</artifactId> <version>1.3.9</version> </dependency> <dependency> <groupId>org.jboss</groupId> <artifactId>jboss-common-core</artifactId> <version>2.5.0.Final</version> </dependency> <dependency> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> <version>1.0-2</version> </dependency> <exclusions> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.1.1</version> </dependency> </exclusions> </dependencies>
jersey関係のjarでjsr311-apiを使ってるものがあり、それもまとめてコメントアウトしようとしたのですが、別のクラスでjersey関係のjarを使っており、
コメントアウトするとそちらでコンパイルエラーが起きるという状況になっています。
(以下該当クラスのメソッド)
@SuppressWarnings("finally") public <E> E sendRequest(String uri,String method,Object requestEntity,Class<E> cls,HashMap<String,String> header){ RestClient restClient=new RestClient(); Client client=restClient.getClient(); ClientRequest.Builder builder=ClientRequest.create(); builder.type(MediaType.APPLICATION_JSON_TYPE); if(requestEntity!=null){ builder.entity(JSON.encode(requestEntity)); } for(Map.Entry<String, String> entry : header.entrySet()) { builder.header(entry.getKey(), entry.getValue()); } ClientRequest request; ClientResponse response = null; E json = null; try { request = builder.build(new URI(uri), method); response=client.handle(request); json=response.getEntity(cls); }catch (URISyntaxException e) { e.printStackTrace(); }catch(Throwable e){ e.printStackTrace(); }finally{ return json; } } }
何かよい解決策があればご教授ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。