0
로컬 웹 서비스 용 webservice-client를 작성하려고합니다. 내가 디버깅 (서버에서) 모든 괜찮아요 및 응답 메시지가 사실입니다 (내 개체). 또한 SOAP UI를 사용해 보았는데 문제가 없었습니다. 여기 UnmarshallingFailureException, 예기치 않은 요소 (uri : "http://schemas.xmlsoap.org/soap/envelope/", 로컬 : "오류")
내 appcontext.xml<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"
p:marshaller-ref="jaxbMarshaller"
p:checkConnectionForFault="false"
p:faultMessageResolver-ref="faultMessageResolver"
p:unmarshaller-ref="jaxbMarshaller"
p:defaultUri="http://localhost:8080/hesapsorgu/endpoints/sendAccountInformationService.wsdl"
p:messageSender-ref="messageSender">
<constructor-arg ref="messageFactory"/>
<property name="interceptors">
<list>
<ref local="wss4jSecurityInterceptor"/>
</list>
</property>
</bean>
<bean id="faultMessageResolver" class="tr.com.tnbkep.FaultMessageResolver"/>
<bean id="wss4jSecurityInterceptor"
class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<!-- The web service provider requires us to pass a timestamp,
username, and password -->
<property name="securementUsername" value="***" />
<property name="securementPassword" value="***" />
<!-- When the web service replies, it will send a timestamp,
username, and password as well. We want to verify that it is still
the same provider -->
<property name="securementPasswordType" value="PasswordText"/>
<property name="validationActions" value="UsernameToken"/>
<property name="validationCallbackHandler">
<!-- just for testing. for real use cases, use integration with spring security -->
<bean class="org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler">
<property name="users">
<props>
<prop key="ernie">bert</prop>
</props>
</property>
</bean>
</property>
</bean>
<bean id="messageSender" class="org.springframework.ws.transport.http.HttpUrlConnectionMessageSender"/>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<!-- Here we use the Jaxb2 marshaller to marshall and unmarshall our Java objects -->
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>tr.com.tnbkep.webservices.AccountInformationResponse</value>
<value>tr.com.tnbkep.webservices.AccountInformationCorporateRequest</value>
<value>tr.com.tnbkep.webservices.AccountInformationPersonalRequest</value>
<value>tr.com.tnbkep.webservices.SendAccountInformationResponse</value>
<value>tr.com.tnbkep.webservices.SendAccountInformationPersonalRequest</value>
<value>tr.com.tnbkep.webservices.SendAccountInformationCorporateRequest</value>
</list>
</property>
</bean>
입니다 그리고 여기 내 주요 클래스
public void marshalWithSoapActionHeader(SendAccountInformationPersonalRequest o) throws SOAPException {
SendAccountInformationResponse sendAccountInformationResponse = (SendAccountInformationResponse) webServiceTemplate.marshalSendAndReceive(o, new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) {
try {
SoapMessage soapMessage = (SoapMessage) message;
SoapHeader header = soapMessage.getSoapHeader();
StringSource headerSource = new StringSource("<wsse:Security 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\">\n" +
" <wsse:UsernameToken wsu:Id=\"UsernameToken-1\">\n" +
" <wsse:Username>user</wsse:Username>\n" +
" <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">***</wsse:Password> \n" +
" </wsse:UsernameToken>\n" +
" </wsse:Security>");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, header.getResult());
((SoapMessage) message).getSoapBody().getFault().getFaultDetail().getDetailEntries().next();
} catch (SoapFaultClientException sfce) {
// This indicates there's something wrong with our message
// For example a validation error
System.out.println(sfce.toString());
logger.error("We sent an invalid message", sfce);
// Add error to model
} catch (WebServiceFaultException e) {
System.out.println(e.toString());
logger.error("We sent an invalid message", e);
} catch (Exception e) {
// exception handling
}
}
});
System.out.println(sendAccountInformationResponse.getAccountInformationResponse().getMessage());
입니다하지만 난 내 WS-클라이언트를 실행할 때 내가 여기에이 오류를 얻고 나의 스택 트레이스
입니다Exception in thread "main" org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://tr/com/tnbkep/webservices}SendAccountInformationCorporateRequest>,<{http://tr/com/tnbkep/webservices}SendAccountInformationPersonalRequest>,<{http://tr/com/tnbkep/webservices}SendAccountInformationResponse>
at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:863)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:742)
at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)
at org.springframework.ws.client.core.WebServiceTemplate$3.extractData(WebServiceTemplate.java:409)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:598)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:539)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:386)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:380)
at tr.com.tnbkep.SendAndReceive.marshalWithSoapActionHeader(SendAndReceive.java:126)
at tr.com.tnbkep.SendAndReceive.main(SendAndReceive.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://tr/com/tnbkep/webservices}SendAccountInformationCorporateRequest>,<{http://tr/com/tnbkep/webservices}SendAccountInformationPersonalRequest>,<{http://tr/com/tnbkep/webservices}SendAccountInformationResponse>
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1048)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:483)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:465)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:229)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:309)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:292)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:127)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738)
... 13 more
아무도 도와 드릴 수 있습니까? 고맙습니다.
어떤 버전의 Spring-WS를 사용하고 있습니까? 스택 추적의 행 번호는 버전 번호가 없으면 쓸모가 없습니다. –
나는 한 걸음 물러서야한다고 생각합니다. 혼란스러운 여러 레이어를 추가 한 것처럼 보입니다. 우선, 모든 Spring WS 보안 컨텐츠를 제거 할 수 있습니까? 또한 p : checkConnectionForFault = "false"와 같은 사용자 정의를 제거하십시오. 대신 Spring WS가 기본적으로하는 것처럼 오류를 확인하려고합니다. spec 레벨의 SOAP 오류가있는 경우이를보고 싶습니다. 또한 p : faultMessageResolver-ref = "faultMessageResolver"가 있습니다. 나는 그것을 제거하고 움직이는 부분의 수를 줄이기 위해 Spring WS의 디폴트 폴트 핸들러를 사용할 것을 제안한다. 이러한 변화로 되돌아와 결과를 게시하십시오. – gregturn