使用reast-easy调用rest服务时出现运行时异常

时间:2019-06-24 11:41:05

标签: java spring rest resteasy

应用程序是带有EJB绑定和WAS 7部署的Spring 3.1.0。

尝试使用具有以下实现的resteasy-jaxrs和jaxrs-api jar调用Rest Service端点。但是无法调用端点,出现如下所示的RunTimeException:

  

java.lang.RuntimeException:java.lang.ClassNotFoundException:   com.sun.ws.rs.ext.RuntimeDelegateImpl

     

原因:java.lang.ClassNotFoundException:   com.sun.ws.rs.ext.RuntimeDelegateImpl

pom中使用的依赖项是

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

呼叫休息端点的代码:

DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpParams params = httpClient.getParams();
            String serviceTimeout = "180000";
            HttpConnectionParams.setConnectionTimeout(params, 
Integer.parseInt(serviceTimeout));
            HttpConnectionParams.setSoTimeout(params, 
Integer.parseInt(serviceTimeout));
            ClientExecutor clientExecutor = new 
ApacheHttpClient4Executor(httpClient);
           ClientRequest clientRequest = new ClientRequest("url", 
clientExecutor);
            clientRequest.body(MediaType.APPLICATION_XML, xml);
            logger.debug("Sending request :");
            ClientResponse<String> clientResponse = 
clientRequest.post(String.class);

任何人都可以就上述问题提出建议。

1 个答案:

答案 0 :(得分:0)

RuntimeDelegateImpl是resteasy-client软件包的一部分。您需要在pom.xml

中声明对resteasy-client的依赖
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
</dependency>