Index: modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
===================================================================
--- modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java (revision 191121)
+++ modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java (working copy)
@@ -23,6 +23,11 @@
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
import javax.xml.namespace.QName;
@@ -33,7 +38,9 @@
import org.apache.axis.context.ConfigurationContext;
import org.apache.axis.context.ConfigurationContextFactory;
import org.apache.axis.context.MessageContext;
+import org.apache.axis.description.OperationDescription;
import org.apache.axis.description.Parameter;
+import org.apache.axis.description.ServiceDescription;
import org.apache.axis.description.TransportInDescription;
import org.apache.axis.description.TransportOutDescription;
import org.apache.axis.engine.AxisEngine;
@@ -158,22 +165,34 @@
msgContext.setProperty(MessageContext.TRANSPORT_WRITER, out);
msgContext.setProperty(MessageContext.TRANSPORT_READER, in);
HTTPTransportReceiver reciver = new HTTPTransportReceiver();
- msgContext.setEnvelope(
- reciver.checkForMessage(msgContext, configurationContext));
+
+ /*
+ * If the request is a GET request then
+ * process the request and send out HTML
+ * if not get the soap message and process it
+ */
+ Map map = reciver.parseTheHeaders(in,msgContext.isServerSide());
+ if(map.get(HTTPConstants.HTTP_REQ_TYPE).equals(HTTPConstants.HEADER_POST)) {
+ //Handle POST Request
+ msgContext.setEnvelope(
+ reciver.checkForMessage(msgContext, configurationContext, map));
- AxisEngine engine = new AxisEngine(configurationContext);
- engine.receive(msgContext);
+ AxisEngine engine = new AxisEngine(configurationContext);
+ engine.receive(msgContext);
- Object contextWritten =
- msgContext.getProperty(Constants.RESPONSE_WRITTEN);
- if (contextWritten == null
- || !Constants.VALUE_TRUE.equals(contextWritten)) {
- out.write(new String(HTTPConstants.NOCONTENT).toCharArray());
- out.close();
+ Object contextWritten =
+ msgContext.getProperty(Constants.RESPONSE_WRITTEN);
+ if (contextWritten == null
+ || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ out.write(new String(HTTPConstants.NOCONTENT).toCharArray());
+ out.close();
+ }
+
+ log.info("status written");
+ } else if(map.get(HTTPConstants.HTTP_REQ_TYPE).equals(HTTPConstants.HEADER_GET)) {
+ this.handleGETRequest((String)map.get(HTTPConstants.REQUEST_URI), out);
}
-
- log.info("status written");
-
+
}
} catch (Throwable e) {
log.error(e);
@@ -313,4 +332,73 @@
}
}
+ private void handleGETRequest(String reqUri, Writer out) {
+
+ try {
+ out.write(this.getServicesHTML().toCharArray());
+ out.flush();
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * 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 :-?
+ * @return
+ */
+ private String getServicesHTML() {
+ String temp = "";
+ Map services = this.configurationContext.getAxisConfiguration().getServices();
+ Hashtable erroneousServices = this.configurationContext.getAxisConfiguration().getFaulytServices();
+ boolean status = false;
+
+ if(services!= null && !services.isEmpty()) {
+ status = true;
+ Collection serviceCollection = services.values();
+ for(Iterator it = serviceCollection.iterator(); it.hasNext();) {
+ Map operations;
+ Collection operationsList;
+ ServiceDescription axisService = (ServiceDescription) it.next();
+ operations = axisService.getOperations();
+ operationsList = operations.values();
+ temp += "
" + "Deployed services" + "
";
+ temp += "" + axisService.getName().getLocalPart() + "
";
+ if(operationsList.size() > 0) {
+ temp += "Available operations ";
+ for (Iterator iterator1 = operationsList.iterator(); iterator1.hasNext();) {
+ OperationDescription axisOperation = (OperationDescription) iterator1.next();
+ temp += "- " + axisOperation.getName().getLocalPart() + "
";
+ }
+ temp += "
";
+ } else {
+ temp += "No operations speficied for this service";
+ }
+ }
+ }
+
+ if(erroneousServices != null && !erroneousServices.isEmpty()) {
+
+ temp += "
Faulty Services
";
+ status = true;
+ Enumeration faultyservices = erroneousServices.keys();
+ while (faultyservices.hasMoreElements()) {
+ String faultyserviceName = (String) faultyservices.nextElement();
+ temp += "" + faultyserviceName + "
";
+ }
+ }
+
+ if(!status) {
+ temp = "There are no services deployed
";
+ }
+
+ temp = "Axis2: Services" +
+ "" + temp + "";
+
+ return temp;
+ }
+
}
Index: modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
===================================================================
--- modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java (revision 191121)
+++ modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java (working copy)
@@ -145,7 +145,65 @@
throw new AxisFault("Input reader not found");
}
}
+
+ /**
+ * This is to be called when we are certain that the message being processed is a SOAP message
+ * @param msgContext
+ * @param engineContext
+ * @param parsedHeaders
+ * @return
+ * @throws AxisFault
+ */
+ public SOAPEnvelope checkForMessage(MessageContext msgContext, ConfigurationContext engineContext, Map parsedHeaders) throws AxisFault {
+
+ SOAPEnvelope soapEnvelope = null;
+ Reader in = (Reader) msgContext.getProperty(MessageContext.TRANSPORT_READER);
+ if (in != null) {
+ if (HTTPConstants.RESPONSE_ACK_CODE_VAL.equals(parsedHeaders.get(HTTPConstants.RESPONSE_CODE))) {
+ msgContext.setProperty(
+ MessageContext.TRANSPORT_SUCCEED,
+ HTTPConstants.RESPONSE_ACK_CODE_VAL);
+ return soapEnvelope;
+ }
+ msgContext.setWSAAction((String) parsedHeaders.get(HTTPConstants.HEADER_SOAP_ACTION));
+ Utils.configureMessageContextForHTTP(
+ (String) parsedHeaders.get(HTTPConstants.HEADER_CONTENT_TYPE),
+ msgContext.getWSAAction(),
+ msgContext);
+
+ String requestURI = (String) parsedHeaders.get(HTTPConstants.REQUEST_URI);
+ msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
+ //getServiceLookUp(requestURI)));
+
+ // TODO see is it a Service request e.g. WSDL, list ....
+ // TODO take care of the other HTTPHeaders
+ try {
+ //Check for the REST behaviour, if you desire rest beahaviour
+ //put a at the server.xml/client.xml file
+ Object doREST = msgContext.getProperty(Constants.Configuration.DO_REST);
+ XMLStreamReader xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in);
+ StAXBuilder builder = null;
+ SOAPEnvelope envelope = null;
+ if (doREST != null && "true".equals(doREST)) {
+ SOAPFactory soapFactory = new SOAP11Factory();
+ builder = new StAXOMBuilder(xmlreader);
+ builder.setOmbuilderFactory(soapFactory);
+ envelope = soapFactory.getDefaultEnvelope();
+ envelope.getBody().addChild(builder.getDocumentElement());
+ } else {
+ builder = new StAXSOAPModelBuilder(xmlreader);
+ envelope = (SOAPEnvelope) builder.getDocumentElement();
+ }
+ return envelope;
+ } catch (Exception e) {
+ throw new AxisFault(e.getMessage(), e);
+ }
+ } else {
+ throw new AxisFault("Input reader not found");
+ }
+ }
+
/**
* parses following two styles of HTTP stuff
* Server Side
@@ -180,14 +238,21 @@
length = readLine(reader, buf);
if (serverSide) {
if ((buf[0] == 'P') && (buf[1] == 'O') && (buf[2] == 'S') && (buf[3] == 'T')) {
+ map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_POST);
index = 5;
- value = readFirstLineArg(' ');
- map.put(HTTPConstants.REQUEST_URI, value);
- value = readFirstLineArg('\n');
- map.put(HTTPConstants.PROTOCOL_VERSION, value);
+
+ } else if ((buf[0] == 'G') && (buf[1] == 'E') && (buf[2] == 'T')) {
+ map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_GET);
+ index = 4;
+
} else {
- throw new AxisFault("Only the POST requests are supported");
- }
+ throw new AxisFault("Unsupported HTTP request type: Only GET and POST is supported");
+ }
+
+ value = readFirstLineArg(' ');
+ map.put(HTTPConstants.REQUEST_URI, value);
+ value = readFirstLineArg('\n');
+ map.put(HTTPConstants.PROTOCOL_VERSION, value);
} else {
index = 0;
value = readFirstLineArg(' ');
Index: modules/core/src/org/apache/axis/transport/http/HTTPConstants.java
===================================================================
--- modules/core/src/org/apache/axis/transport/http/HTTPConstants.java (revision 191121)
+++ modules/core/src/org/apache/axis/transport/http/HTTPConstants.java (working copy)
@@ -71,6 +71,11 @@
* Field HEADER_POST
*/
public static final String HEADER_POST = "POST";
+
+ /**
+ * Field HEADER_GET
+ */
+ public static final String HEADER_GET = "GET";
/**
* Field HEADER_HOST
@@ -372,4 +377,10 @@
* Field HTTP[]
*/
public static char HTTP[] = "HTTP/1.0 ".toCharArray();
+
+ /**
+ * Field HTTP_REQ_TYPE
+ */
+ public static final String HTTP_REQ_TYPE = "HTTP_REQ_TYPE";
+
}