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.jbi.xfire.EjbTransport;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.codehaus.xfire.XFire;
19  import org.codehaus.xfire.aegis.AegisBindingProvider;
20  import org.codehaus.xfire.aegis.type.TypeMapping;
21  import org.codehaus.xfire.annotations.AnnotationServiceFactory;
22  import org.codehaus.xfire.service.Service;
23  import org.codehaus.xfire.service.binding.ObjectServiceFactory;
24  import org.codehaus.xfire.soap.SoapConstants;
25  
26  /**
27   * The ProviderServiceCreator.
28   * 
29   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
30   */
31  public class ProviderServiceCreator {
32  
33      /** Logger. */
34      private static final Logger LOG = LoggerFactory
35              .getLogger(ProviderServiceCreator.class);
36  
37      /**
38       * Empty Constructor.
39       */
40      public ProviderServiceCreator() {}
41  
42      /**
43       * Creates the xfire service.
44       * 
45       * @param serviceDescriptor the servcie descriptr
46       * @param xfire Xfire engine
47       * 
48       * @return the service
49       */
50      @SuppressWarnings("unchecked")
51      public Service createJbiService(
52              ProviderServiceDescriptor serviceDescriptor, XFire xfire) {
53          
54          LOG.debug("Creating xfire service: " + serviceDescriptor.getServiceName());
55  
56          ObjectServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), null);
57  
58          Map<String, Object> props = new HashMap<String, Object>();
59  
60          props.put(ObjectServiceFactory.PORT_TYPE, serviceDescriptor
61                  .getPortTypeName());
62          props.put(ObjectServiceFactory.STYLE, SoapConstants.STYLE_WRAPPED);
63          props.put(ObjectServiceFactory.USE, SoapConstants.USE_LITERAL);
64  
65          props.put(AnnotationServiceFactory.ALLOW_INTERFACE, Boolean.TRUE);
66  
67          factory.getSoap11Transports().clear();
68          factory.getSoap12Transports().clear();
69          factory.getSoap11Transports().add(EjbTransport.EJB_BINDING);
70  
71          Service service = null;
72  
73          service = factory.create(serviceDescriptor.getEjbProxy()
74                  .getRemoteInterfaceClass(), serviceDescriptor.getServiceName()
75                  .getLocalPart(), serviceDescriptor.getServiceName()
76                  .getNamespaceURI(), props);
77  
78          // Adds the invoker
79          service.setInvoker(new ProviderServiceInvoker(serviceDescriptor));
80          
81  
82          // XFire bug : http://jira.codehaus.org/browse/XFIRE-462 - BEGIN
83  
84          AegisBindingProvider abp = (AegisBindingProvider) factory
85                  .getBindingProvider();
86  
87          TypeMapping typeMapping = abp.getTypeMapping(service);
88          typeMapping.register(new ByteType());
89          // XFire bug --------------------------------------------- END
90  
91          return service;
92      }
93  
94  }