Salome HOME
Siman-WS eclipse project is added
[tools/siman.git] / Workspace / Siman-WS / WebContent / axis2-web / HappyAxis.jsp
1 <%--
2   ~ Licensed to the Apache Software Foundation (ASF) under one
3   ~ or more contributor license agreements. See the NOTICE file
4   ~ distributed with this work for additional information
5   ~ regarding copyright ownership. The ASF licenses this file
6   ~ to you under the Apache License, Version 2.0 (the
7   ~ "License"); you may not use this file except in compliance
8   ~ with the License. You may obtain a copy of the License at
9   ~
10   ~ http://www.apache.org/licenses/LICENSE-2.0
11   ~
12   ~ Unless required by applicable law or agreed to in writing,
13   ~ software distributed under the License is distributed on an
14   ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   ~ KIND, either express or implied. See the License for the
16   ~ specific language governing permissions and limitations
17   ~ under the License.
18   --%>
19
20 <html>
21 <%@ page import="org.apache.axis2.AxisFault,
22                  org.apache.axis2.Constants,
23                  org.apache.axis2.addressing.EndpointReference,
24                  org.apache.axis2.client.Options,
25                  org.apache.axis2.client.ServiceClient,
26                  org.apache.axis2.context.ConfigurationContext,
27                  org.apache.axis2.context.ConfigurationContextFactory,
28                  javax.xml.parsers.SAXParser,
29                  javax.xml.parsers.SAXParserFactory,
30                  java.io.IOException,
31                  java.io.InputStream,
32                  java.io.StringWriter,
33                  org.apache.axiom.om.OMElement,
34                  org.apache.axiom.om.OMFactory,
35                  org.apache.axiom.om.OMNamespace,
36                  org.apache.axiom.om.OMAbstractFactory,
37                  javax.xml.stream.XMLOutputFactory,
38                  javax.xml.stream.XMLStreamException"
39          session="false" %>
40 <head>
41     <jsp:include page="include/httpbase.jsp"/>
42     <title>Axis2 Happiness Page</title>
43     <link href="axis2-web/css/axis-style.css" rel="stylesheet" type="text/css">
44 </head>
45
46 <body>
47 <jsp:include page="include/header.inc"/>
48 <jsp:include page="include/link-footer.jsp"/>
49 <%IP = request.getRequestURL().toString();%>
50 <%!
51     /*
52     * Happiness tests for axis2. These look at the classpath and warn if things
53     * are missing. Normally addng this much code in a JSP page is mad
54     * but here we want to validate JSP compilation too, and have a drop-in
55     * page for easy re-use
56     */
57     String IP;
58
59     /**
60      * Get a string providing install information.
61      * TODO: make this platform aware and give specific hints
62      */
63     public String getInstallHints(HttpServletRequest request) {
64
65         return "<B><I>Note:</I></B> On Tomcat 4.x and Java1.4, you may need to put libraries that contain "
66                 + "java.* or javax.* packages into CATALINA_HOME/common/lib"
67                 + "<br>jaxrpc.jar and saaj.jar are two such libraries.";
68     }
69
70     /**
71      * test for a class existing
72      * @param classname
73      * @return class iff present
74      */
75     Class classExists(String classname) {
76         try {
77             return Class.forName(classname);
78         } catch (ClassNotFoundException e) {
79             return null;
80         }
81     }
82
83     /**
84      * test for resource on the classpath
85      * @param resource
86      * @return true iff present
87      */
88     boolean resourceExists(String resource) {
89         boolean found;
90         InputStream instream = this.getClass().getResourceAsStream(resource);
91         found = instream != null;
92         if (instream != null) {
93             try {
94                 instream.close();
95             } catch (IOException e) {
96             }
97         }
98         return found;
99     }
100
101     /**
102      * probe for a class, print an error message is missing
103      * @param out stream to print stuff
104      * @param category text like "warning" or "error"
105      * @param classname class to look for
106      * @param jarFile where this class comes from
107      * @param errorText extra error text
108      * @param homePage where to d/l the library
109      * @return the number of missing classes
110      * @throws IOException
111      */
112     int probeClass(JspWriter out,
113                    String category,
114                    String classname,
115                    String jarFile,
116                    String axisOperation,
117                    String errorText,
118                    String homePage) throws IOException {
119         try {
120             Class clazz = classExists(classname);
121             if (clazz == null) {
122                 String url = "";
123                 if (homePage != null) {
124                     url = "<br>  See <a href=" + homePage + ">" + homePage + "</a>";
125                 }
126                 out.write("<p>" + category + ": could not find class " + classname
127                         + " from file <b>" + jarFile
128                         + "</b><br>  " + errorText
129                         + url
130                         + "<p>");
131                 return 1;
132             } else {
133                 String location = getLocation(out, clazz);
134                 if (location == null) {
135                     out.write("Found " + axisOperation + " (" + classname + ")<br/>");
136                 } else {
137                     out.write("Found " + axisOperation + " (" + classname + ") <br/> &nbsp;&nbsp;at " + location + "<br/>");
138                 }
139                 return 0;
140             }
141         } catch (NoClassDefFoundError ncdfe) {
142             String url = "";
143             if (homePage != null) {
144                 url = "<br>  See <a href=" + homePage + ">" + homePage + "</a>";
145             }
146             out.write("<p>" + category + ": could not find a dependency"
147                     + " of class " + classname
148                     + " from file <b>" + jarFile
149                     + "</b><br> " + errorText
150                     + url
151                     + "<br>The root cause was: " + ncdfe.getMessage()
152                     + "<br>This can happen e.g. if " + classname + " is in"
153                     + " the 'common' classpath, but a dependency like "
154                     + " activation.jar is only in the webapp classpath."
155                     + "<p>");
156             return 1;
157         }
158     }
159
160     /**
161      * get the location of a class
162      * @param out
163      * @param clazz
164      * @return the jar file or path where a class was found
165      */
166
167     String getLocation(JspWriter out,
168                        Class clazz) {
169         try {
170             java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
171             String location = url.toString();
172             if (location.startsWith("jar")) {
173                 url = ((java.net.JarURLConnection) url.openConnection()).getJarFileURL();
174                 location = url.toString();
175             }
176
177             if (location.startsWith("file")) {
178                 java.io.File file = new java.io.File(url.getFile());
179                 return file.getAbsolutePath();
180             } else {
181                 return url.toString();
182             }
183         } catch (Throwable t) {
184         }
185         return "an unknown location";
186     }
187
188     /**
189      * a class we need if a class is missing
190      * @param out stream to print stuff
191      * @param classname class to look for
192      * @param jarFile where this class comes from
193      * @param errorText extra error text
194      * @param homePage where to d/l the library
195      * @throws IOException when needed
196      * @return the number of missing libraries (0 or 1)
197      */
198     int needClass(JspWriter out,
199                   String classname,
200                   String jarFile,
201                   String axisOperation,
202                   String errorText,
203                   String homePage) throws IOException {
204         return probeClass(out,
205                 "<b>Error</b>",
206                 classname,
207                 jarFile,
208                 axisOperation,
209                 errorText,
210                 homePage);
211     }
212
213     /**
214      * print warning message if a class is missing
215      * @param out stream to print stuff
216      * @param classname class to look for
217      * @param jarFile where this class comes from
218      * @param errorText extra error text
219      * @param homePage where to d/l the library
220      * @throws IOException when needed
221      * @return the number of missing libraries (0 or 1)
222      */
223     int wantClass(JspWriter out,
224                   String classname,
225                   String jarFile,
226                   String axisOperation,
227                   String errorText,
228                   String homePage) throws IOException {
229         return probeClass(out,
230                 "<b>Warning</b>",
231                 classname,
232                 jarFile,
233                 axisOperation,
234                 errorText,
235                 homePage);
236     }
237
238     /**
239      * probe for a resource existing,
240      * @param out
241      * @param resource
242      * @param errorText
243      * @throws Exception
244      */
245     int wantResource(JspWriter out,
246                      String resource,
247                      String errorText) throws Exception {
248         if (!resourceExists(resource)) {
249             out.write("<p><b>Warning</b>: could not find resource " + resource
250                     + "<br>"
251                     + errorText);
252             return 0;
253         } else {
254             out.write("found " + resource + "<br>");
255             return 1;
256         }
257     }
258
259
260     /**
261      *  get servlet version string
262      *
263      */
264
265     public String getServletVersion() {
266         ServletContext context = getServletConfig().getServletContext();
267         int major = context.getMajorVersion();
268         int minor = context.getMinorVersion();
269         return Integer.toString(major) + '.' + Integer.toString(minor);
270     }
271
272
273     /**
274      * what parser are we using.
275      * @return the classname of the parser
276      */
277     private String getParserName() {
278         SAXParser saxParser = getSAXParser();
279         if (saxParser == null) {
280             return "Could not create an XML Parser";
281         }
282
283         // check to what is in the classname
284         return saxParser.getClass().getName();
285     }
286
287     /**
288      * Create a JAXP SAXParser
289      * @return parser or null for trouble
290      */
291     private SAXParser getSAXParser() {
292         SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
293         if (saxParserFactory == null) {
294             return null;
295         }
296         SAXParser saxParser = null;
297         try {
298             saxParser = saxParserFactory.newSAXParser();
299         } catch (Exception e) {
300         }
301         return saxParser;
302     }
303
304     /**
305      * get the location of the parser
306      * @return path or null for trouble in tracking it down
307      */
308
309     private String getParserLocation(JspWriter out) {
310         SAXParser saxParser = getSAXParser();
311         if (saxParser == null) {
312             return null;
313         }
314         return getLocation(out, saxParser.getClass());
315     }
316
317     private String value;
318
319     private OMElement createEnvelope() {
320         OMFactory fac = OMAbstractFactory.getOMFactory();
321         OMNamespace omNs = fac.createOMNamespace("http://axisversion.sample", "ns1");
322         OMElement method = fac.createOMElement("getVersion", omNs);
323         OMElement value = fac.createOMElement("myValue", omNs);
324         method.addChild(value);
325         return method;
326     }
327
328     public boolean invokeTheService() {
329         try {
330             // since this one is an internal request we do not use public frontendHostUrl
331             // for it
332             int lastindex = IP.lastIndexOf('/');
333             IP = IP.substring(0, lastindex);
334             ///axis2/axis2-web/services/version
335             IP = IP.replaceAll("axis2-web", "");
336
337             OMElement payload = createEnvelope();
338             ConfigurationContext configctx =
339                     ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
340             ServiceClient client = new ServiceClient(configctx, null);
341             EndpointReference targetEPR = new EndpointReference(IP + configctx.getServicePath() + "/Version");
342             Options options = new Options();
343             client.setOptions(options);
344             options.setTo(targetEPR);
345             options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
346
347             OMElement result = client.sendReceive(payload);
348             StringWriter writer = new StringWriter();
349             result.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
350             writer.flush();
351             value = writer.toString();
352             return true;
353         } catch (AxisFault axisFault) {
354             System.out.println(value);
355             return false;
356         } catch (XMLStreamException e) {
357             value = e.getMessage();
358             return false;
359         }
360     }
361     
362     public String getFormatedSystemProperty(String systemProperty){
363         if (systemProperty == null)
364             return "";
365         return  systemProperty.replaceAll(":", ": ");
366     }
367 %>
368
369 <h1>Axis2 Happiness Page</h1>
370
371 <h2>Examining webapp configuration</h2>
372
373 <blockquote>
374
375 <h4>Essential Components</h4>
376
377 <%
378     int needed = 0,wanted = 0;
379
380     /**
381      * the essentials, without these Axis is not going to work
382      */
383     needed = needClass(out, "org.apache.axis2.transport.http.AxisServlet",
384             "axis2-1.0.jar",
385             "Apache-Axis",
386             "Axis2 will not work",
387             "http://xml.apache.org/axis2/");
388     needed += needClass(out, "org.apache.commons.logging.Log",
389             "commons-logging.jar",
390             "Jakarta-Commons Logging",
391             "Axis2 will not work",
392             "http://jakarta.apache.org/commons/logging.html");
393     needed += needClass(out, "javax.xml.stream.XMLStreamReader",
394             "stax-api-1.0.1.jar",
395             "Streaming API for XML",
396             "Axis2 will not work",
397             "http://dist.codehaus.org/stax/jars/");
398     needed += needClass(out, "org.codehaus.stax2.XMLStreamWriter2",
399             "wstx-asl-3.0.1.jar",
400             "Streaming API for XML implementation",
401             "Axis2 will not work",
402             "http://dist.codehaus.org/stax/jars/");
403
404 %>
405 <%
406     /*
407     * resources on the classpath path
408     */
409     /* broken; this is a file, not a resource
410     wantResource(out,"/server-config.wsdd",
411     "There is no server configuration file;"
412     +"run AdminClient to create one");
413     */
414     /* add more libraries here */
415
416     //is everything we need here
417     if (needed == 0) {
418         //yes, be happy
419         out.write("<p><font color='green'><strong>The core axis2 libraries are present.</strong></font></p>");
420     } else {
421         //no, be very unhappy
422         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
423         out.write("<font color='red'><i>"
424                 + needed
425                 + " core axis2 librar"
426                 + (needed == 1 ? "y is" : "ies are")
427                 + " missing</i></font>");
428     }
429     //now look at wanted stuff
430 %>
431 <p>
432     <B><I>Note:</I></B> Even if everything this page probes for is present,
433     there is no guarantee your Axis Service will work, because there are many configuration options
434     that we do not check for. These tests are <i>necessary</i> but not <i>sufficient</i>
435 </p>
436 </blockquote>
437 <h2>Examining Version Service</h2>
438 <%
439     boolean serviceStatus = invokeTheService();
440     if (serviceStatus) {
441 %>
442 <blockquote>
443     <font color="green"><strong>
444         Found Axis2 default Version service and Axis2 is working
445         properly.</strong></font>
446     <p>Now you can drop a service archive in axis2/WEB-INF/services.
447         Following output was produced while invoking Axis2 version service
448         </p>
449         <p><%= value%></p>
450 </blockquote>
451
452 <%
453 } else {
454 %>
455 <p>
456     <font color="brown"> There was a problem in Axis2 version service , may be
457         the service not available or some thing has gone wrong. But this does
458         not mean system is not working !
459         Try to upload some other service and check to see whether it is
460         working.
461         <br>
462     </font>
463 </p>
464
465 <%
466     }
467 %>
468 <h2>Examining Application Server</h2>
469 <blockquote>
470 <table>
471     <tr><td>Servlet version</td><td><%=getServletVersion()%></td></tr>
472     <tr><td>Platform</td>
473         <td><%=getServletConfig().getServletContext().getServerInfo()%></td>
474     </tr>
475 </table>
476 </blockquote>
477 <h2>Examining System Properties</h2>
478 <%
479     /**
480      * Dump the system properties
481      */
482     java.util.Enumeration e = null;
483     try {
484         e = System.getProperties().propertyNames();
485     } catch (SecurityException se) {
486     }
487     if (e != null) {
488         out.write("<pre>");
489         out.write("<table cellpadding='5px' cellspacing='0px' style='border: .5px blue solid;'>");
490         for (; e.hasMoreElements();) {
491             out.write("<tr>");
492             String key = (String) e.nextElement();
493             out.write("<th style='border: .5px #A3BBFF solid;'>" + key + "</th>");
494             out.write("<td style='border: .5px #A3BBFF solid;'>" + getFormatedSystemProperty(System.getProperty(key)) + "&nbsp;</td>");
495             out.write("<tr>");
496         }
497         out.write("</table>");
498         out.write("</pre><p>");
499     } else {
500         out.write("System properties are not accessible<p>");
501     }
502 %>
503
504 <jsp:include page="include/footer.inc"/>
505 </body>
506 </html>
507
508