简体   繁体   English

javax.xml.ws.WebServiceException:无法访问WSDL。 回复:'401:未经授权'

[英]javax.xml.ws.WebServiceException: Failed to access the WSDL. Response: '401: Unauthorized'

I am trying to access a web service for a project i'm working on. 我正在尝试访问我正在处理的项目的Web服务。 I'm using JAX-WS and the app is deployed on weblogic. 我正在使用JAX-WS,应用程序部署在weblogic上。 When i'm trying to access the WS, i get the following exception: 当我试图访问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)
........

I read through a lot of posts regarding issue and i tried different types of auth. 我阅读了很多关于问题的帖子,我尝试了不同类型的auth。 I tried to use BindingProvider, basicHTTPAuth in different usecases, disable HostnameVerifier etc. but still with no result. 我尝试在不同的用例中使用BindingProvider,basicHTTPAuth,禁用HostnameVerifier等但仍然没有结果。

Below is a snippet of my code, as the last tried version: 以下是我的代码片段,作为最后一个尝试过的版本:

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();

The ComputeUserProfileImplService code looks like : 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;
}

Sorry for replacing the links, but i'm not authorised to post them since it's a pretty known organisation.. If you can help me with some suggestions, i will be grateful. 很抱歉更换链接,但我没有授权发布它们,因为它是一个非常着名的组织..如果你可以帮我提出一些建议,我将不胜感激。 I keep searching for solutions but i'm stuck.. i can't figure it out. 我一直在寻找解决方案,但我被卡住了......我无法弄明白。 It should be a workaround for this weblogic issue that applies to me... but i just can't find it. 它应该是适用于我的这个weblogic问题的解决方法......但我找不到它。 If you need it, i'll post some other snippets. 如果你需要它,我会发布一些其他的片段。 Hope i was pretty clear with this. 希望我对此很清楚。

Thanks in advance !! 提前致谢 !!

Unfortunately Weblogic has a different approach, it uses its own URLStreamHandler that for some reason ignores authentication. 不幸的是,Weblogic有一种不同的方法,它使用自己的URLStreamHandler,由于某种原因忽略了身份验证。

Try to use Sun's implementation: 尝试使用Sun的实现:

instead of 代替

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

use 采用

 url = new URL(null, address, new sun.net.www.protocol.http.Handler()); // use Sun's handler

I had the same issue in Weblogic. 我在Weblogic中遇到了同样的问题。 I can confirm for you that the solution suggested by Paulius Matulionis worked for me in Weblogic 11: 我可以向你确认Paulius Matulionis建议的解决方案在Weblogic 11中为我工作:

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);
        }


    }
}

I did no try this in WebLogic, but on Tomcat, Glassfish, Apache Karaf, the cliet call to web service which needs the basic authentication this works just great: 我没有在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);
    }
}

I do not think that WebLogic has something different. 我不认为WebLogic有不同之处。 This should work. 这应该工作。

The following are suggestions that could solve your issue: 以下是可以解决您的问题的建议:

1) Change in the WEBLOGIC script setDomainEnv.sh to force WEBLOGIC to use SunHttpHandler . 1)更改WEBLOGIC脚本setDomainEnv.sh以强制WEBLOGIC使用SunHttpHandler

or 要么

2) Call the webservice from the command prompt using a shell script/batch file. 2)使用shell脚本/批处理文件从命令提示符调用webservice。

or 要么

3) Try this url object in your webservice new URL(null, "http://...", new sun.net.www.protocol.http.Handler()); 3)在你的webservice new URL(null, "http://...", new sun.net.www.protocol.http.Handler());尝试这个url对象new URL(null, "http://...", new sun.net.www.protocol.http.Handler());

or 要么

4) Write your own sun http handler. 4)编写自己的sun http处理程序。

or 要么

5) Try updating your weblogic-webservice.xml by adding your newly created webservice in it. 5)尝试通过在其中添加新创建的Web服务来更新weblogic-webservice.xml。

or 要么

6) Try using jax-rpc instead of jax-ws. 6)尝试使用jax-rpc而不是jax-ws。

Hopefully any of the first two will resolve your issue, however the other options are also helpful. 希望前两个中的任何一个都能解决您的问题,但其他选项也很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.xml.ws.WebServiceException: 无法访问 WSDL - javax.xml.ws.WebServiceException: Failed to access the WSDL 调用 WSDL 服务时出现 javax.xml.ws.WebServiceException - javax.xml.ws.WebServiceException when invoking WSDL service javax.xml.ws.WebServiceException:找不到以wsdl命名的服务 - javax.xml.ws.WebServiceException: Could not find service named in wsdl 无法创建服务异常javax.xml.ws.WebServiceException: - Failed to create service exception javax.xml.ws.WebServiceException: javax.xml.ws.WebServiceException:不是有效的端口 - javax.xml.ws.WebServiceException: is not a valid port javax.xml.ws.WebServiceException:方法X暴露为WebMethod,但是没有对应的wsdl操作 - javax.xml.ws.WebServiceException: Method X is exposed as WebMethod, but there is no corresponding wsdl operation 出现CXF错误:javax.xml.ws.WebServiceException:WSDL元数据不可用于创建代理 - Getting CXF error: javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy javax.xml.ws.WebServiceException:未定义的端口类型Java Struts SOAP WSDL - javax.xml.ws.WebServiceException: Undefined port type Java Struts SOAP WSDL javax.xml.ws.WebServiceException:org.apache.cxf.service.factory.ServiceConstructionException:创建服务失败 - javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service “ javax.xml.ws.WebServiceException:不是有效的服务。”代理问题? - “javax.xml.ws.WebServiceException: is not a valid service.” proxy issue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM