Java InaccessibleWSDLException while accessing WSDL through client stubs

守給你的承諾、 提交于 2019-12-04 12:40:46

Why access the remote WSDL document file (and schema files) when you can have a local copy? Of course, security is still required to access the endpoint.

First, you need the class loader according to the environment.

// Java EE Enviroment
ClassLoader cl = Thread.currentThread().getContextClassLoader();

// Java Standalone Enviroment
ClassLoader cl = ClassLoader.getSystemClassLoader();

Next, store locally a copy of the WSDL document file (and the scheme files if needed) in your project.

URL wsdlLocation = cl.getResource("com/mahesha999/ExchangeWebService.wsdl");
QName qName = new QName(
    "http://schemas.microsoft.com/exchange/services/2006/messages", 
    "ExchangeWebService"
);

ExchangeWebService exchangeWebService = new ExchangeWebService(wsdlLocation, 
        qName);
ExchangeServicePortType port = exchangeWebService.getExchangeWebPort();

If authentication is required to access the webservice endpoint, in its most basic form, is as follows:

BindingProvider provider = (BindingProvider) port;
Map<String, Object> context = provider.getRequestContext();
context.put(BindingProvider.USERNAME_PROPERTY, username);
context.put(BindingProvider.PASSWORD_PROPERTY, password);

If you need to deal with certificates and that sort of thing, better have a look at Securing WebLogic Web Services.

Did you add username and password this way?

    ShopingCart sc = scs.getShopingCartPort();
    Map requestContext = ((BindingProvider)sc).getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, userName);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);

You have not given your client code in question. Are you using proxy? Then you have to give your proxy username and password in the above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!