簡體   English   中英

我們可以將jersey客戶端用於Apache CXF Web服務嗎?

[英]can we use jersey client for Apache CXF webservice?

我們有一個使用apache CXF的REST服務。 我們可以使用Jersey客戶端調用此服務嗎?

有沒有錯

Web服務的思想是允許異構系統之間的通信。 因此,無論使用什么框架來創建Web服務,只要客戶端和服務器都符合JAX-RS規范,您都應該能夠使用任何客戶端來調用它。 因此,在您的情況下,您應該能夠使用球衣客戶端調用使用Apache CFX開發的REST服務。 由於這兩個框架都遵循JAX-RS規范。

如上所述,您甚至可以使用簡單的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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM