2

作業中のプロジェクトのWebサービスにアクセスしようとしています。JAX-WSを使用しており、アプリはweblogicにデプロイされています。WSにアクセスしようとすると、次の例外が発生します。

javax.portlet.PortletException: javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://xxx.xxxx.ro:40000/idm/ws/cup?wsdl. It failed with: 
Response: '401: Unauthorized' for url: 'http://xxx.xxxx.ro:40000/idm/ws/cup?wsdl'.
at com.bea.portlet.container.PortletStub.processAction(PortletStub.java:346)
at com.bea.portlet.container.AppContainer.invokeProcessAction(AppContainer.java:678)
........

問題に関する多くの投稿を読み、さまざまな種類の認証を試しました。BindingProvider、basicHTTPAuthをさまざまなユースケースで使用し、HostnameVerifierを無効にしようとしましたが、それでも結果が得られませんでした。

以下は、最後に試したバージョンとしての私のコードの抜粋です。

Authenticator.setDefault(new Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                            username,
                            password.toCharArray());
                    }
                });


    ComputeUserProfileImplService computeUserProfileImplService = new ComputeUserProfileImplService(
    new URL(null, endpointURL, new sun.net.www.protocol.http.Handler()),
    new QName("http://xxx.xx.xxxxx.xxxxx.com/",
            "ComputeUserProfileImplService"));
    ComputeUserProfileImpl computeUserProfile = computeUserProfileImplService
    .getComputeUserProfileImplPort();

ComputeUserProfileImplServiceコードは次のようになります。

private final static URL COMPUTEUSERPROFILEIMPLSERVICE_WSDL_LOCATION;
private final static Logger logger = Logger.getLogger(com.xxxxx.xxxxx.xx.xxxxx.cup.ComputeUserProfileImplService.class.getName());

static {
    URL url = null;
    try {
        URL baseUrl;
        baseUrl = com.xxxxx.xxxxx.xx.xxxxx.xxx.ComputeUserProfileImplService.class.getResource("");
        url = new URL(baseUrl, "http://xxxx.xxxxx.ro:40000/idm/ws/cup?wsdl");

    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'xxxxxxxxxxxxxxxx', retrying as a local file");
        logger.warning(e.getMessage());
    }
    COMPUTEUSERPROFILEIMPLSERVICE_WSDL_LOCATION = url;
}

リンクを置き換えて申し訳ありませんが、それはかなり有名な組織であるため、私はそれらを投稿する権限がありません。いくつかの提案で私を助けることができれば、私は感謝します。私は解決策を探し続けていますが、行き詰まっています..私はそれを理解することができません。これは、私に当てはまるこのweblogicの問題の回避策になるはずです...しかし、私はそれを見つけることができません。必要に応じて、他のスニペットを投稿します。私がこれでかなり明確だったことを願っています。

前もって感謝します !!

4

4 に答える 4

5

残念ながら、Weblogic には別のアプローチがあり、何らかの理由で認証を無視する独自の URLStreamHandler を使用しています。

Sun の実装を使用してみてください。

それ以外の

 url = new URL(address); // use WebLogic handler

使用する

 url = new URL(null, address, new sun.net.www.protocol.http.Handler()); // use Sun's handler
于 2012-09-11T08:58:58.693 に答える
4

Weblogicでも同じ問題が発生しました。PauliusMatulionisによって提案されたソリューションがWeblogic11で機能したことを確認できます。

import my.MyPortType;

import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import javax.xml.ws.handler.MessageContext;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyWebServiceClient {

    public static void main(String[] args) {
        URL url = null;
        try {
            url = new URL("http://host:10001/mycontext/ws?WSDL");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        try {
            final String username = "some";
            final String password = "other";
            Authenticator.setDefault(new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(
                            username,
                            password.toCharArray());
                }
            });
            QName qname = new QName("http://whatevertheqname/", "whatevertheservicename");
            Service service = Service.create(url, qname);
            MyPortType proxy = service.getPort(MyPortType.class);
            Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext();
            requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());
            requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
            Map<String, List<String>> headers = new HashMap<String, List<String>>();
            headers.put("Timeout", Collections.singletonList("10000"));
            requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
            String result = proxy.myMethod23");

            System.out.println("Result is: " + result);

        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Error occurred in operations web service client initialization", e);
        }


    }
}
于 2012-10-29T18:50:37.773 に答える
2

WebLogicではこれを試しませんでしたが、Tomcat、Glassfish、Apache Karafでは、基本認証を必要とするWebサービスへのcliet呼び出しがうまく機能します。

/**
 * Proxy.
 */
private OperationsService proxy;

/**
 * Operations wrapper constructor.
 *
 * @throws SystemException if error occurs
 */
public OperationsWrapper()
        throws SystemException {
    try {
        final String username = getBundle().getString("wswrappers.operations.username");
        final String password = getBundle().getString("wswrappers.operations.password");
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                        username,
                        password.toCharArray());
            }
        });
        URL url = new URL(getBundle().getString("wswrappers.operations.url"));
        QName qname = new QName("http://hltech.lt/ws/operations", "Operations");
        Service service = Service.create(url, qname);
        proxy = service.getPort(OperationsService.class);
        Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("Timeout", Collections.singletonList(getBundle().getString("wswrappers.operations.timeout")));
        requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    } catch (Exception e) {
        LOGGER.error("Error occurred in operations web service client initialization", e);
        throw new SystemException("Error occurred in operations web service client initialization", e);
    }
}

WebLogicに何か違いがあるとは思いません。これは機能するはずです。

于 2012-08-11T12:50:39.033 に答える
0

以下は、問題を解決するための提案です。

1) WEBLOGIC スクリプト setDomainEnv.sh を変更して、WEBLOGIC を強制的に使用させますSunHttpHandler

また

2) シェル スクリプト/バッチ ファイルを使用して、コマンド プロンプトから Web サービスを呼び出します。

また

3) Web サービスでこの URL オブジェクトを試してくださいnew URL(null, "http://...", new sun.net.www.protocol.http.Handler());

また

4) 独自の sun http ハンドラを作成します。

また

5) 新しく作成した Web サービスを追加して、weblogic-webservice.xml を更新してみてください。

また

6) jax-ws の代わりに jax-rpc を使用してみてください。

最初の 2 つのいずれかで問題が解決することを願っていますが、他のオプションも役に立ちます。

于 2015-08-11T13:07:26.037 に答える