wsimport를 사용하여 일부 JAX-WS 아티팩트를 작성했습니다. 다음은 내가 사용했던 wsimport 명령입니다.JAX-WS 및 WS-Addressing을 사용하여 SOAP 사용하기
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
이것은 효과가있는 것 같습니다. 적어도 나는 그랬다고 생각한다. wsimport는 많은 패키지와 공용 인터페이스를 만들었습니다. 이제 여기에 유효한 끝점이라고 생각하는 연결을 시도하는 방법에 대한 코드 조각이 있습니다.
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();
나는 사용자 이름과 암호를 설정하는 여러 가지 방법을 시도했지만 나는 항상 HTTP 전송 오류가 나타날 수 java.net.ConnectException : 연결 시간이 초과되었습니다 : 연결합니다. 나는 SoapUI에 뛰어 올라 WSDL이있는 새로운 프로젝트를 https://api.sendwordnow.com/webservices/v3/users.svc?wsdl에서 만들었습니다. https://api.sendwordnow.com/webservices/v3/Users.svc에게 요청을 제출할 수 있으며 적절한 인증과 WSS-Password Type 속성을 PasswordText로 설정하면 EchoAuthenticated를 성공적으로 호출 할 수 있습니다. 다음은 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>"
나는 wsa : Action, wsse : password Type 및 wsse : Nonce EncodingType이 누락 된 것 같습니다. 적어도 그것은 SoapUI 요청에 있었던 것입니다. 이 모든 잘못을 저지른 것처럼 느껴집니다. 분명히 누락 된 구성 요소가 필요하지만 실제로 구현하는 방법을 파악할 수 없습니다. 어떤 제안이라도 도움이 될 것입니다. 나는 약간의 인증 오류를받을 것이라고 생각했지만 나는 그 정도까지 얻을 수없는 것처럼 보였다.
UPDATE 1
내가 가까이 여부를이에 얻고 있는지 확실하지 않습니다. 이것은 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>
그리고 여기에 코드가 있습니다.
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");
나는 더 이상 시간 초과하지 오전하지만 난 지금이 오류가 발생하고있다.
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
wsa : action을 특정 URL로 설정해야합니까?