You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by he...@apache.org on 2005/06/20 07:14:37 UTC
svn commit: r191395 - in
/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http:
HTTPConstants.java HTTPTransportReceiver.java SimpleHTTPServer.java
Author: hemapani
Date: Sun Jun 19 22:14:35 2005
New Revision: 191395
URL: http://svn.apache.org/viewcvs?rev=191395&view=rev
Log:
checking in the ruchiths patch
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPConstants.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPConstants.java?rev=191395&r1=191394&r2=191395&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPConstants.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPConstants.java Sun Jun 19 22:14:35 2005
@@ -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";
+
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java?rev=191395&r1=191394&r2=191395&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java Sun Jun 19 22:14:35 2005
@@ -145,6 +145,64 @@
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 <parameter name="doREST" value="true"/> 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
@@ -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(' ');
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java?rev=191395&r1=191394&r2=191395&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java Sun Jun 19 22:14:35 2005
@@ -22,6 +22,11 @@
import java.io.Reader;
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;
@@ -32,7 +37,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;
@@ -157,22 +164,34 @@
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
msgContext.setProperty(MessageContext.TRANSPORT_READER, in);
HTTPTransportReceiver reciver = new HTTPTransportReceiver();
- msgContext.setEnvelope(
- reciver.checkForMessage(msgContext, configurationContext));
-
- 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).getBytes());
- out.close();
+
+ /*
+ * 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);
+
+ Object contextWritten =
+ msgContext.getProperty(Constants.RESPONSE_WRITTEN);
+ if (contextWritten == null
+ || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ out.write(new String(HTTPConstants.NOCONTENT).getBytes());
+ 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);
@@ -312,4 +331,73 @@
}
}
+ private void handleGETRequest(String reqUri, OutputStream out) {
+
+ try {
+ out.write(this.getServicesHTML().getBytes());
+ 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 += "<h2>" + "Deployed services" + "</h2>";
+ temp += "<h3>" + axisService.getName().getLocalPart() + "</h3>";
+ if(operationsList.size() > 0) {
+ temp += "Available operations <ul>";
+ for (Iterator iterator1 = operationsList.iterator(); iterator1.hasNext();) {
+ OperationDescription axisOperation = (OperationDescription) iterator1.next();
+ temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
+ }
+ temp += "</ul>";
+ } else {
+ temp += "No operations speficied for this service";
+ }
+ }
+ }
+
+ if(erroneousServices != null && !erroneousServices.isEmpty()) {
+
+ temp += "<hr><h2><font color=\"blue\">Faulty Services</font></h2>";
+ status = true;
+ Enumeration faultyservices = erroneousServices.keys();
+ while (faultyservices.hasMoreElements()) {
+ String faultyserviceName = (String) faultyservices.nextElement();
+ temp += "<h3><font color=\"blue\">" + faultyserviceName + "</font></h3>";
+ }
+ }
+
+ if(!status) {
+ temp = "<h2>There are no services deployed</h2>";
+ }
+
+ temp = "<html><head><title>Axis2: Services</title></head>" +
+ "<body>" + temp + "</body></html>";
+
+ return temp;
+ }
+
}