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
10 ~ http://www.apache.org/licenses/LICENSE-2.0
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
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,
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"
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">
47 <jsp:include page="include/header.inc"/>
48 <jsp:include page="include/link-footer.jsp"/>
49 <%IP = request.getRequestURL().toString();%>
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
60 * Get a string providing install information.
61 * TODO: make this platform aware and give specific hints
63 public String getInstallHints(HttpServletRequest request) {
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.";
71 * test for a class existing
73 * @return class iff present
75 Class classExists(String classname) {
77 return Class.forName(classname);
78 } catch (ClassNotFoundException e) {
84 * test for resource on the classpath
86 * @return true iff present
88 boolean resourceExists(String resource) {
90 InputStream instream = this.getClass().getResourceAsStream(resource);
91 found = instream != null;
92 if (instream != null) {
95 } catch (IOException e) {
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
112 int probeClass(JspWriter out,
116 String axisOperation,
118 String homePage) throws IOException {
120 Class clazz = classExists(classname);
123 if (homePage != null) {
124 url = "<br> See <a href=" + homePage + ">" + homePage + "</a>";
126 out.write("<p>" + category + ": could not find class " + classname
127 + " from file <b>" + jarFile
128 + "</b><br> " + errorText
133 String location = getLocation(out, clazz);
134 if (location == null) {
135 out.write("Found " + axisOperation + " (" + classname + ")<br/>");
137 out.write("Found " + axisOperation + " (" + classname + ") <br/> at " + location + "<br/>");
141 } catch (NoClassDefFoundError ncdfe) {
143 if (homePage != null) {
144 url = "<br> See <a href=" + homePage + ">" + homePage + "</a>";
146 out.write("<p>" + category + ": could not find a dependency"
147 + " of class " + classname
148 + " from file <b>" + jarFile
149 + "</b><br> " + errorText
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."
161 * get the location of a class
164 * @return the jar file or path where a class was found
167 String getLocation(JspWriter out,
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();
177 if (location.startsWith("file")) {
178 java.io.File file = new java.io.File(url.getFile());
179 return file.getAbsolutePath();
181 return url.toString();
183 } catch (Throwable t) {
185 return "an unknown location";
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)
198 int needClass(JspWriter out,
201 String axisOperation,
203 String homePage) throws IOException {
204 return probeClass(out,
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)
223 int wantClass(JspWriter out,
226 String axisOperation,
228 String homePage) throws IOException {
229 return probeClass(out,
239 * probe for a resource existing,
245 int wantResource(JspWriter out,
247 String errorText) throws Exception {
248 if (!resourceExists(resource)) {
249 out.write("<p><b>Warning</b>: could not find resource " + resource
254 out.write("found " + resource + "<br>");
261 * get servlet version string
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);
274 * what parser are we using.
275 * @return the classname of the parser
277 private String getParserName() {
278 SAXParser saxParser = getSAXParser();
279 if (saxParser == null) {
280 return "Could not create an XML Parser";
283 // check to what is in the classname
284 return saxParser.getClass().getName();
288 * Create a JAXP SAXParser
289 * @return parser or null for trouble
291 private SAXParser getSAXParser() {
292 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
293 if (saxParserFactory == null) {
296 SAXParser saxParser = null;
298 saxParser = saxParserFactory.newSAXParser();
299 } catch (Exception e) {
305 * get the location of the parser
306 * @return path or null for trouble in tracking it down
309 private String getParserLocation(JspWriter out) {
310 SAXParser saxParser = getSAXParser();
311 if (saxParser == null) {
314 return getLocation(out, saxParser.getClass());
317 private String value;
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);
328 public boolean invokeTheService() {
330 // since this one is an internal request we do not use public frontendHostUrl
332 int lastindex = IP.lastIndexOf('/');
333 IP = IP.substring(0, lastindex);
334 ///axis2/axis2-web/services/version
335 IP = IP.replaceAll("axis2-web", "");
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);
347 OMElement result = client.sendReceive(payload);
348 StringWriter writer = new StringWriter();
349 result.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
351 value = writer.toString();
353 } catch (AxisFault axisFault) {
354 System.out.println(value);
356 } catch (XMLStreamException e) {
357 value = e.getMessage();
362 public String getFormatedSystemProperty(String systemProperty){
363 if (systemProperty == null)
365 return systemProperty.replaceAll(":", ": ");
369 <h1>Axis2 Happiness Page</h1>
371 <h2>Examining webapp configuration</h2>
375 <h4>Essential Components</h4>
378 int needed = 0,wanted = 0;
381 * the essentials, without these Axis is not going to work
383 needed = needClass(out, "org.apache.axis2.transport.http.AxisServlet",
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/");
407 * resources on the classpath path
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");
414 /* add more libraries here */
416 //is everything we need here
419 out.write("<p><font color='green'><strong>The core axis2 libraries are present.</strong></font></p>");
421 //no, be very unhappy
422 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
423 out.write("<font color='red'><i>"
425 + " core axis2 librar"
426 + (needed == 1 ? "y is" : "ies are")
427 + " missing</i></font>");
429 //now look at wanted stuff
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>
437 <h2>Examining Version Service</h2>
439 boolean serviceStatus = invokeTheService();
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
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
468 <h2>Examining Application Server</h2>
471 <tr><td>Servlet version</td><td><%=getServletVersion()%></td></tr>
472 <tr><td>Platform</td>
473 <td><%=getServletConfig().getServletContext().getServerInfo()%></td>
477 <h2>Examining System Properties</h2>
480 * Dump the system properties
482 java.util.Enumeration e = null;
484 e = System.getProperties().propertyNames();
485 } catch (SecurityException se) {
489 out.write("<table cellpadding='5px' cellspacing='0px' style='border: .5px blue solid;'>");
490 for (; e.hasMoreElements();) {
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)) + " </td>");
497 out.write("</table>");
498 out.write("</pre><p>");
500 out.write("System properties are not accessible<p>");
504 <jsp:include page="include/footer.inc"/>