AddressingHeaders inHeaders,
AddressingHeadersFactory factory)
throws XFireFault, Exception
{
String addr = epr.getAddress();
OutMessage outMessage = null;
boolean isFault = epr.getName().equals(WSAConstants.WSA_FAULT_TO);
Transport t = null;
Channel c = null;
if (addr == null)
{
throw new XFireFault("Invalid ReplyTo address.", XFireFault.SENDER);
}
if (addr.equals(factory.getAnonymousUri()))
{
outMessage = new OutMessage(Channel.BACKCHANNEL_URI);
c = context.getInMessage().getChannel();
t = c.getTransport();
}
else
{
if (isNoneAddress(factory, addr))
{
t = new DeadLetterTransport();
outMessage = new OutMessage(addr);
c = t.createChannel();
}
else
{
outMessage = new OutMessage(addr);
t = context.getXFire().getTransportManager().getTransportForUri(addr);
c = t.createChannel();
}
}
outMessage.setChannel(c);
outMessage.setSoapVersion(context.getExchange().getInMessage().getSoapVersion());
if (t == null)
{
throw new XFireFault("URL was not recognized: " + addr, XFireFault.SENDER);
}
AddressingHeaders headers = new AddressingHeaders();
// Fault can have only refrenceParameters
if (!isFault)
{
headers.setTo(addr);
headers.setAction(aoi.getOutAction());
}
else
{
headers.setAction(WSAConstants.WSA_200508_FAULT_ACTION);
}
//headers.setMessageID("urn:uuid:" + guidGenerator.toString());
headers.setMessageID("urn:uuid:" +new RandomGUID(false).toString());
headers.setRelatesTo(inHeaders.getMessageID());
Element refParam = epr.getReferenceParametersElement();
if (refParam != null)
{
List refs = refParam.cloneContent();
List params = new ArrayList();
for (int i = 0; i < refs.size(); i++)
{
if (refs.get(i) instanceof Element)
{
Element e = (Element) refs.get(i);
e.setAttribute(new Attribute(WSAConstants.WSA_IS_REF_PARAMETER, "true", epr.getNamespace()));
params.add(e);
}
}
headers.setReferenceParameters(params);
}
outMessage.setProperty(ADRESSING_HEADERS, headers);
outMessage.setProperty(ADRESSING_FACTORY, factory);
return outMessage;
}