1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.jbi.component;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.jbi.Messages;
13 import it.imolinfo.jbi4corba.jbi.component.runtime.AbstractMessageExchangeHandler;
14 import it.imolinfo.jbi4corba.jbi.component.runtime.RuntimeHelper;
15 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaEndpoint;
16 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaSFServiceEndpoint;
17 import it.imolinfo.jbi4corba.jbi.processor.ExchangeProcessor;
18
19 import javax.jbi.messaging.ExchangeStatus;
20 import javax.jbi.messaging.Fault;
21 import javax.jbi.messaging.InOnly;
22 import javax.jbi.messaging.InOut;
23 import javax.jbi.messaging.MessageExchange;
24 import javax.jbi.messaging.MessagingException;
25 import javax.jbi.servicedesc.ServiceEndpoint;
26
27
28
29
30
31
32
33 public class Jbi4CorbaMessageExchangeHandler extends AbstractMessageExchangeHandler {
34
35
36 public static final long SEND_SYNC_TIMEOUT = 60000;
37
38
39 private static final Logger LOG = LoggerFactory.getLogger(Jbi4CorbaMessageExchangeHandler.class);
40 private static final Messages MESSAGES =
41 Messages.getMessages(Jbi4CorbaMessageExchangeHandler.class);
42
43
44 private Jbi4CorbaSUManager suManager = null;
45
46
47
48
49
50
51
52 public Jbi4CorbaMessageExchangeHandler(Jbi4CorbaSUManager suManager) {
53 super();
54 this.suManager = suManager;
55 }
56
57
58
59
60 protected final void processMessage() {
61
62 MessageExchange me = this.getMessageExchange();
63
64
65 ServiceEndpoint sep = me.getEndpoint();
66
67 Jbi4CorbaSFServiceEndpoint ep;
68
69 if(sep instanceof Jbi4CorbaSFServiceEndpoint){
70 ep= (Jbi4CorbaSFServiceEndpoint) sep;
71 me.setProperty("EPR_IOR", ep.getIor());
72 String msg=MESSAGES.getString("CRB000230_Received_message_invocation_for_endpoint");
73 LOG.debug(msg);
74 }
75
76 Jbi4CorbaEndpoint corbaEndpoint = suManager.getStartedEndpoint(me.getEndpoint());
77
78
79
80 java.util.logging.Logger.getLogger("com.sun.EnterContext").fine("JBI4Corba-" + corbaEndpoint.getSuName());
81
82 LOG.debug("CRB000208_Received_message_invocation_for_endpoint",
83 new Object[]{corbaEndpoint.getEndpointName()});
84
85 ExchangeProcessor processor = corbaEndpoint.getExchangeProcessor();
86
87
88 processor.process(me);
89 java.util.logging.Logger.getLogger("com.sun.ExitContext").fine("JBI4Corba-"+corbaEndpoint.getSuName());
90 }
91
92
93
94
95
96
97
98 protected void validateMessageExchange() throws MessagingException {
99
100 MessageExchange msgExchange = this.getMessageExchange();
101 LOG.debug("begin validation of exchange: "+msgExchange);
102
103
104 if ( this.getMessageExchange() == null ) {
105 String msg=MESSAGES.getString("CRB000209_MessageExchange_Object_is_null_in_MessageExchageHandler");
106 LOG.error(msg);
107 throw new MessagingException(msg);
108
109 }
110
111 if ( MessageExchange.Role.CONSUMER.equals(msgExchange.getRole()) && !(msgExchange.getStatus()==ExchangeStatus.DONE) ) {
112 String msg=MESSAGES.getString("CRB000210_Message_Exchange_Handler_can_not_have_MessageExchange_with_CONSUMER_Role");
113 LOG.error(msg);
114 throw new MessagingException(msg);
115 }
116
117 if ((!(msgExchange instanceof InOut)) && (!(msgExchange instanceof InOnly) )) {
118 String msg=MESSAGES.getString("CRB000211_MessageExchange_shoul_be_instance_of_javax.jbi.messaging.InOut_or_of_javax.jbi.messaging.InOnly");
119 LOG.error(msg);
120 throw new MessagingException(msg);
121 }
122 }
123
124
125
126
127
128
129
130 protected void processFault(Fault fault) {
131 Jbi4CorbaEndpoint corbaEndpoint = suManager.getStartedEndpoint(this.getMessageExchange().getEndpoint());
132 corbaEndpoint.getEndpointStatus().incrementReceivedErrors();
133 String msg=MESSAGES.getString("CRB000212_InOut_Message_exchange_provider_received_FAULT");
134 LOG.error(msg);
135 }
136
137
138
139
140 protected void processDone() {
141 Jbi4CorbaEndpoint corbaEndpoint = suManager.getStartedEndpoint(this.getMessageExchange().getEndpoint());
142 corbaEndpoint.getEndpointStatus().incrementReceivedDones();
143 LOG.debug("InOut Message Exchange Provider handler received DONE : END of service invocation");
144 }
145
146
147
148
149
150
151
152 protected void processError(Exception ex) {
153 String msg=MESSAGES.getString("CRB000213_InOut_Message_Exchange_Provider_handler_received_Error");
154 LOG.error(msg,ex);
155 RuntimeHelper.logError(msg + ex);
156
157 }
158
159 }