简体   繁体   English

使用jersey创建Restful Web服务客户端

[英]Creating restful webservice client with jersey

I have the underlisted code to consume a restful webservice, but it always reports an error which is listed below as well. 我有下面列出的代码可以使用一个安静的Web服务,但是它始终报告以下列出的错误。 I have tried to using jersey api 1.8 and 1.9 but there isn't any effect. 我试图使用jersey api 1.8和1.9,但没有任何效果。

My Code: 我的代码:

public class JerseyClient {
    public static void main(String[] args) {
        Client client = Client.create(); // faulty line

        WebResource resource;

        resource = client.resource("http://localhost:8080/CustomerApp/webresources/entities.customer");

        String string = resource.path("1")
            .accept(MediaType.APPLICATION_XML)
            .get(String.class);
        System.out.println(string);
    }
}

Error: 错误:

Dec 28, 2012 8:17:06 AM com.sun.jersey.spi.inject.Errors processErrorMessages

Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException 
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) 
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) 
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) 
at com.sun.jersey.api.client.Client.(Client.java:187) at com.sun.jersey.api.client.Client.(Client.java:159) 
at com.sun.jersey.api.client.Client.create(Client.java:669) 
at client.JerseyClient.main(JerseyClient.java:20)

Get the Jersey client jar file, maven location for the jersey client is 获取Jersey客户端jar文件,该jersey客户端的maven位置为

<!-- language: lang-xml -->      
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.13-b01</version>
</dependency>

After this ensure your service running or not and run this client class, it will work well. 在此之后,请确保您的服务是否在运行,并运行此客户端类,它将运行良好。 You can find the tutorial for creating a restful web service here 您可以在此处找到创建静态Web服务的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM