1   
2   
3   
4   
5   
6   
7   
8   
9   package it.imolinfo.jbi4ejb.jbi.xfire;
10  
11  import it.imolinfo.jbi4ejb.Logger;
12  import it.imolinfo.jbi4ejb.LoggerFactory;
13  import it.imolinfo.jbi4ejb.jbi.Messages;
14  import it.imolinfo.jbi4ejb.jbi.component.Jbi4EjbLifeCycle;
15  
16  import java.io.OutputStream;
17  
18  import javax.xml.stream.XMLOutputFactory;
19  import javax.xml.stream.XMLStreamException;
20  import javax.xml.stream.XMLStreamWriter;
21  
22  import org.codehaus.xfire.MessageContext;
23  import org.codehaus.xfire.XFireException;
24  import org.codehaus.xfire.exchange.OutMessage;
25  import org.codehaus.xfire.transport.AbstractChannel;
26  import org.codehaus.xfire.transport.Channel;
27  
28  
29  
30  
31  
32  
33  public class EjbChannel extends AbstractChannel {
34      
35      
36      private static final Logger LOG = LoggerFactory.getLogger(EjbChannel.class);
37      private static final Messages MESSAGES = Messages.getMessages(EjbChannel.class);
38      
39      
40      private XMLOutputFactory outputFactory;             
41  
42      
43  
44  
45  
46  
47  
48      public EjbChannel(String uri, EjbTransport transport) {
49          setTransport(transport);
50          setUri(uri);
51          this.outputFactory = XMLOutputFactory.newInstance();        
52      }
53  
54      
55      
56  
57  
58  
59  
60  
61  
62      public void open() throws Exception {
63          
64      }
65  
66      
67  
68  
69      
70      
71      
72  
73  
74  
75  
76  
77  
78  
79      public void send(MessageContext context, OutMessage message) throws XFireException {
80          LOG.debug("Xfire send called");
81          if (Channel.BACKCHANNEL_URI.equals(message.getUri())) {
82              LOG.debug("message.getUri(): " + message.getUri());
83              final OutputStream out = (OutputStream) context.getProperty(Channel.BACKCHANNEL_URI);
84              if (out != null) {
85                  try {
86                      final XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, message.getEncoding());                                        
87                      message.getSerializer().writeMessage(message, writer, context);                    
88                      writer.close();
89                  } catch (XMLStreamException e) {
90                  	String msg=MESSAGES.getString("EJB000501_EjbChannel", new Object[]{e.getMessage()});
91                      LOG.error(msg,e);
92                      throw new XFireException(msg,e);   
93  
94                  }
95                  return;
96              }
97          } else {
98              
99              LOG.debug("NOT a backchannel URI, not implemented");
100         }
101     }
102 
103 }