0

apache CXF を使用した REST サービスがあります。Jersey クライアントを使用してこのサービスを呼び出すことはできますか?

間違いはありませんか?

4

2 に答える 2

1

Web サービスの考え方は、異種システム間の通信を可能にすることです。そのため、Web サービスの作成に使用されるフレームワークに関係なく、クライアントとサーバーの両方が JAX-RS 仕様に準拠していれば、任意のクライアントを使用して呼び出すことができます。したがって、あなたの場合、ジャージークライアントを使用して、Apache CFX を使用して開発された REST サービスを呼び出すことができるはずです。どちらのフレームワークも JAX-RS 仕様に従っています。

于 2013-11-01T13:06:07.340 に答える
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();
于 2014-06-04T00:58:37.357 に答える