View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf.support;
8   
9   import java.lang.reflect.Method;
10  import java.util.ArrayList;
11  import java.util.List;
12  import java.util.logging.Level;
13  import java.util.logging.Logger;
14  
15  import javax.xml.namespace.QName;
16  import javax.xml.transform.Source;
17  
18  import org.apache.cxf.common.logging.LogUtils;
19  import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
20  import org.apache.cxf.service.factory.ServiceConstructionException;
21  import org.apache.cxf.service.model.EndpointInfo;
22  import org.apache.cxf.service.model.OperationInfo;
23  import org.apache.cxf.service.model.ServiceInfo;
24  import org.mule.module.cxf.i18n.CxfMessages;
25  
26  public class ProxyServiceFactoryBean extends ReflectionServiceFactoryBean
27  {
28  
29      private static final Logger LOG = LogUtils.getLogger(ProxyServiceFactoryBean.class);
30  
31      public ProxyServiceFactoryBean()
32      {
33          getServiceConfigurations().add(0, new ProxyServiceConfiguration());
34  
35          List<String> ignoredClasses = new ArrayList<String>();
36          ignoredClasses.add("java.lang.Object");
37          ignoredClasses.add("java.lang.Throwable");
38          ignoredClasses.add("org.omg.CORBA_2_3.portable.ObjectImpl");
39          ignoredClasses.add("org.omg.CORBA.portable.ObjectImpl");
40          ignoredClasses.add("javax.ejb.EJBObject");
41          ignoredClasses.add("javax.rmi.CORBA.Stub");
42          setIgnoredClasses(ignoredClasses);
43      }
44  
45  
46      @Override
47      protected void initializeFaultInterceptors()
48      {
49          getService().getOutFaultInterceptors().add(new ProxyFaultOutInterceptor());
50      }
51  
52      @Override
53      protected void initializeWSDLOperations()
54      {
55          if (getServiceClass().isAssignableFrom(ProxyService.class))
56          {
57              initializeWSDLOperationsForProvider();
58          }
59          else
60          {
61              super.initializeWSDLOperations();
62          }
63      }
64  
65      protected void initializeWSDLOperationsForProvider()
66      {
67          Class c = Source.class;
68  
69          if (getEndpointInfo() == null && isFromWsdl())
70          {
71              // most likely, they specified a WSDL, but for some reason
72              // did not give a valid ServiceName/PortName. For provider,
73              // we'll allow this since everything is bound directly to
74              // the invoke method, however, this CAN cause other problems
75              // such as addresses in the wsdl not getting updated and such
76              // so we'll WARN about it.....
77              List<QName> enames = new ArrayList<QName>();
78              for (ServiceInfo si : getService().getServiceInfos())
79              {
80                  for (EndpointInfo ep : si.getEndpoints())
81                  {
82                      enames.add(ep.getName());
83                  }
84              }
85              LOG.log(Level.WARNING, "COULD_NOT_FIND_ENDPOINT",  new ComponentNotFoundRuntimeException(
86                  CxfMessages.couldNotFindEndpoint(getEndpointName(), enames)));
87          }
88  
89          try
90          {
91              Method invoke = getServiceClass().getMethod("invoke", c);
92  
93              // Bind every operation to the invoke method.
94              for (ServiceInfo si : getService().getServiceInfos())
95              {
96                  for (OperationInfo o : si.getInterface().getOperations())
97                  {
98                      getMethodDispatcher().bind(o, invoke);
99                  }
100             }
101         }
102         catch (SecurityException e)
103         {
104             throw new ServiceConstructionException(e);
105         }
106         catch (NoSuchMethodException e)
107         {
108             throw new ServiceConstructionException(e);
109         }
110 
111     }
112 
113 }