Talend ESB: cxfws producer, POJO data format, how to set SOAP headers

Six Stars

Talend ESB: cxfws producer, POJO data format, how to set SOAP headers

Hi, 

 

I am using a CXFWS component to make a SOAP request. Below is my code to configure the component and set SOAP headers using Header.HEADER_LIST. 

Issue is that only the SOAP body is sent as part of the request, but not the CredentialsHeader. How can I send the CredentialsHeader header?

// CXF endpoint for cSOAP_1
		org.apache.camel.component.cxf.CxfEndpoint endpoint_cSOAP_1 = getCxfEndpoint(
				"cxf://"
						+ "https://api.stage.eventcore.com/ReportService.asmx"
						+ "?dataFormat=POJO"
						+ "&serviceClass="
						+ "tableau.ea.eventcore.api.reportservice.ReportServiceSoap"
						+ "&serviceName="
						+ "{https://api.eventcore.com/}ReportService"
						+ "&endpointName="
						+ "{https://api.eventcore.com/}ReportServiceSoap12"
						+ "&defaultOperationNamespace="
						+ javax.xml.namespace.QName.valueOf(
								"{https://api.eventcore.com/}GetReport")
								.getNamespaceURI()
						+ "&defaultOperationName="
						+ javax.xml.namespace.QName.valueOf(
								"{https://api.eventcore.com/}GetReport")
								.getLocalPart() + "&" + "loggingFeatureEnabled"
						+ "=" + "true" + "&" + "continuationTimeout" + "="
						+ 600000
						+ "&headerFilterStrategy=#CXF_PAYLOAD_HEADER_FILTER"
						+ "&properties.id=" + "cSOAP_1", false, false, false,
				(String[]) null);

from("timer:cTimer_1" + "?repeatCount=" + 1 + "&delay=" + 1000)
.routeId("ConferenceRegistrationSync_ECtoSFDC_cTimer_1")
.setHeader("SOAPAction")
.constant("https://api.eventcore.com/GetReport")
.setHeader("operationNamespace")
.constant("https://api.eventcore.com/")
.setHeader("relayHeaders")
.constant("true")
.setHeader("operationName")
.constant("GetReport")
.id("ConferenceRegistrationSync_ECtoSFDC_cSetHeader_1")
.process(new org.apache.camel.Processor() {
public void process(org.apache.camel.Exchange exchange)
throws Exception {
/*
* Provide own codes to consume or translate the message
* exchanges.
*
* @param org.apache.camel.Exchange exchange
*/

/*
* Provide own codes to consume or translate the message
* exchanges.
*
* @param org.apache.camel.Exchange exchange
*/
GetReport getReport = new GetReport();
getReport.setReportID(111);
getReport.setSortColumn("LastModified");
getReport.setStartRow(1);
getReport.setEndRow(2);
getReport.setReportName("foo");
getReport.setSortAscending(true);
ReportFilter filter = new ReportFilter();
filter.setField("LastModified");
filter.setComparison(ComparisonType.GREATER_THAN);
filter.setMatchValue("2018-05-09T23:23:51.8769404Z");
filter.setMode(FilterMode.SELF);
getReport.setFilter(filter);

CredentialsHeader credentials = new CredentialsHeader();
credentials
.setUserName("foo");
credentials.setPassword("bar");
credentials.setEventID(123);

List<Object> params = new ArrayList<Object>();
params.add(1037); // reportID
params.add(null); // reportName
params.add("LastModified"); // sortColumn
params.add(true); // sortAscending
params.add(1); // startRow
params.add(2); // endRow
params.add(filter); // filter
// params.add(credentials);

exchange.getOut().setBody(params);

List<SoapHeader> soapHeaders = new ArrayList<SoapHeader>();// (List)exchange.getIn().getHeader(Header.HEADER_LIST);

SoapHeader newHeader = new SoapHeader(new QName(
"https://api.eventcore.com/",
"CredentialsHeader"), credentials,
new JAXBDataBinding(CredentialsHeader.class));

newHeader.setDirection(Direction.DIRECTION_IN);
soapHeaders.add(newHeader);

exchange.getOut().setHeader(Header.HEADER_LIST,
soapHeaders);

}

})
.id("ConferenceRegistrationSync_ECtoSFDC_cProcessor_1")
.to(endpoint_cSOAP_1)
.id("ConferenceRegistrationSync_ECtoSFDC_cSOAP_1")
.log(org.apache.camel.LoggingLevel.WARN,
"ConferenceRegistrationSync_ECtoSFDC.cLog_1",
"RESPONSE = ${body}")

 

Here is the outbound request from logs: 

[INFO ]: org.apache.cxf.services.ReportService.ReportServiceSoap12.ReportServiceSoap - Outbound Message
---------------------------
ID: 1
Address: https://api.stage.eventcore.com/ReportService.asmx
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], SOAPAction=["https://api.eventcore.com/GetReport"]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetReport xmlns="https://api.eventcore.com/"><reportID>1037</reportID><sortColumn>LastModified</sortColumn><sortAscending>true</sortAscending><startRow>1</startRow><endRow>2</endRow><filter><Field>LastModified</Field><Comparison>GreaterThan</Comparison><MatchValue>2018-05-09T23:23:51.8769404Z</MatchValue><Mode>Self</Mode><Negate>false</Negate></filter></GetReport></soap:Body></soap:Envelope>
--------------------------------------

I want to send the below SOAP request

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Header>
		<CredentialsHeader xmlns="https://api.eventcore.com/">
			<!--Optional:-->
			<UserName>foo</UserName>
			<!--Optional:-->
			<Password>bar</Password>
			<EventID>123</EventID>
		</CredentialsHeader>
	</soap:Header>
	<soap:Body>
		<GetReport xmlns="https://api.eventcore.com/">
			<reportID>1037</reportID>
			<sortColumn>LastModified</sortColumn>
			<sortAscending>true</sortAscending>
			<startRow>1</startRow>
			<endRow>2</endRow>
			<filter>
				<Field>LastModified</Field>
				<Comparison>GreaterThan</Comparison>
				<MatchValue>2018-05-09T23:23:51.8769404Z</MatchValue>
				<Mode>Self</Mode>
				<Negate>false</Negate>
			</filter>
		</GetReport>
	</soap:Body>
</soap:Envelope>

 

 

I am using Talend enterprise edition.