use of org.springframework.ws.soap.SoapHeader in project camel by apache.
the class BasicMessageFilter method doProcessSoapHeader.
/**
* The SOAP header is populated from exchange.getOut().getHeaders() if this
* class is used by the consumer or exchange.getIn().getHeaders() if this
* class is used by the producer. If .getHeaders() contains under a certain
* key a value with the QName object, it is directly added as a new header
* element. If it contains only a String value, it is transformed into a
* header attribute. Following headers are excluded:
*/
protected void doProcessSoapHeader(Message inOrOut, SoapMessage soapMessage) {
SoapHeader soapHeader = soapMessage.getSoapHeader();
Map<String, Object> headers = inOrOut.getHeaders();
HashSet<String> headerKeySet = new HashSet<String>(headers.keySet());
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_CONSUMER_FAULT_ACTION);
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_CONSUMER_OUTPUT_ACTION);
// This gets repeated again in the below 'for loop' and gets added as attribute to soapenv:header.
// This would have already been processed in SpringWebserviceProducer/Consumer instance.
headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER);
// Replaced local constant 'BreadcrumbId' with the actual constant key in header 'breadcrumbId'
// from org.apache.camel.Exchange.BREADCRUMB_ID. Because of this case mismatch, this key never
// gets removed from header rather gets added to soapHeader all the time.
headerKeySet.remove(Exchange.BREADCRUMB_ID);
for (String name : headerKeySet) {
Object value = headers.get(name);
if (value instanceof QName) {
soapHeader.addHeaderElement((QName) value);
} else {
if (value instanceof String) {
soapHeader.addAttribute(new QName(name), value + "");
}
}
}
}
use of org.springframework.ws.soap.SoapHeader in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapper method populateUserDefinedHeader.
@Override
protected void populateUserDefinedHeader(String headerName, Object headerValue, SoapMessage target) {
SoapHeader soapHeader = target.getSoapHeader();
if (headerValue instanceof String) {
QName qname = QNameUtils.parseQNameString(headerName);
soapHeader.addAttribute(qname, (String) headerValue);
} else if (headerValue instanceof Source) {
Result result = soapHeader.getResult();
try {
this.transformerHelper.transform((Source) headerValue, result);
} catch (TransformerException e) {
throw new SoapHeaderException("Could not transform source [" + headerValue + "] to result [" + result + "]", e);
}
}
}
use of org.springframework.ws.soap.SoapHeader in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testCustomSoapHeader.
@Test
public void testCustomSoapHeader() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
mapper.setReplyHeaderNames("x:attr", "x:elem");
SoapMessage soapMessage = mock(SoapMessage.class);
SoapHeader soapHeader = mock(SoapHeader.class);
@SuppressWarnings("unchecked") Iterator<QName> attrIterator = mock(Iterator.class);
QName attribute = new QName("http://x", "attr", "x");
@SuppressWarnings("unchecked") Iterator<SoapHeaderElement> elementIterator = mock(Iterator.class);
SoapHeaderElement soapHeaderElement = mock(SoapHeaderElement.class);
QName element = new QName("http://x", "elem", "x");
when(soapMessage.getSoapHeader()).thenReturn(soapHeader);
when(soapHeader.getAllAttributes()).thenReturn(attrIterator);
when(attrIterator.hasNext()).thenReturn(true).thenReturn(false);
when(attrIterator.next()).thenReturn(attribute);
when(soapHeader.getAttributeValue(attribute)).thenReturn("attrValue");
when(soapHeader.examineAllHeaderElements()).thenReturn(elementIterator);
when(elementIterator.hasNext()).thenReturn(true).thenReturn(false);
when(elementIterator.next()).thenReturn(soapHeaderElement);
when(soapHeaderElement.getName()).thenReturn(element);
Map<String, Object> headers = mapper.toHeadersFromReply(soapMessage);
assertEquals(2, headers.size());
assertEquals("attrValue", headers.get("x:attr"));
assertSame(soapHeaderElement, headers.get("x:elem"));
}
use of org.springframework.ws.soap.SoapHeader in project camel by apache.
the class SpringWebserviceConsumer method extractSourceFromSoapHeader.
/**
* Extracts the SOAP headers and set them as headers in the Exchange. Also sets
* it as a header with the key SpringWebserviceConstants.SPRING_WS_SOAP_HEADER
* and a value of type Source.
*
* @param headers the Exchange Headers
* @param request the WebService Request
*/
private void extractSourceFromSoapHeader(Map<String, Object> headers, WebServiceMessage request) {
if (request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
SoapHeader soapHeader = soapMessage.getSoapHeader();
if (soapHeader != null) {
//Set the raw soap header as a header in the exchange.
headers.put(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader.getSource());
//Set header values for the soap header attributes
Iterator<QName> attIter = soapHeader.getAllAttributes();
while (attIter.hasNext()) {
QName name = attIter.next();
headers.put(name.getLocalPart(), soapHeader.getAttributeValue(name));
}
//Set header values for the soap header elements
Iterator<SoapHeaderElement> elementIter = soapHeader.examineAllHeaderElements();
while (elementIter.hasNext()) {
SoapHeaderElement element = elementIter.next();
QName name = element.getName();
headers.put(name.getLocalPart(), element);
}
}
}
}
use of org.springframework.ws.soap.SoapHeader in project webservices-axiom by apache.
the class TestCreateWebServiceMessage method runTest.
@Override
protected void runTest(SoapMessageFactory messageFactory) {
SoapMessage message = messageFactory.createWebServiceMessage();
SoapEnvelope env = message.getEnvelope();
assertNotNull(env);
assertEquals(spec.getEnvelopeQName(), env.getName());
SoapHeader header = env.getHeader();
assertNotNull(header);
assertEquals(spec.getHeaderQName(), header.getName());
SoapBody body = env.getBody();
assertNotNull(body);
assertEquals(spec.getHeaderQName(), header.getName());
}
Aggregations