【问题标题】:error while consuming a RestFul WebService使用 RestFul WebService 时出错
【发布时间】:2014-03-08 09:23:10
【问题描述】:

我已经创建了一个网络服务 -

@Path("/info")
public class RestFulService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPlain()
{
    return " Web Service created";
}
}

当我通过 localhost 访问时,浏览器正在呈现 - “Web Service created”。

但是当我尝试通过不同的应用程序使用此 Web 服务时,我收到 404 错误代码 - “线程“主”java.lang.RuntimeException 中的异常:失败:HTTP 错误代码:404 在 RestConsumer.main(RestConsumer.java:28) "

RestConsumer.java 中的代码 -

 public static void main(String[] args) {
    try {
        String uri = "http://localhost:8080/RestFul/rest/info";
        URL url = new URL(uri);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", MediaType.TEXT_PLAIN);
        conn.connect();
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(
                (conn.getInputStream())));
        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }
        conn.disconnect();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

任何人都可以建议所需的更改。

【问题讨论】:

    标签: web-services


    【解决方案1】:

    这是Eclipse EE中的一个基本设置问题,参考这个Youtube链接在6:54

    它提供了纠正相同问题的分步指南。希望对你有帮助tutorial

    【讨论】:

    • 我想你忘了添加链接
    猜你喜欢
    • 2013-04-20
    • 1970-01-01
    • 2015-04-30
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2015-12-29
    相关资源
    最近更新 更多