I cannot set FaultCode.RECEIVER for my fault message;
The code in response is always SERVER
Here is my response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">Something wrong!</faultstring>
<faultactor>http://fault.actor.com/actor/</faultactor>
<detail>
<ServiceException>
<code>ABCD</code>
<message>Invalid input</message>
</ServiceException>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The fault code is SOAP-ENV:Server instead of SOAP-ENV:Receiver
Heres my exception class
#SoapFault(faultCode = FaultCode.RECEIVER, faultStringOrReason = "Something wrong!")
public class CustomFault extends RuntimeException
When i'm putting faultCode = FaultCode.CLIENT, it changes in response to Client, but with RECEIVER doesn't work.
For adding fault details in response i'm using SoapFaultAnnotationExceptionResolver
Any ideas?
Related
How to add namespace in both Parent and Child element using Spring Boot & SOAP xml.
Expected:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SubmitXmlSyncResponse xmlns="http://www.w3.org/2001/XMLSchema-instance">
<BlueStar MsgName="B05" RqUid="b520981a-1912-4a4f-b882-9f709b248be2"
xmlns="http://www.w3.org/2001/XMLSchema-instance" Status="0">
<response/>
<FMHLEN>03</FMHLEN>
<PTION>00</PTION>
<LOGICALDEV>00</LOGICALDEV>
</BlueStar>
</SubmitXmlSyncResponse>
</soap:Body>
</soap:Envelope>
Actual:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xsd="http://www.w3.org/2001/XMLSchema"
<soap:Body>
<SubmitXmlSyncResponse xmlns="http://www.w3.org/2001/XMLSchema-instance">
<BlueStar MsgName="B05" RqUid="b520981a-1912-4a4f-b882-9f709b248be2" Status="0">
<response/>
<FMHLEN>03</FMHLEN>
<PTION>00</PTION>
<LOGICALDEV>00</LOGICALDEV>
</BlueStar>
</SubmitXmlSyncResponse>
</soap:Body>
</soap:Envelope>
Need xmlns in both SubmitXmlSyncResponse & BlueStar
I am working on spring boot soap-ws project with contract last approach using CXF. I have xml request from a client as below.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<teen xmlns="some url">
<!--Optional:-->
<arg0>
//DATA
</arg0>
</teen>
</soapenv:Body>
</soapenv:Envelope>
The service is not accepting the above request. I would like to change the xml request to below(service accepts below message). The arg0 should have an added empty namespace.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:se>
<soapenv:Header/>
<soapenv:Body>
<teen xmlns="some url">
<!--Optional:-->
<arg0 xmlns="">
//DATA
</arg0>
</teen>
</soapenv:Body>
</soapenv:Envelope>
Can someone help me on how I can achieve this?
I did some research and here is the answer. I have created a below class and implemented the handlemethod of extended class. The handlemethod does all the xml modification.
public class InvalidCharInterceptor extends AbstractPhaseInterceptor<Message> {
public InvalidCharInterceptor() {
super(Phase.RECEIVE); // This is important which determines at what point are we modifying the xml.
}
public void handleMessage(Message message) throws Fault {
}
}
And, then I added the new interceptor class in my webserviceconfig class.
EndpointImpl endpoint = new EndpointImpl(bus, "service-class-name");
endpoint.getInInterceptors().add(new InvalidCharInterceptor());
FYI..Apache cxf has detailed explanation on interceptors. https://cxf.apache.org/docs/interceptors.html
I am creating a soap web service using jaxb2 plugin. Hence I have generated jaxb classes from wsdl file. I have entered the sample of generated codes here.
//ObjectFactory.java
#XmlElementDecl(namespace = "http://xxxxx/", name = "InquiryResponse")
public JAXBElement<InquiryResponse> createInquiryResponse(InquiryResponse value) {
return new JAXBElement<InquiryResponse>(_InquiryResponse_QNAME, InquiryResponse.class, null, value);
}
//package-info.java
#javax.xml.bind.annotation.XmlSchema(namespace = "http://XXXX/",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED,
xmlns = {
#XmlNs(namespaceURI = "http://XXXX/", prefix = "ws")
})
package X.X.X;
import javax.xml.bind.annotation.XmlNs;
And the response is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<InquiryResponse xmlns:ws="http://XXXX/">
<InquiryResponse>
<refId>0004440</refId>
<status>UP</status>
</InquiryResponse>
</InquiryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But what I wanted is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ws:InquiryResponse xmlns:ws="http://XXXX/">
<InquiryResponse>
<refId>0004440</refId>
<status>UP</status>
</InquiryResponse>
</InquiryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am using a spring boot. Please help me. Thanks.
I believe that happens because you specified elementFormDefault as UNQUALIFIED in your package-info.java. Try switching this to QUALIFIED to see if it helps.
When I get SAML Assertion from Identity Server, DigestValue and SignatureValue are empty :\
Assertion:
<?xml version="1.0" encoding="UTF-8"?><saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="lhgklipdcdifghfbehlmdbbghndlgdpbdeggppjd" IssueInstant="2016-12-28T10:22:35.668Z" Version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"><saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">localhost</saml2:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#lhgklipdcdifghfbehlmdbbghndlgdpbdeggppjd"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="xs"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue/></ds:Reference></ds:SignedInfo><ds:SignatureValue/><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICNTCCAZ6gAwIBAgIES343gjANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxDTALBgNVBAoMBFdTTzIxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xMDAyMTkwNzAyMjZaFw0zNTAyMTMwNzAyMjZaMFUxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzENMAsGA1UECgwEV1NPMjESMBAGA1UEAwwJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCUp/oV1vWc8/TkQSiAvTousMzOM4asB2iltr2QKozni5aVFu818MpOLZIr8LMnTzWllJvvaA5RAAdpbECb+48FjbBe0hseUdN5HpwvnH/DW8ZccGvk53I6Orq7hLCv1ZHtuOCokghz/ATrhyPq+QktMfXnRS4HrKGJTzxaCcU7OQIDAQABoxIwEDAOBgNVHQ8BAf8EBAMCBPAwDQYJKoZIhvcNAQEFBQADgYEAW5wPR7cr1LAdq+IrR44iQlRG5ITCZXY9hI0PygLP2rHANh+PYfTmxbuOnykNGyhM6FjFLbW2uZHQTY1jMrPprjOrmyK5sjJRO4d1DeGHT/YnIjs9JogRKv4XHECwLtIVdAbIdWHEtVZJyMSktcyysFcvuhPQK8Qc/E/Wq8uHSCo=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">admin#carbon.super</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml2:SubjectConfirmationData InResponseTo="a4feh03406aeih7f2g73aaai048a3f1" NotOnOrAfter="2016-12-28T10:27:35.663Z" Recipient="http://localhost:22222/console/saml/SSO"/></saml2:SubjectConfirmation><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml2:SubjectConfirmationData InResponseTo="a4feh03406aeih7f2g73aaai048a3f1" NotOnOrAfter="2016-12-28T10:27:35.663Z" Recipient="https://192.168.100.120:9443/oauth2/token"/></saml2:SubjectConfirmation></saml2:Subject><saml2:Conditions NotBefore="2016-12-28T10:22:35.668Z" NotOnOrAfter="2016-12-28T10:27:35.663Z"><saml2:AudienceRestriction><saml2:Audience>onGeoConsoleTest2</saml2:Audience><saml2:Audience>https://192.168.100.120:9443/oauth2/token</saml2:Audience></saml2:AudienceRestriction></saml2:Conditions><saml2:AuthnStatement AuthnInstant="2016-12-28T10:22:35.676Z" SessionIndex="5d427a5b-9392-47f8-84a8-8faf5a2fc029"><saml2:AuthnContext><saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml2:AuthnContextClassRef></saml2:AuthnContext></saml2:AuthnStatement><saml2:AttributeStatement><saml2:Attribute Name="role" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Internal/subscriber</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Application/ongeo-auth</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Application/api-store</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Internal/everyone</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">admin</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Application/api-publisher</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Application/ongeo-console</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Internal/cg_unpublisher</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Application/admin_Testujemy_PRODUCTION</saml2:AttributeValue><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Internal/cg_publisher</saml2:AttributeValue></saml2:Attribute></saml2:AttributeStatement></saml2:Assertion>
Service Provider configuration:
Please, help!
Problem was on Spring SAML extension side. Signature have been deleted from assertion in WebSSOProfileConsumerImpl in method processAuthenticationResponse, but when I set property releaseDOM to false it is working fine.
I am developing a SOAP webservice application written in Spring soap webservice
The application simply returns the same object it receives from the client as response.
In CountryEndpoint.java
#PayloadRoot(namespace = "http://xml.dexter.com/Country", localPart = "CountryLocalPart")
public Country getCountry(SoapHeader soapHeader, #RequestPayload Country request, #SoapHeader(value = "MessageHeader") SoapHeaderElement messageHeader, MessageContext messageContext) {
System.out.println("THE REQUEST: "+request);
return request;
}
The request SOAP XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns2:Country xmlns="http://example.org" xmlns:ns2="http://xml.dexter.org/Country" xmlns:h="http://pqr.com/pqr.xsd xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<ns2:countryName>Spain</ns2:countryName>
<ns2:population>1213123</ns2:population>
</ns2:Country>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The response SOAP XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns2:Country xmlns:ns2="http://xml.dexter.com/Country">
<ns2:countryName>Spain</ns2:countryName>
<ns2:population>1213123</ns2:population>
</ns2:Country>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The Country XML Root element seems to have the xmlns attributes missing.
This fails the JAXB unmarshalling step in the client.
The error is
ERROR: org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].
[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in
context with path [] threw exception [Request processing failed; nested
exception is org.springframework.oxm.UnmarshallingFailureException: JAXB
unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException:
unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/",
local:"Header"). Expected elements are <{http://www.....}Country>,<{http:
//www.....}Category>,<{http://www.....}SomeOther>] with root cause
javax.xml.bind.UnmarshalException: unexpected element
(uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Header"). Expected
elements are ...
I tried adding #PayloadRoots and also #Namespaces with array of #Namespace but nothing worked.
Is there a way I could have the response SOAP xml same as request SOAP xml?
Thanks!
The namespace URIs in the Country element on the request with the prefixes h, s, and default are superfluous as they don't correspond to any XML elements or attributes. There would be no reason to send them on the response and they would impact JAXB's ability to unmarshal the result assuming everything is properly mapped.
Based on your exception. Your JAXB client is trying to unmarshal the Header element and you need to unmarshal the Country element.