KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2007 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$
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.binding.axis2.listener.soap;
23
24 import java.io.IOException JavaDoc;
25 import java.io.OutputStream JavaDoc;
26
27 import javax.jbi.component.ComponentContext;
28 import javax.jbi.servicedesc.ServiceEndpoint;
29
30 import org.apache.axis2.AxisFault;
31 import org.apache.axis2.description.AxisService;
32 import org.apache.axis2.engine.AxisConfiguration;
33 import org.objectweb.petals.component.common.util.WSDLHelper;
34 import org.w3c.dom.Document JavaDoc;
35
36 /**
37  * The {@link PetalsAxisService} extends an {@link AxisService}. It is
38  * registered during SU deployment into the {@link AxisConfiguration}.
39  *
40  * This class override the printWSDL method to dynamically generate the WSDL
41  * from the JBI container.
42  *
43  * @author Christophe HAMERLING - eBMWebSourcing
44  *
45  */

46 public class PetalsAxisService extends AxisService {
47
48     private ComponentContext componentContext;
49
50     private ServiceEndpoint endpoint;
51
52     /**
53      * Creates a new instance of {@link PetalsAxisService}
54      *
55      * @param name
56      * @param componentContext
57      * @param endpoint
58      */

59     public PetalsAxisService(String JavaDoc name, ComponentContext componentContext,
60         ServiceEndpoint endpoint) {
61         super(name);
62         this.componentContext = componentContext;
63         this.endpoint = endpoint;
64     }
65
66     /*
67      * (non-Javadoc)
68      *
69      * @see org.apache.axis2.description.AxisService#printWSDL(java.io.OutputStream,
70      * java.lang.String, java.lang.String)
71      */

72     @Override JavaDoc
73     public void printWSDL(OutputStream JavaDoc out, String JavaDoc requestIP, String JavaDoc servicePath)
74         throws AxisFault {
75         try {
76             Document JavaDoc document = componentContext
77                 .getEndpointDescriptor(endpoint);
78             if (document == null) {
79                 printWSDLError(out);
80             } else {
81                 WSDLHelper.printWSDL(document, out);
82             }
83         } catch (Exception JavaDoc e) {
84             throw new AxisFault(e);
85         }
86     }
87     
88     /* (non-Javadoc)
89      * @see org.apache.axis2.description.AxisService#printWSDL2(java.io.OutputStream, java.lang.String, java.lang.String)
90      */

91     @Override JavaDoc
92     public void printWSDL2(OutputStream JavaDoc out, String JavaDoc requestIP, String JavaDoc servicePath) throws AxisFault {
93         printWSDL(out, requestIP, servicePath);
94     }
95
96     /**
97      * Print the WSDL error on the output stream
98      *
99      * @param out
100      * @throws AxisFault
101      */

102     private void printWSDLError(OutputStream JavaDoc out) throws AxisFault {
103         try {
104             String JavaDoc wsdlntfound = "<error>"
105                 + "<description>Unable to get WSDL for this service</description>"
106                 + "<reason>The PEtALS endpoint did not returns its descriptor. </reason>"
107                 + "</error>";
108             out.write(wsdlntfound.getBytes());
109             out.flush();
110             out.close();
111         } catch (IOException JavaDoc e) {
112             throw new AxisFault(e);
113         }
114     }
115 }
116
Popular Tags