addressingNamespaceObject =
OMAbstractFactory.getOMFactory().createOMNamespace(
addressingNamespace, WSA_DEFAULT_PREFIX);
MessageInformationHeaders messageInformationHeaders =
msgContext.getMessageInformationHeaders();
SOAPHeader soapHeader = msgContext.getEnvelope().getHeader();
// by this time, we definitely have some addressing information to be sent. This is because,
// we have tested at the start of this whether messageInformationHeaders are null or not.
// So rather than declaring addressing namespace in each and every addressing header, lets
// define that in the Header itself.
soapHeader.declareNamespace(addressingNamespaceObject);
// processing WSA To
EndpointReference epr = messageInformationHeaders.getTo();
if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, soapHeader)) {
String address = epr.getAddress();
if (!"".equals(address) && address != null) {
SOAPHeaderBlock toHeaderBlock = soapHeader.addHeaderBlock(
WSA_TO, addressingNamespaceObject);
toHeaderBlock.setText(address);
}
AnyContentType referenceParameters = epr.getReferenceParameters();
if (referenceParameters != null) {
processAnyContentType(referenceParameters, soapHeader);
}
addToHeader(epr, soapHeader);
}
// processing WSA Action
String action = messageInformationHeaders.getAction();
if (action != null && !isAddressingHeaderAlreadyAvailable(WSA_ACTION, soapHeader)) {
processStringInfo(action, WSA_ACTION, soapHeader);
}
// processing WSA replyTo
if (!isAddressingHeaderAlreadyAvailable(WSA_REPLY_TO, soapHeader)) {
epr = messageInformationHeaders.getReplyTo();
if (epr == null) {//optional
// setting anonymous URI. Defaulting to Final.
String anonymousURI = Final.WSA_ANONYMOUS_URL;
if (Submission.WSA_NAMESPACE.equals(addressingNamespace)) {
anonymousURI = Submission.WSA_ANONYMOUS_URL;
}
epr = new EndpointReference(anonymousURI);
}
// add the service group id as a reference parameter
String serviceGroupContextId = msgContext.getServiceGroupContextId();
if (serviceGroupContextId != null && !"".equals(serviceGroupContextId)) {
if (epr.getReferenceParameters() == null) {
epr.setReferenceParameters(new AnyContentType());
}
epr.getReferenceParameters().addReferenceValue(new QName(Constants.AXIS2_NAMESPACE_URI,
Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX), serviceGroupContextId);
}
addToSOAPHeader(epr, AddressingConstants.WSA_REPLY_TO, soapHeader);
}
epr = messageInformationHeaders.getFrom();
if (epr != null) {//optional
addToSOAPHeader(epr, AddressingConstants.WSA_FROM, soapHeader);
}
epr = messageInformationHeaders.getFaultTo();
if (epr != null) {//optional
addToSOAPHeader(epr, AddressingConstants.WSA_FAULT_TO, soapHeader);
}
String messageID = messageInformationHeaders.getMessageId();
if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID, soapHeader)) {//optional
processStringInfo(messageID, WSA_MESSAGE_ID, soapHeader);
}
if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, soapHeader)) {
org.apache.axis2.addressing.RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
OMElement relatesToHeader = null;
if (relatesTo != null) {
relatesToHeader =
processStringInfo(relatesTo.getValue(),