View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4ejb.runtime;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
12  import it.imolinfo.jbi4ejb.descriptor.ProviderServiceDescriptor;
13  import it.imolinfo.jbi4ejb.exception.EJBInvokeException;
14  import it.imolinfo.jbi4ejb.jbi.Messages;
15  import it.imolinfo.jbi4ejb.processor.transform.StringSource;
16  import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxy;
17  
18  import java.lang.reflect.InvocationTargetException;
19  import java.lang.reflect.Method;
20  
21  import org.apache.commons.lang.builder.ReflectionToStringBuilder;
22  import org.codehaus.xfire.MessageContext;
23  import org.codehaus.xfire.fault.XFireFault;
24  import org.codehaus.xfire.service.invoker.Invoker;
25  
26  /**
27   * The Service invoker, wraps th eEJBProxy call.
28   * 
29   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
30   */
31  public class ProviderServiceInvoker implements Invoker {
32  
33      /** The Logger. */
34      private static final Logger LOG
35          = LoggerFactory.getLogger(ProviderServiceInvoker.class);
36      private static final Messages MESSAGES
37      = Messages.getMessages(ProviderServiceInvoker.class);
38  
39      /** The service descriptor. */
40      private ProviderServiceDescriptor serviceDescriptor;
41  
42      /**
43       * Creates the ProviderServiceInvoker.
44       * 
45       * @param serviceDescriptor the service descriptor
46       */
47      public ProviderServiceInvoker(
48              final ProviderServiceDescriptor serviceDescriptor) {
49          this.serviceDescriptor = serviceDescriptor;
50      }
51  
52      /**
53       * The service class invocation.
54       * 
55       * @param method
56       *            The method to invoke.
57       * @param args
58       *            The method params
59       * @param messageContext
60       *            The message context
61       * @return the result Object
62       * 
63       * @throws XFireFault the service fault
64       */
65      public Object invoke(final Method method, final Object[] args,
66              final MessageContext messageContext) throws XFireFault {
67  
68          LOG.debug(">>>>> invoke - begin");
69          
70          StatelessEJBProxy ejbProxy = serviceDescriptor.getEjbProxy();        
71  
72          Object result = null;
73  
74          try {
75              // Invocation
76              result = ejbProxy.invokeMethod(method, args);
77              if (LOG.isDebugEnabled()) {
78                  LOG.debug("Result: " + ReflectionToStringBuilder.toString(result));                
79              }
80          } catch (IllegalAccessException e) {
81              // TODO i18n
82              //String msg = "Error in invoking the method: " + method + " on the remote object: " + ejbProxy.getRemoteInterfaceClassName();  
83              //LOG.error(e.getMessage());
84              //throw new XFireFault(msg, e.getCause(), XFireFault.SOAP11_SERVER);
85          	
86          } catch (InvocationTargetException e) {
87              // TODO i18n
88              String msg = "Error in invoking the method: " + method + " on the remote object: " + ejbProxy.getRemoteInterfaceClassName();  
89              LOG.error(e.getMessage());
90              throw new XFireFault(msg, e.getCause(), XFireFault.SOAP11_SERVER); 
91  
92          } catch (EJBInvokeException ex) {
93              // This exception should be thrown only if the proxy is NOT correctly initialized
94              // TODO i18n
95              String msg = "Error in invoking the method: " + method + " on the remote object: " + ejbProxy.getRemoteInterfaceClassName();  
96              LOG.error(ex.getMessage());
97              throw new XFireFault(msg, ex.getCause(), XFireFault.SOAP11_SERVER);                           
98          } finally {
99              LOG.debug(">>>>> invoke - end");
100         }
101         return result;
102     }
103 
104 }