KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > axis2 > listener > soap > PetalsDispatcher


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: Axis2BCListener.java 154 19 avr. 2006 wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.binding.axis2.listener.soap;
23
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import javax.jbi.component.ComponentContext;
28 import javax.jbi.messaging.DeliveryChannel;
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.apache.axis2.AxisFault;
32 import org.apache.axis2.addressing.AddressingConstants;
33 import org.apache.axis2.addressing.EndpointReference;
34 import org.apache.axis2.context.MessageContext;
35 import org.apache.axis2.description.AxisOperation;
36 import org.apache.axis2.description.AxisService;
37 import org.apache.axis2.description.HandlerDescription;
38 import org.apache.axis2.description.InOutAxisOperation;
39 import org.apache.axis2.engine.AbstractDispatcher;
40 import org.objectweb.petals.component.common.su.SimpleServiceUnitManager;
41 import org.objectweb.petals.tools.jbicommon.descriptor.Consumes;
42
43 /**
44  * Dispatcher for JBI container. This dispatcher is used to return the service
45  * that has been registered on SU deployment.
46  *
47  * @version $Rev: 250 $ $Date: 2006-04-21 14:20:57 +0200 (ven, 21 avr 2006) $
48  * @since Petals 1.0
49  * @author alouis,wjoseph,chamerling - EBM Websourcing
50  *
51  */

52 public class PetalsDispatcher extends AbstractDispatcher implements
53     AddressingConstants {
54
55     protected Logger JavaDoc log = null;
56
57     protected ComponentContext componentContext;
58
59     protected DeliveryChannel channel;
60
61     protected SimpleServiceUnitManager bindingSUM;
62
63     protected PetalsReceiver jbiReceiver;
64
65     protected AxisService jbiService;
66
67     protected AxisOperation jbiOperation;
68
69     public static final String JavaDoc NAME = "PetalsDispatcher";
70
71     private static final long serialVersionUID = 10983L;
72
73     protected static final QName JavaDoc OPERATION_QNAME = QName
74         .valueOf("PetalsGenericOperation");
75
76     /**
77      * Init the PetalsDispatcher after it has been created by Axis.
78      *
79      * @param componentContext
80      * @param channel
81      * @param bindingSUM
82      * @param log
83      */

84     public void init(ComponentContext componentContext,
85         DeliveryChannel channel, SimpleServiceUnitManager bindingSUM, Logger JavaDoc log) {
86         this.bindingSUM = bindingSUM;
87         this.componentContext = componentContext;
88         this.log = log;
89         this.channel = channel;
90
91         this.jbiService = new AxisService();
92         this.jbiReceiver = new PetalsReceiver(componentContext, channel,
93             bindingSUM, log);
94         this.jbiOperation = new InOutAxisOperation(OPERATION_QNAME);
95         this.jbiOperation.setMessageReceiver(jbiReceiver);
96         this.jbiService.addOperation(jbiOperation);
97     }
98
99     /**
100      * Called by Axis Engine to find the operation. TODO : try to retrieve the
101      * service description of the JBI service engine and search this description
102      * for an operation with the same name
103      *
104      * @param service
105      * The service for which we search the operation
106      * @param messageContext
107      * Current MessageContext
108      * @return Returns an AxisOperation if found in the service description file
109      * or else null.
110      * @throws AxisFault
111      */

112     public AxisOperation findOperation(AxisService service,
113         MessageContext messageContext) throws AxisFault {
114         return jbiOperation;
115     }
116
117     /**
118      * Called by Axis Engine to find the service. Asks the JBI container if
119      * there is a service registered with the name of the computed called
120      * service.
121      *
122      * @param messageContext
123      * Current Messagecontext
124      * @return Returns an AxisService if found on the JBI container or else
125      * null.
126      * @throws AxisFault
127      */

128     public AxisService findService(MessageContext messageContext)
129         throws AxisFault {
130         AxisService axisService = null;
131         String JavaDoc serviceName = null;
132
133         // Get Service name using endpoint
134
EndpointReference toEPR = messageContext.getTo();
135         log.log(Level.FINE,
136             "PetalsDispatcher - Checking for Service using target endpoint address : "
137                 + toEPR.getAddress());
138         String JavaDoc filePart = toEPR.getAddress();
139         serviceName = extractWebServiceName(filePart);
140
141         // Retrieve the JBI ServiceEndpoint related to the request serviceName
142
Consumes consumes = bindingSUM.getConsumesFromAddress(serviceName);
143         if (consumes != null) {
144             // try to find if the axisService has already been registered
145
axisService = messageContext.getConfigurationContext()
146                 .getAxisConfiguration().getService(serviceName);
147         }
148         return axisService;
149     }
150
151     /*
152      * (non-Javadoc)
153      *
154      * @see org.apache.axis2.engine.AbstractDispatcher#initDispatcher()
155      */

156     public void initDispatcher() {
157         init(new HandlerDescription(NAME));
158     }
159
160     /**
161      * Parse request URL to catch the service name:
162      * ...server/services/[SERVICENAME]?method=...
163      *
164      * @param serviceName
165      * @return
166      */

167     protected String JavaDoc extractWebServiceName(String JavaDoc serviceName) {
168         int indexOfOperation = serviceName.indexOf('?');
169         indexOfOperation = (indexOfOperation > 0) ? indexOfOperation
170             : serviceName.length();
171
172         int indexOfService = serviceName.lastIndexOf('/');
173         indexOfService = (indexOfService > 0) ? indexOfService + 1 : 0;
174
175         return serviceName.substring(indexOfService, indexOfOperation);
176     }
177 }
178
Popular Tags