public class EbMSMessageUtils
{
public static MessageHeader createMessageHeader(CollaborationProtocolAgreement cpa, EbMSMessageContext context, String hostname) throws DatatypeConfigurationException
{
String uuid = UUID.getUUID();
PartyInfo sendingPartyInfo = CPAUtils.getSendingPartyInfo(cpa,context.getFromRole(),context.getServiceType(),context.getService(),context.getAction());
PartyInfo receivingPartyInfo = CPAUtils.getReceivingPartyInfo(cpa,context.getToRole(),context.getServiceType(),context.getService(),context.getAction());
//PartyInfo receivingPartyInfo = CPAUtils.getOtherReceivingPartyInfo(cpa,context.getFromRole(),context.getServiceType(),context.getService(),context.getAction());
MessageHeader messageHeader = new MessageHeader();
messageHeader.setVersion(Constants.EBMS_VERSION);
messageHeader.setMustUnderstand(true);
messageHeader.setCPAId(cpa.getCpaid());
messageHeader.setConversationId(context.getConversationId() != null ? context.getConversationId() : uuid);
messageHeader.setFrom(new From());
PartyId from = new PartyId();
from.setType(sendingPartyInfo.getPartyId().get(0).getType());
from.setValue(sendingPartyInfo.getPartyId().get(0).getValue());
messageHeader.getFrom().getPartyId().add(from);
messageHeader.getFrom().setRole(sendingPartyInfo.getCollaborationRole().get(0).getRole().getName());
messageHeader.setTo(new To());
PartyId to = new PartyId();
to.setType(receivingPartyInfo.getPartyId().get(0).getType());
to.setValue(receivingPartyInfo.getPartyId().get(0).getValue());
messageHeader.getTo().getPartyId().add(to);
messageHeader.getTo().setRole(receivingPartyInfo.getCollaborationRole().get(0).getRole().getName());
messageHeader.setService(new Service());
messageHeader.getService().setType(sendingPartyInfo.getCollaborationRole().get(0).getServiceBinding().getService().getType());
messageHeader.getService().setValue(sendingPartyInfo.getCollaborationRole().get(0).getServiceBinding().getService().getValue());
messageHeader.setAction(sendingPartyInfo.getCollaborationRole().get(0).getServiceBinding().getCanSend().get(0).getThisPartyActionBinding().getAction());