1 7 package org.jboss.webservice.server; 8 9 11 import org.jboss.axis.AxisEngine; 12 import org.jboss.axis.AxisFault; 13 import org.jboss.axis.MessageContext; 14 import org.jboss.axis.handlers.soap.SOAPService; 15 import org.jboss.logging.Logger; 16 17 import javax.servlet.ServletException ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 23 31 public class ContextServlet extends AbstractServlet 32 { 33 protected final Logger log = Logger.getLogger(ContextServlet.class); 35 36 43 private boolean assertServiceAccess(HttpServletRequest req, HttpServletResponse res) 44 throws IOException 45 { 46 String contextPath = req.getContextPath(); 47 String requestURI = req.getRequestURI(); 48 String pathInfo = req.getPathInfo(); 49 50 if (requestURI.startsWith(contextPath + "/services/") && "/Version".equals(pathInfo) == false) 51 { 52 reportTrouble(new IllegalAccessException (requestURI), res, res.getWriter()); 53 return false; 54 } 55 56 return true; 57 } 58 59 62 public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException 63 { 64 if (assertServiceAccess(req, res) == false) 65 return; 66 67 super.doPost(req, res); 68 } 69 70 73 public void doGet(HttpServletRequest req, HttpServletResponse res) 74 throws ServletException , IOException 75 { 76 if (assertServiceAccess(req, res) == false) 77 return; 78 79 String url = req.getRequestURL().toString(); 80 String queryString = req.getQueryString(); 81 log.debug("doGet: " + url + (queryString != null ? "?" + queryString : "")); 82 83 PrintWriter writer = res.getWriter(); 84 try 85 { 86 AxisEngine engine = getEngine(); 87 88 String serviceName = getServiceName(req); 90 SOAPService service = (serviceName != null ? engine.getService(serviceName) : null); 91 92 boolean wsdlRequested = req.getParameter("wsdl") != null || req.getParameter("WSDL") != null; 93 94 if (!wsdlRequested) 95 { 96 log.debug("Report available services"); 97 98 reportAvailableServices(res, writer, req); 102 return; 103 } 104 105 if (service == null) 106 { 107 log.error("Cannot get axis service: " + serviceName); 108 reportCantGetAxisService(req, res, writer); 109 return; 110 } 111 112 MessageContext msgContext = createMessageContext(engine, req, res); 114 115 if (service != null) 118 msgContext.setTargetService(serviceName); 119 120 String transportURL = getTransportURL(req, serviceName); 121 if (transportURL != null) 122 { 123 msgContext.setProperty(MessageContext.TRANS_URL, transportURL); 124 log.debug("Set transport.url=" + transportURL); 125 } 126 127 if (wsdlRequested) 128 { 129 String wsdlResource = req.getParameter("resource"); 130 if (wsdlResource != null) 131 { 132 log.debug("Process wsdl import request: " + wsdlResource); 133 msgContext.setProperty(MessageContext.WSDLGEN_RESOURCE, wsdlResource); 134 } 135 else 136 { 137 log.debug("Process wsdl request"); 138 } 139 140 processWsdlRequest(msgContext, res, writer); 141 return; 142 } 143 144 log.debug("Report service info"); 146 reportServiceInfo(res, writer, service, serviceName); 147 } 148 catch (AxisFault fault) 149 { 150 reportTrouble(fault, res, writer); 151 } 152 catch (Exception e) 153 { 154 reportTrouble(e, res, writer); 155 } 156 finally 157 { 158 AxisEngine.setCurrentMessageContext(null); 160 writer.close(); 161 } 162 } 163 164 169 protected String getServiceName(HttpServletRequest req) 170 { 171 String serviceName = null; 172 if (req.getRequestURI().equals(req.getContextPath() + "/services/Version")) 173 serviceName = "Version"; 174 175 return serviceName; 176 } 177 } 178 | Popular Tags |