[英]javax.xml.ws.WebServiceException: Failed to access the WSDL
[英]javax.xml.ws.WebServiceException: Failed to access the WSDL. Response: '401: Unauthorized'
我正在嘗試訪問我正在處理的項目的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)
........
我閱讀了很多關於問題的帖子,我嘗試了不同類型的auth。 我嘗試在不同的用例中使用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
我在Weblogic中遇到了同樣的問題。 我可以向你確認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);
}
}
}
我沒有在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有不同之處。 這應該工作。
以下是可以解決您的問題的建議:
1)更改WEBLOGIC腳本setDomainEnv.sh以強制WEBLOGIC使用SunHttpHandler
。
要么
2)使用shell腳本/批處理文件從命令提示符調用webservice。
要么
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());
要么
4)編寫自己的sun http處理程序。
要么
5)嘗試通過在其中添加新創建的Web服務來更新weblogic-webservice.xml。
要么
6)嘗試使用jax-rpc而不是jax-ws。
希望前兩個中的任何一個都能解決您的問題,但其他選項也很有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.