Author: supun
Date: Mon Jan 3 07:15:25 2011
New Revision: 1054538
URL: http://svn.apache.org/viewvc?rev=1054538&view=rev
Log:
applying patch for issue SYNAPSE-699, this introduces a pluggable http get
request processor to nhttp transport, thanks heshan for the contribution
Added:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/DefaultHttpGetProcessor.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpGetRequestProcessor.java
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
Added:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/DefaultHttpGetProcessor.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/DefaultHttpGetProcessor.java?rev=1054538&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/DefaultHttpGetProcessor.java
(added)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/DefaultHttpGetProcessor.java
Mon Jan 3 07:15:25 2011
@@ -0,0 +1,632 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.transport.nhttp;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.transport.http.HTTPTransportReceiver;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.util.MessageContextBuilder;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.nio.NHttpServerConnection;
+import org.apache.http.protocol.HTTP;
+import org.apache.synapse.transport.nhttp.util.RESTUtil;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.*;
+
+/**
+ * Default http Get processor implementation for Synapse.
+ */
+public class DefaultHttpGetProcessor implements HttpGetRequestProcessor {
+ private static final Log log =
LogFactory.getLog(DefaultHttpGetProcessor.class);
+
+ private static final String LOCATION = "Location";
+ private static final String CONTENT_TYPE = "Content-Type";
+ private static final String TEXT_HTML = "text/html";
+ private static final String TEXT_XML = "text/xml";
+
+ protected ConfigurationContext cfgCtx;
+
+ protected ServerHandler serverHandler;
+
+ public void init(ConfigurationContext cfgCtx, ServerHandler serverHandler)
throws AxisFault {
+ this.cfgCtx = cfgCtx;
+ this.serverHandler = serverHandler;
+ }
+
+ /**
+ * Process the HTTP GET request.
+ *
+ * @param request The HttpRequest
+ * @param response The HttpResponse
+ * @param msgContext The MessageContext
+ * @param conn The NHttpServerConnection
+ * @param os The OutputStream
+ */
+ public void process(HttpRequest request,
+ HttpResponse response,
+ MessageContext msgContext,
+ NHttpServerConnection conn,
+ OutputStream os,
+ boolean isRestDispatching) {
+
+ String uri = request.getRequestLine().getUri();
+
+ String servicePath = cfgCtx.getServiceContextPath();
+ if (!servicePath.startsWith("/")) {
+ servicePath = "/" + servicePath;
+ }
+
+ String serviceName = getServiceName(request);
+
+ Map<String, String> parameters = new HashMap<String, String>();
+ int pos = uri.indexOf("?");
+ if (pos != -1) {
+ msgContext.setTo(new EndpointReference(uri.substring(0, pos)));
+ StringTokenizer st = new StringTokenizer(uri.substring(pos + 1),
"&");
+ while (st.hasMoreTokens()) {
+ String param = st.nextToken();
+ pos = param.indexOf("=");
+ if (pos != -1) {
+ parameters.put(param.substring(0, pos),
param.substring(pos + 1));
+ } else {
+ parameters.put(param, null);
+ }
+ }
+ } else {
+ msgContext.setTo(new EndpointReference(uri));
+ }
+
+ if (uri.equals("/favicon.ico")) {
+ response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
+ response.addHeader(LOCATION, "http://ws.apache.org/favicon.ico");
+ serverHandler.commitResponseHideExceptions(conn, response);
+
+// } else if (!uri.startsWith(servicePath)) {
+// response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
+// response.addHeader(LOCATION, servicePath + "/");
+// serverHandler.commitResponseHideExceptions(conn, response);
+
+ } else if (serviceName != null && parameters.containsKey("wsdl")) {
+ generateWsdl(request, response, msgContext,
+ conn, os, serviceName, parameters, isRestDispatching);
+ } else if (serviceName != null && parameters.containsKey("wsdl2")) {
+ generateWsdl2(request, response, msgContext,
+ conn, os, serviceName, isRestDispatching);
+ } else if (serviceName != null && parameters.containsKey("xsd")) {
+ generateXsd(response, conn, os, serviceName, parameters);
+ } else if (serviceName != null && parameters.containsKey("info")) {
+ generateServiceDetailsPage(response, conn, os, serviceName);
+ } else if (uri.startsWith(servicePath) &&
+ (serviceName == null || serviceName.length() == 0)) {
+ generateServicesList(response, conn, os, servicePath);
+ } else {
+ processGetAndDelete(request, response, msgContext,
+ conn, os, "GET", isRestDispatching);
+ return;
+ }
+
+ // make sure that the output stream is flushed and closed properly
+ try {
+ os.flush();
+ os.close();
+ } catch (IOException ignore) {
+ }
+
+ }
+
+ /**
+ * Returns the service name.
+ *
+ * @param request HttpRequest
+ * @return service name as a String
+ */
+ protected String getServiceName(HttpRequest request) {
+ String uri = request.getRequestLine().getUri();
+
+ String servicePath = cfgCtx.getServiceContextPath();
+ if (!servicePath.startsWith("/")) {
+ servicePath = "/" + servicePath;
+ }
+
+ String serviceName = null;
+ if (uri.startsWith(servicePath)) {
+ serviceName = uri.substring(servicePath.length());
+ if (serviceName.startsWith("/")) {
+ serviceName = serviceName.substring(1);
+ }
+ if (serviceName.indexOf("?") != -1) {
+ serviceName = serviceName.substring(0,
serviceName.indexOf("?"));
+ }
+ }
+
+ if (serviceName != null) {
+ int opnStart = serviceName.indexOf("/");
+ if (opnStart != -1) {
+ serviceName = serviceName.substring(0, opnStart);
+ }
+ }
+ return serviceName;
+ }
+
+ /**
+ * Generates the services list.
+ *
+ * @param response HttpResponse
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param servicePath service path of the service
+ */
+ protected void generateServicesList(HttpResponse response,
+ NHttpServerConnection conn,
+ OutputStream os, String servicePath) {
+ try {
+ byte[] bytes = getServicesHTML(
+ servicePath.endsWith("/") ? "" : servicePath +
"/").getBytes();
+ response.addHeader(CONTENT_TYPE, TEXT_HTML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ os.write(bytes);
+
+ } catch (IOException e) {
+ handleBrowserException(response, conn, os,
+ "Error generating services list", e);
+ }
+ }
+
+ /**
+ * Generates service details page.
+ *
+ * @param response HttpResponse
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param serviceName service name
+ */
+ protected void generateServiceDetailsPage(HttpResponse response,
+ NHttpServerConnection conn,
+ OutputStream os, String
serviceName) {
+ AxisService service = cfgCtx.getAxisConfiguration().
+ getServices().get(serviceName);
+ if (service != null) {
+ String parameterValue = (String)
service.getParameterValue("serviceType");
+ if ("proxy".equals(parameterValue) &&
!isWSDLProvidedForProxyService(service)) {
+ handleBrowserException(response, conn, os,
+ "No WSDL was provided for the Service " + serviceName +
+ ". A WSDL cannot be generated.", null);
+ }
+ try {
+ byte[] bytes =
+ HTTPTransportReceiver.printServiceHTML(serviceName,
cfgCtx).getBytes();
+ response.addHeader(CONTENT_TYPE, TEXT_HTML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ os.write(bytes);
+
+ } catch (IOException e) {
+ handleBrowserException(response, conn, os,
+ "Error generating service details page for : " +
serviceName, e);
+ }
+ } else {
+ handleBrowserException(response, conn, os,
+ "Invalid service : " + serviceName, null);
+ }
+ }
+
+ /**
+ * Generates Schema.
+ *
+ * @param response HttpResponse
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param serviceName service name
+ * @param parameters url parameters
+ */
+ protected void generateXsd(HttpResponse response, NHttpServerConnection
conn,
+ OutputStream os, String serviceName,
+ Map<String, String> parameters) {
+ if (parameters.get("xsd") == null || "".equals(parameters.get("xsd")))
{
+ AxisService service = cfgCtx.getAxisConfiguration()
+ .getServices().get(serviceName);
+ if (service != null) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ service.printSchema(baos);
+ response.addHeader(CONTENT_TYPE, TEXT_XML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ os.write(baos.toByteArray());
+
+ } catch (Exception e) {
+ handleBrowserException(response, conn, os,
+ "Error generating ?xsd output for service : " +
serviceName, e);
+ }
+ }
+
+ } else {
+ //cater for named xsds - check for the xsd name
+ String schemaName = parameters.get("xsd");
+ AxisService service = cfgCtx.getAxisConfiguration()
+ .getServices().get(serviceName);
+
+ if (service != null) {
+ //run the population logic just to be sure
+ service.populateSchemaMappings();
+ //write out the correct schema
+ Map schemaTable = service.getSchemaMappingTable();
+ XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
+ if (schema == null) {
+ int dotIndex = schemaName.indexOf('.');
+ if (dotIndex > 0) {
+ String schemaKey = schemaName.substring(0, dotIndex);
+ schema = (XmlSchema) schemaTable.get(schemaKey);
+ }
+ }
+ //schema found - write it to the stream
+ if (schema != null) {
+ try {
+ ByteArrayOutputStream baos = new
ByteArrayOutputStream();
+ schema.write(baos);
+ response.addHeader(CONTENT_TYPE, TEXT_XML);
+ serverHandler.commitResponseHideExceptions(conn,
response);
+ os.write(baos.toByteArray());
+ } catch (Exception e) {
+ handleBrowserException(response, conn, os,
+ "Error generating named ?xsd output for
service : " + serviceName, e);
+ }
+
+ } else {
+ // no schema available by that name - send 404
+ response.setStatusCode(HttpStatus.SC_NOT_FOUND);
+ }
+ }
+ }
+ }
+
+ /**
+ * Generate WSDL2.
+ *
+ * @param request HttpRequest
+ * @param response HttpResponse
+ * @param msgContext MessageContext
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param serviceName service name
+ * @param isRestDispatching weather nhttp should do rest dispatching
+ */
+ protected void generateWsdl2(HttpRequest request, HttpResponse response,
+ MessageContext msgContext,
+ NHttpServerConnection conn,
+ OutputStream os, String serviceName, boolean
isRestDispatching) {
+ AxisService service = cfgCtx.getAxisConfiguration().
+ getServices().get(serviceName);
+ if (service != null) {
+ String parameterValue = (String)
service.getParameterValue("serviceType");
+ if ("proxy".equals(parameterValue) &&
!isWSDLProvidedForProxyService(service)) {
+ handleBrowserException(response, conn, os,
+ "No WSDL was provided for the Service " + serviceName +
+ ". A WSDL cannot be generated.", null);
+ }
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ service.printWSDL2(baos, getIpAddress());
+ response.addHeader(CONTENT_TYPE, TEXT_XML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ os.write(baos.toByteArray());
+
+ } catch (Exception e) {
+ handleBrowserException(response, conn, os,
+ "Error generating ?wsdl2 output for service : " +
serviceName, e);
+ }
+ } else {
+ processGetAndDelete(request, response, msgContext,
+ conn, os, "GET", isRestDispatching);
+ }
+ }
+
+ /**
+ * Generate WSDL.
+ *
+ * @param request HttpRequest
+ * @param response HttpResponse
+ * @param msgContext MessageContext
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param serviceName service name
+ * @param parameters parameters
+ * @param isRestDispatching if restDispatching is on
+ */
+ protected void generateWsdl(HttpRequest request, HttpResponse response,
+ MessageContext msgContext,
+ NHttpServerConnection conn,
+ OutputStream os, String serviceName,
+ Map<String, String> parameters, boolean
isRestDispatching) {
+ AxisService service = cfgCtx.getAxisConfiguration().
+ getServices().get(serviceName);
+ if (service != null) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ String parameterValue = parameters.get("wsdl");
+ if (parameterValue == null) {
+ service.printWSDL(baos, getIpAddress());
+ } else {
+ // here the parameter value should be the wsdl file name
+ service.printUserWSDL(baos, parameterValue);
+ }
+ response.addHeader(CONTENT_TYPE, TEXT_XML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ os.write(baos.toByteArray());
+
+ } catch (Exception e) {
+ handleBrowserException(response, conn, os,
+ "Error generating ?wsdl output for service : " +
serviceName, e);
+ }
+ } else {
+ processGetAndDelete(request, response, msgContext,
+ conn, os, "GET", isRestDispatching);
+ }
+ }
+
+ /**
+ * Calls the RESTUtil to process GET and DELETE Request
+ *
+ * @param request HttpRequest
+ * @param response HttpResponse
+ * @param msgContext MessageContext
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param method HTTP method, either GET or DELETE
+ * @param isRestDispatching weather transport should do rest dispatching
+ */
+ protected void processGetAndDelete(HttpRequest request, HttpResponse
response,
+ MessageContext msgContext,
+ NHttpServerConnection conn,
OutputStream os,
+ String method, boolean
isRestDispatching) {
+ try {
+ RESTUtil.processGetAndDeleteRequest(
+ msgContext, os, request.getRequestLine().getUri(),
+ request.getFirstHeader(HTTP.CONTENT_TYPE), method,
isRestDispatching);
+ // do not let the output stream close (as by default below) since
+ // we are serving this GET/DELETE request through the Synapse
engine
+ } catch (AxisFault axisFault) {
+ handleException(response, msgContext, conn, os,
+ "Error processing " + method + " request for: " +
+ request.getRequestLine().getUri(), axisFault);
+ }
+
+ }
+
+ /**
+ * Handles exception.
+ *
+ * @param response HttpResponse
+ * @param msgContext MessageContext
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param msg message
+ * @param e Exception
+ */
+ protected void handleException(HttpResponse response, MessageContext
msgContext,
+ NHttpServerConnection conn,
+ OutputStream os, String msg, Exception e) {
+ if (e == null) {
+ log.error(msg);
+ } else {
+ log.error(msg, e);
+ }
+
+ if (e == null) {
+ e = new Exception(msg);
+ }
+
+ try {
+ MessageContext faultContext =
MessageContextBuilder.createFaultMessageContext(
+ msgContext, e);
+ AxisEngine.sendFault(faultContext);
+
+ } catch (Exception ex) {
+ response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ response.addHeader(CONTENT_TYPE, TEXT_XML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+
+ try {
+ os.write(msg.getBytes());
+ if (ex != null) {
+ os.write(ex.getMessage().getBytes());
+ }
+ } catch (IOException ignore) {
+ }
+
+ if (conn != null) {
+ try {
+ conn.shutdown();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Handles browser exception.
+ *
+ * @param response HttpResponse
+ * @param conn NHttpServerConnection
+ * @param os OutputStream
+ * @param msg message
+ * @param e Exception
+ */
+ protected void handleBrowserException(HttpResponse response,
+ NHttpServerConnection conn,
OutputStream os,
+ String msg, Exception e) {
+ if (e == null) {
+ log.error(msg);
+ } else {
+ log.error(msg, e);
+ }
+
+ if (!response.containsHeader(HTTP.TRANSFER_ENCODING)) {
+ response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ response.setReasonPhrase(msg);
+ response.addHeader(CONTENT_TYPE, TEXT_HTML);
+ serverHandler.commitResponseHideExceptions(conn, response);
+ try {
+ os.write(msg.getBytes());
+ os.close();
+ } catch (IOException ignore) {
+ }
+ }
+
+ if (conn != null) {
+ try {
+ conn.shutdown();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+
+ /**
+ * Checks whether a wsdl is provided for a proxy service.
+ *
+ * @param service AxisService
+ * @return whether the wsdl is provided or not
+ */
+ protected boolean isWSDLProvidedForProxyService(AxisService service) {
+ boolean isWSDLProvided = false;
+ if (service.getParameterValue(WSDLConstants.WSDL_4_J_DEFINITION) !=
null ||
+ service.getParameterValue(WSDLConstants.WSDL_20_DESCRIPTION)
!= null) {
+ isWSDLProvided = true;
+ }
+ return isWSDLProvided;
+ }
+
+ /**
+ * Whatever this method returns as the IP is ignored by the actual http/s
listener when
+ * its getServiceEPR is invoked. This was originally copied from axis2
+ *
+ * @return Returns String.
+ * @throws java.net.SocketException if the socket can not be accessed
+ */
+ protected static String getIpAddress() throws SocketException {
+ Enumeration e = NetworkInterface.getNetworkInterfaces();
+ String address = "127.0.0.1";
+
+ while (e.hasMoreElements()) {
+ NetworkInterface netface = (NetworkInterface) e.nextElement();
+ Enumeration addresses = netface.getInetAddresses();
+
+ while (addresses.hasMoreElements()) {
+ InetAddress ip = (InetAddress) addresses.nextElement();
+ if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
+ return ip.getHostAddress();
+ }
+ }
+ }
+ return address;
+ }
+
+ protected static boolean isIP(String hostAddress) {
+ return hostAddress.split("[.]").length == 4;
+ }
+
+ /**
+ * Returns the HTML text for the list of services deployed.
+ * This can be delegated to another Class as well
+ * where it will handle more options of GET messages.
+ *
+ * @param prefix to be used for the Service names
+ * @return the HTML to be displayed as a String
+ */
+ protected String getServicesHTML(String prefix) {
+
+ Map services = cfgCtx.getAxisConfiguration().getServices();
+ Hashtable erroneousServices =
cfgCtx.getAxisConfiguration().getFaultyServices();
+ boolean servicesFound = false;
+
+ StringBuffer resultBuf = new StringBuffer();
+ resultBuf.append("<html><head><title>Axis2: Services</title></head>" +
"<body>");
+
+ if ((services != null) && !services.isEmpty()) {
+
+ servicesFound = true;
+ resultBuf.append("<h2>" + "Deployed services" + "</h2>");
+
+ for (Object service : services.values()) {
+
+ AxisService axisService = (AxisService) service;
+ Parameter parameter = axisService.getParameter(
+ NhttpConstants.HIDDEN_SERVICE_PARAM_NAME);
+ if (axisService.getName().startsWith("__") ||
+ (parameter != null &&
JavaUtils.isTrueExplicitly(parameter.getValue()))) {
+ continue; // skip private services
+ }
+
+ Iterator iterator = axisService.getOperations();
+ resultBuf.append("<h3><a
href=\"").append(prefix).append(axisService.getName()).append(
+
"?wsdl\">").append(axisService.getName()).append("</a></h3>");
+
+ if (iterator.hasNext()) {
+ resultBuf.append("Available operations <ul>");
+
+ for (; iterator.hasNext();) {
+ AxisOperation axisOperation = (AxisOperation)
iterator.next();
+ resultBuf.append("<li>").append(
+
axisOperation.getName().getLocalPart()).append("</li>");
+ }
+ resultBuf.append("</ul>");
+ } else {
+ resultBuf.append("No operations specified for this
service");
+ }
+ }
+ }
+
+ if ((erroneousServices != null) && !erroneousServices.isEmpty()) {
+ servicesFound = true;
+ resultBuf.append("<hr><h2><font color=\"blue\">Faulty
Services</font></h2>");
+ Enumeration faultyservices = erroneousServices.keys();
+
+ while (faultyservices.hasMoreElements()) {
+ String faultyserviceName = (String)
faultyservices.nextElement();
+ resultBuf.append("<h3><font color=\"blue\">").append(
+ faultyserviceName).append("</font></h3>");
+ }
+ }
+
+ if (!servicesFound) {
+ resultBuf.append("<h2>There are no services deployed</h2>");
+ }
+
+ resultBuf.append("</body></html>");
+ return resultBuf.toString();
+ }
+
+}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java?rev=1054538&r1=1054537&r2=1054538&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListener.java
Mon Jan 3 07:15:25 2011
@@ -118,6 +118,8 @@ public class HttpCoreNIOListener impleme
private Parser parser = null;
/** if falses we won't dispatch to axis2 service in case of rest scenarios
*/
private boolean restDispatching = true;
+ /** WSDL processor for Get requests*/
+ private HttpGetRequestProcessor httpGetRequestProcessor = null;
protected IOEventDispatch getEventDispatch(
NHttpServiceHandler handler, SSLContext sslContext,
@@ -216,6 +218,36 @@ public class HttpCoreNIOListener impleme
restDispatching = false;
}
}
+
+ // create http Get processor
+ param = transprtIn.getParameter(NhttpConstants.HTTP_GET_PROCESSOR);
+ if (param != null && param.getValue() != null) {
+ httpGetRequestProcessor =
createHttpGetProcessor(param.getValue().toString());
+ } else {
+ httpGetRequestProcessor = new DefaultHttpGetProcessor();
+ }
+ }
+
+ private HttpGetRequestProcessor createHttpGetProcessor(String str) throws
AxisFault {
+ Object obj = null;
+ try {
+ obj = Class.forName(str).newInstance();
+ } catch (ClassNotFoundException e) {
+ handleException("Error creating WSDL processor", e);
+ } catch (InstantiationException e) {
+ handleException("Error creating WSDL processor", e);
+ } catch (IllegalAccessException e) {
+ handleException("Error creating WSDL processor", e);
+ }
+
+ if (obj instanceof HttpGetRequestProcessor) {
+ return (HttpGetRequestProcessor) obj;
+ } else {
+ handleException("Error creating WSDL processor. The HttpProcessor
should be of type " +
+
"org.apache.synapse.transport.nhttp.HttpGetRequestProcessor");
+ }
+
+ return null;
}
public int getActiveConnectionsSize() {
@@ -368,7 +400,7 @@ public class HttpCoreNIOListener impleme
}
handler = new ServerHandler(cfgCtx, params, sslContext != null
- , metrics, parser, executor, restDispatching);
+ , metrics, parser, executor, restDispatching,
httpGetRequestProcessor);
final IOEventDispatch ioEventDispatch = getEventDispatch(handler,
sslContext, sslIOSessionHandler, params);
state = BaseConstants.STARTED;
Added:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpGetRequestProcessor.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpGetRequestProcessor.java?rev=1054538&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpGetRequestProcessor.java
(added)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/HttpGetRequestProcessor.java
Mon Jan 3 07:15:25 2011
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.transport.nhttp;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.nio.NHttpServerConnection;
+
+import java.io.OutputStream;
+
+/**
+ * This interface is used for plugging in different implementations for
special processing of some
+ * HTTP GET requests.
+ * <p/>
+ * e.g. ?wsdl, ?wsdl2 etc.
+ * <p/>
+ * If you need to handle a special HTTP GET request, you have to write an
implementation of this
+ * interface.
+ */
+public interface HttpGetRequestProcessor {
+ /**
+ * Initialize the HttpGetProcessor
+ * @param cfgCtx servers configuration context
+ * @param serverHandler dispatching handler
+ * @throws AxisFault if an error occurs
+ */
+ void init(ConfigurationContext cfgCtx, ServerHandler serverHandler) throws
AxisFault;
+
+ /**
+ * Process the HTTP GET request.
+ *
+ * @param request The HttpRequest
+ * @param response The HttpResponse
+ * @param msgContext The MessageContext
+ * @param conn The NHttpServerConnection
+ * @param os The OutputStream
+ * @param isRestDispatching Rest dispatching
+ */
+ void process(HttpRequest request,
+ HttpResponse response,
+ MessageContext msgContext,
+ NHttpServerConnection conn,
+ OutputStream os,
+ boolean isRestDispatching);
+
+}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java?rev=1054538&r1=1054537&r2=1054538&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
Mon Jan 3 07:15:25 2011
@@ -128,4 +128,8 @@ public class NhttpConstants {
public static final String NHTTP_INPUT_STREAM = "nhttp.input.stream";
/** Output stram of the message is set to this message context property */
public static final String NHTTP_OUTPUT_STREAM = "nhttp.output.stream";
+
+ /** This constant is used to plugin a custom WSDL processor for Get
requests*/
+ public static final String HTTP_GET_PROCESSOR = "httpGetProcessor";
+
}
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java?rev=1054538&r1=1054537&r2=1054538&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerHandler.java
Mon Jan 3 07:15:25 2011
@@ -102,6 +102,9 @@ public class ServerHandler implements NH
*/
private Parser parser = null;
+ /** WSDL processor for Get requests*/
+ private HttpGetRequestProcessor httpGetRequestProcessor = null;
+
/**
* An executor capable of exucuting the Server Worker according the
priority assigned
* to a particular message
@@ -120,7 +123,8 @@ public class ServerHandler implements NH
public ServerHandler(final ConfigurationContext cfgCtx, final HttpParams
params,
final boolean isHttps, final NhttpMetricsCollector metrics,
- Parser parser, PriorityExecutor executor, boolean restDispatching) {
+ Parser parser, PriorityExecutor executor, boolean restDispatching,
+ HttpGetRequestProcessor httpGetRequestProcessor) {
super();
this.cfgCtx = cfgCtx;
this.params = params;
@@ -147,6 +151,8 @@ public class ServerHandler implements NH
this.executor = executor;
this.parser = parser;
}
+
+ this.httpGetRequestProcessor = httpGetRequestProcessor;
}
/**
@@ -201,7 +207,7 @@ public class ServerHandler implements NH
// hand off processing of the request to a thread off the pool
ServerWorker worker = new ServerWorker(cfgCtx, conn, isHttps,
metrics, this,
- request, is, response, os, restDispatching);
+ request, is, response, os, restDispatching,
httpGetRequestProcessor);
if (workerPool != null) {
workerPool.execute(worker);
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=1054538&r1=1054537&r2=1054538&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
Mon Jan 3 07:15:25 2011
@@ -21,21 +21,15 @@ package org.apache.synapse.transport.nht
import org.apache.axiom.util.UIDGenerator;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisEngine;
import org.apache.axis2.transport.RequestResponseTransport;
import org.apache.axis2.transport.base.MetricsCollector;
-import org.apache.axis2.transport.http.HTTPTransportReceiver;
import org.apache.axis2.transport.http.HTTPTransportUtils;
-import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.util.MessageContextBuilder;
-import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.*;
@@ -43,16 +37,14 @@ import org.apache.http.nio.NHttpServerCo
import org.apache.http.protocol.HTTP;
import org.apache.synapse.transport.nhttp.util.NhttpUtil;
import org.apache.synapse.transport.nhttp.util.RESTUtil;
-import org.apache.ws.commons.schema.XmlSchema;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.*;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.TreeMap;
/**
* Processes an incoming request through Axis2. An instance of this class
would be created to
@@ -84,6 +76,8 @@ public class ServerWorker implements Run
private MetricsCollector metrics = null;
/** Weather we should do rest dispatching or not */
private boolean isRestDispatching = true;
+ /** WSDL processor for Get requests */
+ private HttpGetRequestProcessor httpGetRequestProcessor = null;
private static final String SOAPACTION = "SOAPAction";
private static final String LOCATION = "Location";
@@ -118,7 +112,8 @@ public class ServerWorker implements Run
final ServerHandler serverHandler,
final HttpRequest request, final InputStream is,
final HttpResponse response, final OutputStream os,
- final boolean isRestDispatching) {
+ final boolean isRestDispatching,
+ final HttpGetRequestProcessor httpGetRequestProcessor) {
this.cfgCtx = cfgCtx;
this.conn = conn;
@@ -131,6 +126,7 @@ public class ServerWorker implements Run
this.os = os;
this.msgContext = createMessageContext(request);
this.isRestDispatching = isRestDispatching;
+ this.httpGetRequestProcessor = httpGetRequestProcessor;
}
/**
@@ -261,8 +257,9 @@ public class ServerWorker implements Run
}
msgContext.setProperty(NhttpConstants.SERVICE_PREFIX, servicePrefix);
- if ("GET".equals(method)) {
- processGet();
+ if ("GET".equals(method)) {
+ httpGetRequestProcessor.process(request, response,
+ msgContext, conn, os, isRestDispatching);
} else if ("POST".equals(method)) {
processEntityEnclosingMethod();
} else if ("PUT".equals(method)) {
@@ -451,229 +448,6 @@ public class ServerWorker implements Run
}
}
- /**
- *
- */
- private void processGet() {
-
- String uri = request.getRequestLine().getUri();
-
- String servicePath = cfgCtx.getServiceContextPath();
- if (!servicePath.startsWith("/")) {
- servicePath = "/" + servicePath;
- }
-
- String serviceName = null;
- if (uri.startsWith(servicePath)) {
- serviceName = uri.substring(servicePath.length());
- if (serviceName.startsWith("/")) {
- serviceName = serviceName.substring(1);
- }
- if (serviceName.indexOf("?") != -1) {
- serviceName = serviceName.substring(0,
serviceName.indexOf("?"));
- }
- }
-
- if (serviceName != null) {
- int opnStart = serviceName.indexOf("/");
- if (opnStart != -1) {
- serviceName = serviceName.substring(0, opnStart);
- }
- }
-
- Map<String, String> parameters = new HashMap<String, String>();
- int pos = uri.indexOf("?");
- if (pos != -1) {
- msgContext.setTo(new EndpointReference(uri.substring(0, pos)));
- StringTokenizer st = new StringTokenizer(uri.substring(pos+1),
"&");
- while (st.hasMoreTokens()) {
- String param = st.nextToken();
- pos = param.indexOf("=");
- if (pos != -1) {
- parameters.put(param.substring(0, pos),
param.substring(pos+1));
- } else {
- parameters.put(param, null);
- }
- }
- } else {
- msgContext.setTo(new EndpointReference(uri));
- }
-
- if (uri.equals("/favicon.ico")) {
- response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
- response.addHeader(LOCATION, "http://ws.apache.org/favicon.ico");
- serverHandler.commitResponseHideExceptions(conn, response);
-
-// } else if (!uri.startsWith(servicePath)) {
-// response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
-// response.addHeader(LOCATION, servicePath + "/");
-// serverHandler.commitResponseHideExceptions(conn, response);
-
- } else if (serviceName != null && parameters.containsKey("wsdl")) {
- AxisService service = cfgCtx.getAxisConfiguration().
- getServices().get(serviceName);
- if (service != null) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- String parameterValue = parameters.get("wsdl");
- if (parameterValue == null) {
- service.printWSDL(baos, getIpAddress());
- } else {
- // here the parameter value should be the wsdl file
name
- service.printUserWSDL(baos, parameterValue);
- }
- response.addHeader(CONTENT_TYPE, TEXT_XML);
- serverHandler.commitResponseHideExceptions(conn, response);
- os.write(baos.toByteArray());
-
- } catch (Exception e) {
- handleBrowserException(
- "Error generating ?wsdl output for service : " +
serviceName, e);
- return;
- }
- } else {
- processGetAndDelete("GET");
- return;
- }
-
- } else if (serviceName != null && parameters.containsKey("wsdl2")) {
- AxisService service = cfgCtx.getAxisConfiguration().
- getServices().get(serviceName);
- if (service != null) {
- String parameterValue = (String)
service.getParameterValue("serviceType");
- if ("proxy".equals(parameterValue) &&
!isWSDLProvidedForProxyService(service)) {
- handleBrowserException("No WSDL was provided for the
Service " + serviceName +
- ". A WSDL cannot be generated.", null);
- return;
- }
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- service.printWSDL2(baos, getIpAddress());
- response.addHeader(CONTENT_TYPE, TEXT_XML);
- serverHandler.commitResponseHideExceptions(conn, response);
- os.write(baos.toByteArray());
-
- } catch (Exception e) {
- handleBrowserException(
- "Error generating ?wsdl2 output for service : " +
serviceName, e);
- return;
- }
- } else {
- processGetAndDelete("GET");
- return;
- }
-
- } else if (serviceName != null && parameters.containsKey("xsd")) {
- if (parameters.get("xsd") == null ||
"".equals(parameters.get("xsd"))) {
- AxisService service = cfgCtx.getAxisConfiguration()
- .getServices().get(serviceName);
- if (service != null) {
- try {
- ByteArrayOutputStream baos = new
ByteArrayOutputStream();
- service.printSchema(baos);
- response.addHeader(CONTENT_TYPE, TEXT_XML);
- serverHandler.commitResponseHideExceptions(conn,
response);
- os.write(baos.toByteArray());
-
- } catch (Exception e) {
- handleBrowserException(
- "Error generating ?xsd output for service : " +
serviceName, e);
- return;
- }
- }
-
- } else {
- //cater for named xsds - check for the xsd name
- String schemaName = parameters.get("xsd");
- AxisService service = cfgCtx.getAxisConfiguration()
- .getServices().get(serviceName);
-
- if (service != null) {
- //run the population logic just to be sure
- service.populateSchemaMappings();
- //write out the correct schema
- Map schemaTable = service.getSchemaMappingTable();
- XmlSchema schema = (XmlSchema)schemaTable.get(schemaName);
- if (schema == null) {
- int dotIndex = schemaName.indexOf('.');
- if (dotIndex > 0) {
- String schemaKey =
schemaName.substring(0,dotIndex);
- schema = (XmlSchema) schemaTable.get(schemaKey);
- }
- }
- //schema found - write it to the stream
- if (schema != null) {
- try {
- ByteArrayOutputStream baos = new
ByteArrayOutputStream();
- schema.write(baos);
- response.addHeader(CONTENT_TYPE, TEXT_XML);
- serverHandler.commitResponseHideExceptions(conn,
response);
- os.write(baos.toByteArray());
- } catch (Exception e) {
- handleBrowserException(
- "Error generating named ?xsd output for
service : " + serviceName, e);
- return;
- }
-
- } else {
- // no schema available by that name - send 404
- response.setStatusCode(HttpStatus.SC_NOT_FOUND);
- }
- }
- }
-
- }
- else if (serviceName != null && parameters.containsKey("info")) {
- AxisService service = cfgCtx.getAxisConfiguration().
- getServices().get(serviceName);
- if (service != null) {
- String parameterValue = (String)
service.getParameterValue("serviceType");
- if ("proxy".equals(parameterValue) &&
!isWSDLProvidedForProxyService(service)) {
- handleBrowserException("No WSDL was provided for the
Service " + serviceName +
- ". A WSDL cannot be generated.", null);
- return;
- }
- try {
- byte[] bytes =
- HTTPTransportReceiver.printServiceHTML(serviceName,
cfgCtx).getBytes();
- response.addHeader(CONTENT_TYPE, TEXT_HTML);
- serverHandler.commitResponseHideExceptions(conn, response);
- os.write(bytes);
-
- } catch (IOException e) {
- handleBrowserException(
- "Error generating service details page for : " +
serviceName, e);
- return;
- }
- } else {
- handleBrowserException("Invalid service : " + serviceName,
null);
- return;
- }
- } else if (uri.startsWith(servicePath) &&
- (serviceName == null || serviceName.length() == 0)) {
-
- try {
- byte[] bytes = getServicesHTML(
- servicePath.endsWith("/") ? "" : servicePath +
"/").getBytes();
- response.addHeader(CONTENT_TYPE, TEXT_HTML);
- serverHandler.commitResponseHideExceptions(conn, response);
- os.write(bytes);
-
- } catch (IOException e) {
- handleBrowserException("Error generating services list", e);
- }
-
- } else {
- processGetAndDelete("GET");
- return;
- }
-
- // make sure that the output stream is flushed and closed properly
- try {
- os.flush();
- os.close();
- } catch (IOException ignore) {}
- }
/**
* Calls the RESTUtil to process GET and DELETE Request
@@ -694,32 +468,6 @@ public class ServerWorker implements Run
}
- private void handleBrowserException(String msg, Exception e) {
-
- if (e == null) {
- log.error(msg);
- } else {
- log.error(msg, e);
- }
-
- if (!response.containsHeader(HTTP.TRANSFER_ENCODING)) {
- response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- response.setReasonPhrase(msg);
- response.addHeader(CONTENT_TYPE, TEXT_HTML);
- serverHandler.commitResponseHideExceptions(conn, response);
- try {
- os.write(msg.getBytes());
- os.close();
- } catch (IOException ignore) {}
- }
-
- if (conn != null) {
- try {
- conn.shutdown();
- } catch (IOException ignore) {}
- }
- }
-
private void handleException(String msg, Exception e) {
if (e == null) {
@@ -757,15 +505,6 @@ public class ServerWorker implements Run
}
}
- private boolean isWSDLProvidedForProxyService(AxisService service) {
- boolean isWSDLProvided = false;
- if (service.getParameterValue(WSDLConstants.WSDL_4_J_DEFINITION) !=
null ||
- service.getParameterValue(WSDLConstants.WSDL_20_DESCRIPTION)
!= null) {
- isWSDLProvided = true;
- }
- return isWSDLProvided;
- }
-
public HttpResponse getResponse() {
return response;
}
@@ -790,103 +529,4 @@ public class ServerWorker implements Run
return remoteAddress;
}
- /**
- * Whatever this method returns as the IP is ignored by the actual http/s
listener when
- * its getServiceEPR is invoked. This was originally copied from axis2
- *
- * @return Returns String.
- * @throws java.net.SocketException if the socket can not be accessed
- */
- private static String getIpAddress() throws SocketException {
- Enumeration e = NetworkInterface.getNetworkInterfaces();
- String address = "127.0.0.1";
-
- while (e.hasMoreElements()) {
- NetworkInterface netface = (NetworkInterface) e.nextElement();
- Enumeration addresses = netface.getInetAddresses();
-
- while (addresses.hasMoreElements()) {
- InetAddress ip = (InetAddress) addresses.nextElement();
- if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
- return ip.getHostAddress();
- }
- }
- }
- return address;
- }
-
- private static boolean isIP(String hostAddress) {
- return hostAddress.split("[.]").length == 4;
- }
-
- /**
- * Returns the HTML text for the list of services deployed.
- * This can be delegated to another Class as well
- * where it will handle more options of GET messages.
- *
- * @param prefix to be used for the Service names
- * @return the HTML to be displayed as a String
- */
- public String getServicesHTML(String prefix) {
-
- Map services = cfgCtx.getAxisConfiguration().getServices();
- Hashtable erroneousServices =
cfgCtx.getAxisConfiguration().getFaultyServices();
- boolean servicesFound = false;
-
- StringBuffer resultBuf = new StringBuffer();
- resultBuf.append("<html><head><title>Axis2: Services</title></head>" +
"<body>");
-
- if ((services != null) && !services.isEmpty()) {
-
- servicesFound = true;
- resultBuf.append("<h2>" + "Deployed services" + "</h2>");
-
- for (Object service : services.values()) {
-
- AxisService axisService = (AxisService) service;
- Parameter parameter = axisService.getParameter(
- NhttpConstants.HIDDEN_SERVICE_PARAM_NAME);
- if (axisService.getName().startsWith("__") ||
- (parameter != null &&
JavaUtils.isTrueExplicitly(parameter.getValue()))) {
- continue; // skip private services
- }
-
- Iterator iterator = axisService.getOperations();
- resultBuf.append("<h3><a
href=\"").append(prefix).append(axisService.getName()).append(
-
"?wsdl\">").append(axisService.getName()).append("</a></h3>");
-
- if (iterator.hasNext()) {
- resultBuf.append("Available operations <ul>");
-
- for (; iterator.hasNext();) {
- AxisOperation axisOperation = (AxisOperation)
iterator.next();
- resultBuf.append("<li>").append(
-
axisOperation.getName().getLocalPart()).append("</li>");
- }
- resultBuf.append("</ul>");
- } else {
- resultBuf.append("No operations specified for this
service");
- }
- }
- }
-
- if ((erroneousServices != null) && !erroneousServices.isEmpty()) {
- servicesFound = true;
- resultBuf.append("<hr><h2><font color=\"blue\">Faulty
Services</font></h2>");
- Enumeration faultyservices = erroneousServices.keys();
-
- while (faultyservices.hasMoreElements()) {
- String faultyserviceName = (String)
faultyservices.nextElement();
- resultBuf.append("<h3><font color=\"blue\">").append(
- faultyserviceName).append("</font></h3>");
- }
- }
-
- if (!servicesFound) {
- resultBuf.append("<h2>There are no services deployed</h2>");
- }
-
- resultBuf.append("</body></html>");
- return resultBuf.toString();
- }
}