2017-03-29 1 views
1

J'ai utilisé wsimport pour créer des artefacts JAX-WS. Voici la commande wsimport que j'ai utilisée.Consommation de SOAP avec JAX-WS et adressage WS

wsimport -b "C:\temp\Customization.xml" -B-XautoNameResolution -d C:\temp -extension -J-Djavax.xml.accessExternalSchema=all -J-Djavax.xml.accessExternalDTD=all -keep -verbose -XadditionalHeaders -Xnocompile https://api.sendwordnow.com/webservices/v3/users.svc?wsdl 

Cela semble avoir fonctionné. Au moins, je pense que oui. wsimport a créé un certain nombre de paquets et même une interface publique. Maintenant, voici un code de comment j'essaie de me connecter à ce que je pense être un point de terminaison valide.

HttpTransportPipe.dump = true; 
Users users = new Users(); 
IUsers iUsers = users.getWSHttpBindingIUsers(); 
((BindingProvider)iUsers).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://api.sendwordnow.com/webservices/v3/Users.svc"); 
((BindingProvider)iUsers).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "somename"); 
((BindingProvider)iUsers).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "somepassword"); 
iUsers.echoAuthenticated("This is an echo test."); 
System.out.println(); 

J'ai essayé différentes façons de définir le nom d'utilisateur et mot de passe, mais je reçois toujours une erreur de transport HTTP: java.net.ConnectException: Connection timed out: connect. J'ai sauté à SoapUI et créé un nouveau projet avec le WSDL de https://api.sendwordnow.com/webservices/v3/users.svc?wsdl. Je peux soumettre une demande à https://api.sendwordnow.com/webservices/v3/Users.svc et avec l'authentification appropriée et la propriété Type de mot de passe WSS définie à PasswordText je peux réussir à appeler EchoAuthenticated. Voici la sortie de SoapUI.

Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "POST /webservices/v3/Users.svc HTTP/1.1[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Content-Type: application/soap+xml;charset=UTF-8;action="http://www.sendwordnow.com/contract/users/v3/IUsers/EchoAuthenticated"[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Authorization: Basic c2lyaXVzYXBpOnRlbXBvcmFyeTEyMw==[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Content-Length: 1224[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Host: api.sendwordnow.com[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "Connection: Keep-Alive[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "[\r][\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v3="http://www.sendwordnow.com/contract/users/v3">[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> " <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-838F7D896DB9148E2414907229483491"><wsse:Username>somename</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somepassword</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">QpJwiZjZex+3ikqVWZp+Yw==</wsse:Nonce><wsu:Created>2017-03-28T17:42:28.348Z</wsu:Created></wsse:UsernameToken></wsse:Security><wsa:Action>http://www.sendwordnow.com/contract/users/v3/IUsers/EchoAuthenticated</wsa:Action></soap:Header>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> " <soap:Body>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "  <v3:EchoAuthenticated>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "   <!--Optional:-->[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "   <v3:value>This is an echo test.</v3:value>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "  </v3:EchoAuthenticated>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> " </soap:Body>[\n]" 
Tue Mar 28 12:42:28 CDT 2017:DEBUG:>> "</soap:Envelope>" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "Content-Type: application/soap+xml; charset=utf-8[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "Server: Microsoft-IIS/8.5[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "Date: Tue, 28 Mar 2017 17:42:29 GMT[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "Content-Length: 887[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "[\r][\n]" 
Tue Mar 28 12:42:29 CDT 2017:DEBUG:<< "<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><a:Action s:mustUnderstand="1">http://www.sendwordnow.com/contract/users/v3/IUsers/EchoAuthenticatedResponse</a:Action><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2017-03-28T17:42:29.695Z</u:Created><u:Expires>2017-03-28T17:47:29.695Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><EchoAuthenticatedResponse xmlns="http://www.sendwordnow.com/contract/users/v3"><EchoAuthenticatedResult>This is the Users service answering back. The value you sent was: This is an echo test.</EchoAuthenticatedResult></EchoAuthenticatedResponse></s:Body></s:Envelope>" 

On dirait que je suis absent WSA: Action, wsse: mot de passe type et wsse: Nonce EncodingType. Au moins c'est ce qui était dans la requête SoapUI. J'ai l'impression que je vais à ce sujet tout faux. J'ai évidemment besoin de ces composants manquants mais je n'arrive pas à comprendre comment les implémenter réellement. Toute suggestion serait super utile. J'ai pensé que je recevrais une erreur d'authentification mais je n'arrive même pas à aller aussi loin.

MISE À JOUR 1

Je ne suis pas sûr si je reçois plus près ou non à ce sujet. C'est la requête SoapUI.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v3="http://www.sendwordnow.com/contract/users/v3"> 
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<wsse:Username> 
*********</wsse:Username> 
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"> 
**********</wsse:Password> 
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"> 
zhVqVXnkOsPCFRZolLSWtw==</wsse:Nonce> 
<wsu:Created> 
2017-03-29T14:05:54.820Z</wsu:Created> 
</wsse:UsernameToken> 
</wsse:Security> 
<wsa:Action> 
http://www.sendwordnow.com/contract/users/v3/IUsers/EchoAuthenticated 
</wsa:Action> 
</soap:Header> 
    <soap:Body> 
     <v3:EchoAuthenticated> 
     <v3:value> 
Test Message</v3:value> 
     </v3:EchoAuthenticated> 
    </soap:Body> 
</soap:Envelope> 

Et voici une coupure de code.

SOAPElement security = header.addChildElement("Security", "wsse", 
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); 
SOAPElement userToken = security.addChildElement("UsernameToken", "wsse"); 
userToken.addChildElement("Username", "wsse").addTextNode("someusername"); 
userToken.addChildElement("Password", "wsse").addTextNode("somepassword"); 
userToken.addChildElement("Nonce", "wsse").addTextNode("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); 
userToken.addChildElement("Password", "wsse").addTextNode("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); 
userToken.addChildElement("Action", "wsa"); 

Je ne suis plus temporisé mais je reçois maintenant cette erreur.

com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://www.sendwordnow.com/contract/users/v3}EchoAuthenticatedResponse but found: {http://www.sendwordnow.com/contract/users/v3}EchoAuthenticated 

Dois-je définir l'action wsa: sur une URL spécifique?

Répondre

0

Bien que ce n'était pas la seule pièce, c'était une pièce majeure du puzzle.

security.addAttribute(soapFactory.createName("S:mustUnderstand"),"1"); 

Je l'avais utilisé.

security.addAttribute(soapFactory.createName("SOAP:mustUnderstand"),"True"); 

Quelques autres changements avec la construction de l'arbre de l'élément WSSE et WSA ont été faites, mais que mustUnderstand était vraiment me cause un tas de chagrin. Tout va bien maintenant.