Java InaccessibleWSDLException lors de l'accès WSDL via client talons
Je suis en train d'écrire personnalisé client Java pour les Services Web Exchange.
J'ai généré des stubs client à l'aide de wsimport
outil comme expliqué ici de l'EWS.fichier wsdl. Et maintenant, j'ai écrit un code qui utilise ces talons. Je suis arriver exception suivante:
Exception in thread "main" com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.io.IOException: Got Server returned HTTP response code: 401 for URL: https://host.domain.com/ews/Services.wsdl while opening stream from https://host.domain.com/ews/Services.wsdl
java.io.IOException: Got Server returned HTTP response code: 401 for URL: https://host.domain.com/ews/Services.wsdl?wsdl while opening stream from https://host.domain.com/ews/Services.wsdl?wsdl
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at com.microsoft.schemas.exchange.services._2006.messages.ExchangeWebService.<init>(ExchangeWebService.java:58)
at com.xyz.abc.EWSJavaAPI.ExchangeAuthenticator.getExchangeServicePort(ExchangeAuthenticator.java:33)
at com.xyz.abc.test.ExchangeDevelopmentTest.main(ExchangeDevelopmentTest.java:35)
Comme nous pouvons le voir ci-dessus ExchangeDevelopmentTest
est un client qui utilise une autre classe ExchangeAuthenticator
qui utilise à son tour généré stub client ExchangeWebService
. Mais dans la trace de la pile j'ai eu des erreurs provenant de Sources Inconnues sans doute Jdk Pots de.
La IOException
dit qu'il a obtenu HTTP response code: 401
, qui est de l'accès non autorisé. Mais j'ai bien spécifié le nom d'utilisateur et mot de passe et aussi ont compris le besoin de certificat dans le keystore. Je suis totalement d'indécision où cette exception.
Code des classes, j'ai écrit:
ExchangeAuthenticator
public class ExchangeAuthenticator {
/**
* Obtains an authenticated ExchangeServicePortType with given credentials.
*
*/
public ExchangeServicePortType getExchangeServicePort(String username, String password, String domain, URL wsdlURL) throws MalformedURLException {
//Concatinate our domain and username for the UID needed in authentication.
String uid = "domain" + "\\" + "uname";
//Create an ExchangeWebService object that uses the supplied WSDL file, wsdlURL.
ExchangeWebService exchangeWebService = new ExchangeWebService(wsdlURL, new QName("<a href=\"http://schemas.microsoft.com/exchange/services/2006/messages\">http://schemas.microsoft.com/exchange/services/2006/messages</a>", "ExchangeWebService"));
ExchangeServicePortType port = exchangeWebService.getExchangeWebPort();
//Supply your username and password when the ExchangeServicePortType is used for binding in the SOAP request.
((BindingProvider)port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, uid);
((BindingProvider)port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
return port;
}
}
ExchangeDevelopmentTest
public class ExchangeDevelopmentTest {
public static void main (String[] args) {
ExchangeAuthenticator exchangeAuthenticator = new ExchangeAuthenticator();
//Print statement so we can easily see where our statements start in the Java console.
System.out.println("Let's get started!");
try {
//Create a URL object which points at the .wsdl we deployed in the previous step.
URL wsdlURL = new URL("https://172.17.245.196/ews/Services.wsdl");
//URL wsdlURL = new URL("<a href=\"https://172.17.245.196/ews/Services.wsdl\">https://172.17.245.196/ews/Services.wsdl</a>");
//Call to the class we just created to return an ExchangeServicePortType with authentication credentials.
ExchangeServicePortType port = exchangeAuthenticator.getExchangeServicePort("uname", "password@123", "domain", wsdlURL);
//Prints out the default toString() for the ExchangeServicePortType.
System.out.println(port.toString());
} catch (MalformedURLException ex) {
//Catch any errors that may occur.
Logger.getLogger(ExchangeDevelopmentTest.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ex.getMessage()+"\n"+ex.getStackTrace());
}
}
}
ExchangeWebService
Généré par JAX-WS avec wsimport
outil, d'autres constructeurs et méthodes supprimé. Seul constructeur à la ligne 58, qui appelle super
(ici Service
classe) constructeur est tenu.
@WebServiceClient(name = "ExchangeWebService", targetNamespace = "http://schemas.microsoft.com/exchange/services/2006/messages", wsdlLocation = "file:/C:/Services.wsdl")
public class ExchangeWebService extends Service
{
private final static URL EXCHANGEWEBSERVICE_WSDL_LOCATION;
private final static WebServiceException EXCHANGEWEBSERVICE_EXCEPTION;
private final static QName EXCHANGEWEBSERVICE_QNAME = new QName("http://schemas.microsoft.com/exchange/services/2006/messages", "ExchangeWebService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/C:/workspace/Server%20files/Client%20files/Services.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
EXCHANGEWEBSERVICE_WSDL_LOCATION = url;
EXCHANGEWEBSERVICE_EXCEPTION = e;
}
//other constructos & methods removed
//line 58
public ExchangeWebService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
}
OriginalL'auteur Mahesha999 | 2013-10-08
Vous devez vous connecter pour publier un commentaire.
Pourquoi accès distant document WSDL fichier (fichiers de schéma) quand vous pouvez avoir un copie locale? Bien sûr, la sécurité est toujours requis pour accéder à l'ordinateur d'extrémité.
Tout d'abord, vous avez besoin du chargeur de classe en fonction de l'environnement.
Prochaine, stocker localement une copie du document WSDL fichier (et le système de fichiers si nécessaire) dans votre projet.
Si l'authentification est requise pour accéder au webservice de point de terminaison, dans sa forme la plus basique, est comme suit:
Si vous avez besoin de traiter avec des certificats et ce genre de chose, il vaut mieux avoir un coup d'oeil à la Sécurisation de WebLogic Services Web.
OriginalL'auteur Paul Vargas
Avez-vous ajouter un nom d'utilisateur et le mot de passe de cette façon?
Vous n'avez pas donné votre code client en question. Êtes-vous en utilisant un proxy? Ensuite, vous avez à donner votre proxy nom d'utilisateur et mot de passe ci-dessus.
ExchangeDevelopmentTest
contient lesmain()
. Et dansExchangeAuthenticator
à la ligneExchangeWebService exchangeWebService...
je suis une Exception. Cette ligne simplement en appelant l'un des constructeur deExchangeWebService
classe (généré parwsimport
outil) qui à son tour appellesuper
(iciService
classe) constructeur. Alors que le débogage je ne peux pas obtenir dans la source de cette classe (évidemment).Dans ce constructeur pour le deuxième paramètre utiliser QName comment code généré automatiquement.
new QName("http://schemas.microsoft.com/exchange/services/2006/messages", "ExchangeWebService")
OriginalL'auteur Satish