我知道关于Java的WSDL的Basic Authentication
有很多问题,我用Google搜索了许多解决方案,但似乎没有用。我有这个网络服务
@WebServiceClient(name = "WSMrrtService", targetNamespace = "http://www.asycuda.org", wsdlLocation = "http://www.linktowsdl.com?wsdl")
public class WSMrrtService
extends Service
{
private final static URL WSMRRTSERVICE_WSDL_LOCATION;
private final static WebServiceException WSMRRTSERVICE_EXCEPTION;
private final static QName WSMRRTSERVICE_QNAME = new QName("http://www.asycuda.org", "WSMrrtService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://www.linktowsdl.com/WSMrrt?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
WSMRRTSERVICE_WSDL_LOCATION = url;
WSMRRTSERVICE_EXCEPTION = e;
}
public WSMrrtService() {
super(__getWsdlLocation(), WSMRRTSERVICE_QNAME);
}
public WSMrrtService(WebServiceFeature... features) {
super(__getWsdlLocation(), WSMRRTSERVICE_QNAME, features);
}
public WSMrrtService(URL wsdlLocation) {
super(wsdlLocation, WSMRRTSERVICE_QNAME);
}
public WSMrrtService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, WSMRRTSERVICE_QNAME, features);
}
public WSMrrtService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public WSMrrtService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns WSMrrt
*/
@WebEndpoint(name = "WSMrrtServicePort")
public WSMrrt getWSMrrtServicePort() {
return super.getPort(new QName("http://www.asycuda.org", "WSMrrtServicePort"), WSMrrt.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns WSMrrt
*/
@WebEndpoint(name = "WSMrrtServicePort")
public WSMrrt getWSMrrtServicePort(WebServiceFeature... features) {
return super.getPort(new QName("http://www.asycuda.org", "WSMrrtServicePort"), WSMrrt.class, features);
}
private static URL __getWsdlLocation() {
if (WSMRRTSERVICE_EXCEPTION!= null) {
throw WSMRRTSERVICE_EXCEPTION;
}
return WSMRRTSERVICE_WSDL_LOCATION;
}
我这样称呼
private static MrrtResult mrrtStore_1(org.asycuda.MrrtInfo mrrtInfo) {
org.asycuda.WSMrrtService service = new org.asycuda.WSMrrtService();
org.asycuda.WSMrrt port = service.getWSMrrtServicePort();
return port.mrrtStore(mrrtInfo);
}
除了它总是会给我这个错误
Exception in thread "JavaFX Application Thread" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
所以我在网上尝试了很多解决方案,
private static MrrtResult mrrtStore(org.asycuda.MrrtInfo mrrtInfo) {
org.asycuda.WSMrrtService service = new org.asycuda.WSMrrtService();
org.asycuda.WSMrrt port = service.getWSMrrtServicePort();
/*Default Authentication
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myuser", "mypassword".toCharArray());
}
});
*/
//Header authentication
Map<String, List<String>> credentials = new HashMap<String,List<String>>();
credentials.put("username", Collections.singletonList("myuser"));
credentials.put("password", Collections.singletonList("mypassword"));
((BindingProvider)port).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, credentials);
/*
//JAX-WS Authentication
Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "myuser");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "mypassword");
*/
return port.mrrtStore(mrrtInfo);
}
我尝试了header authentication
,default authentication
和JAX-WS
身份验证,但似乎不起作用,它们都给了我相同的401 error
我什至尝试了SOAPUI
default Authentication
,但遇到了同样的错误,有人可以帮我弄清楚我要去哪里了吗?