javax.xml.ws.WebServiceException : Failed to access the WSDL. 响应: '401: Unauthorized'

标签 java wsdl weblogic jax-ws webservice-client

我正在尝试访问我正在处理的项目的网络服务。我正在使用 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 问题的解决方法...但我就是找不到它。如果你需要的话,我会发布一些其他的片段。希望我对此很清楚。

提前致谢!!

最佳答案

不幸的是,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

关于javax.xml.ws.WebServiceException : Failed to access the WSDL. 响应: '401: Unauthorized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11882360/

相关文章:

wcf - 从 WSDL 文件生成 C#.net 类

java - 如何创建简单的 WSDL?

java - com.bea.wli.config.deployment.server.ServerDeploymentConflictException:由于与正在进行的其他工作发生冲突,无法激活 session

java - Android向ArrayList添加数据时出错

java - 是否可以在没有 RoundTimeout 注解的情况下拦截超时方法?

java - Javascript 中的 GWT 自定义事件触发器

java - 带有自定义安全过滤器的 Spring Boot OAuth2

web-services - 关于 SSL 的概念混淆

java - Hibernate Weblogic 10.3.4 java.lang.NoSuchMethodError : javax/persistence/spi/PersistenceUnitInfo. getValidationMode()Ljavax/persistence/ValidationMode;

java - 从 Weblogic 迁移到 Apache Tomcat