XFire xfire = endpoint.getXFire();
Service service = endpoint.getXFireService();
Transport t = xfire.getTransportManager().getTransport(JbiTransport.JBI_BINDING);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Channel c = t.createChannel();
MessageContext ctx = new MessageContext();
ctx.setXFire(xfire);
ctx.setService(service);
ctx.setProperty(Channel.BACKCHANNEL_URI, out);
ctx.setExchange(new org.codehaus.xfire.exchange.MessageExchange(ctx));
InMessage msg = new InMessage();
ctx.getExchange().setInMessage(msg);
if (exchange.getOperation() != null) {
OperationInfo op = service.getServiceInfo().getOperation(exchange.getOperation().getLocalPart());
if (op != null) {
ctx.getExchange().setOperation(op);
}
}
ctx.setCurrentMessage(msg);
NormalizedMessage in = exchange.getMessage("in");
msg.setXMLStreamReader(getXMLStreamReader(in.getContent()));
if (in.getAttachmentNames() != null && in.getAttachmentNames().size() > 0) {
JavaMailAttachments attachments = new JavaMailAttachments();
for (Iterator it = in.getAttachmentNames().iterator(); it.hasNext();) {
String name = (String) it.next();
DataHandler dh = in.getAttachment(name);
attachments.addPart(new SimpleAttachment(name, dh));
}
msg.setAttachments(attachments);
}
EndpointDeliveryChannel.setEndpoint(endpoint);
JBIContext.setMessageExchange(exchange);
if (isInAndOut(exchange)) {
}
try {
c.receive(ctx, msg);
} finally {
JBIContext.setMessageExchange(null);
EndpointDeliveryChannel.setEndpoint(null);
}
c.close();
// Set response or DONE status
if (isInAndOut(exchange)) {
if (ctx.getExchange().hasFaultMessage() && ctx.getExchange().getFaultMessage().getBody() != null) {
String charSet = ctx.getExchange().getFaultMessage().getEncoding();
Fault fault = exchange.getFault();
if (fault == null) {
fault = exchange.createFault();
exchange.setFault(fault);
}
fault.setContent(new StringSource(out.toString(charSet)));
XFireFault xFault = (XFireFault) ctx.getExchange().getFaultMessage().getBody();
fault.setProperty(SOAP_FAULT_CODE, xFault.getFaultCode());
fault.setProperty(SOAP_FAULT_REASON, xFault.getReason());
fault.setProperty(SOAP_FAULT_ROLE, xFault.getRole());
fault.setProperty(SOAP_FAULT_SUBCODE, xFault.getSubCode());
} else {
String charSet = ctx.getOutMessage().getEncoding();
NormalizedMessage outMsg = exchange.getMessage("out");
if (outMsg == null) {
outMsg = exchange.createMessage();
exchange.setMessage(outMsg, "out");
}
Attachments attachments = ctx.getCurrentMessage().getAttachments();
if (attachments != null) {
for (Iterator it = attachments.getParts(); it.hasNext();) {
Attachment att = (Attachment) it.next();
outMsg.addAttachment(att.getId(), att.getDataHandler());
}