String charSet = ctx.getOutMessage().getEncoding();
    public void process(MessageExchange exchange) throws Exception {        if (exchange.getStatus() == ExchangeStatus.DONE) {            return;        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {            return;        }        // TODO: clean this code        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);        }        JBIContext.setMessageExchange(exchange);        try {            c.receive(ctx, msg);        } finally {            JBIContext.setMessageExchange(null);        }        c.close();                // Set response or DONE status        if (isInAndOut(exchange)) {            String charSet = ctx.getOutMessage().getEncoding();            if (ctx.getExchange().hasFaultMessage() && ctx.getExchange().getFaultMessage().getBody() != null) {                Fault fault = exchange.createFault();                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());                exchange.setFault(fault);            } else {                NormalizedMessage outMsg = exchange.createMessage();                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());                    }                }                outMsg.setContent(new StringSource(out.toString(charSet)));                exchange.setMessage(outMsg, "out");            }            if (exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC))) {                channel.sendSync(exchange);            } else {                channel.send(exchange);            }        } else {            exchange.setStatus(ExchangeStatus.DONE);            channel.send(exchange);        }    }