我们可以使用针对Apache CXF webservice的jersey客户端吗?

时间:2013-11-01 12:56:25

标签: java rest cxf jersey-client

我们使用apache CXF提供REST服务。我们可以使用Jersey客户端来调用此服务。

有任何错误吗?

2 个答案:

答案 0 :(得分:1)

Web服务的想法是允许在hetrogenous系统之间进行通信。因此,无论使用何种框架来创建Web服务,您都应该能够使用任何客户端调用它,前提是客户端和服务器都符合JAX-RS规范。因此,在您的情况下,您应该能够使用jersey客户端调用使用Apache CFX开发的REST服务。因为这两个框架都遵循JAX-RS规范。

答案 1 :(得分:0)

如上所述,您甚至可以使用简单的Http客户端来使用REST服务。使用HTTP,您可以轻松执行GET,PUT,POST,DELETE 简单的http客户端示例供您参考

URL url = null;
        try {
            url = new URL(urlStr);
        } catch (MalformedURLException e) {
            throw new Exception("Malformed URL", e);
        }

    HttpURLConnection con = null;
    try {
        if (user != null && pass != null)
            Authenticator.setDefault(new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(user, pass
                            .toCharArray());
                }
            });
        // end of authentication test

        SSLUtilities.trustAllHostnames();
        SSLUtilities.trustAllHttpsCertificates();
        con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        con.setAllowUserInteraction(true);
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false);
        con.setRequestProperty("Content-Type", ConTypeGet);
        s_logger.debug("Execute GET request Content-Type: "
                + con.getRequestProperty("Content-Type"));
        s_logger.debug("URL:" + url);

        con.connect();
相关问题