1 16 17 package org.apache.axis.transport.http; 18 19 import java.io.ByteArrayInputStream; 20 import java.io.PrintWriter; 21 import java.util.Enumeration; 22 23 import javax.servlet.http.HttpServletRequest; 24 import javax.servlet.http.HttpServletResponse; 25 26 import org.apache.axis.AxisFault; 27 import org.apache.axis.Message; 28 import org.apache.axis.MessageContext; 29 import org.apache.axis.server.AxisServer; 30 import org.apache.axis.utils.Messages; 31 32 41 42 public class QSMethodHandler extends AbstractQueryStringHandler { 43 44 52 53 public void invoke (MessageContext msgContext) throws AxisFault { 54 57 configureFromContext(msgContext); 58 AxisServer engine = (AxisServer) msgContext.getProperty 59 (HTTPConstants.PLUGIN_ENGINE); 60 PrintWriter writer = (PrintWriter) msgContext.getProperty 61 (HTTPConstants.PLUGIN_WRITER); 62 HttpServletRequest request = (HttpServletRequest) 63 msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETREQUEST); 64 HttpServletResponse response = (HttpServletResponse) 65 msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE); 66 67 68 String method = null; 69 String args = ""; 70 Enumeration enum = request.getParameterNames(); 71 72 while (enum.hasMoreElements()) { 73 String param = (String) enum.nextElement(); 74 if (param.equalsIgnoreCase ("method")) { 75 method = request.getParameter (param); 76 } 77 78 else { 79 args += "<" + param + ">" + request.getParameter (param) + 80 "</" + param + ">"; 81 } 82 } 83 84 if (method == null) { 85 response.setContentType ("text/html"); 86 response.setStatus (HttpServletResponse.SC_BAD_REQUEST); 87 88 writer.println ("<h2>" + Messages.getMessage ("error00") + 89 ": " + Messages.getMessage ("invokeGet00") + "</h2>"); 90 writer.println ("<p>" + Messages.getMessage ("noMethod01") + 91 "</p>"); 92 } 93 94 else { 95 invokeEndpointFromGet (msgContext, response, writer, method, args); 96 } 97 } 98 99 111 112 private void invokeEndpointFromGet (MessageContext msgContext, 113 HttpServletResponse response, PrintWriter writer, String method, 114 String args) throws AxisFault { 115 String body = "<" + method + ">" + args + "</" + method + ">"; 116 String msgtxt = "<SOAP-ENV:Envelope" + 117 " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 118 "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" + 119 "</SOAP-ENV:Envelope>"; 120 ByteArrayInputStream istream = 121 new ByteArrayInputStream (msgtxt.getBytes()); 122 Message responseMsg = null; 123 124 try { 125 AxisServer engine = (AxisServer) msgContext.getProperty 126 (HTTPConstants.PLUGIN_ENGINE); 127 Message msg = new Message (istream, false); 128 129 msgContext.setRequestMessage (msg); 130 engine.invoke (msgContext); 131 132 responseMsg = msgContext.getResponseMessage(); 133 134 136 response.setHeader ("Cache-Control", "no-cache"); 137 response.setHeader ("Pragma", "no-cache"); 138 139 if (responseMsg == null) { 140 142 throw new Exception (Messages.getMessage ("noResponse01")); 143 } 144 145 } 146 147 catch (AxisFault fault) { 148 processAxisFault (fault); 149 150 configureResponseFromAxisFault (response, fault); 151 152 if (responseMsg == null) { 153 responseMsg = new Message (fault); 154 responseMsg.setMessageContext(msgContext); 155 } 156 } 157 158 catch (Exception e) { 159 response.setStatus (HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 160 responseMsg = convertExceptionToAxisFault (e, responseMsg); 161 } 162 163 166 response.setContentType ("text/xml"); 167 168 writer.println (responseMsg.getSOAPPartAsString()); 169 } 170 171 } 172 | Popular Tags |