📄 axisservlet.java
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed 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.axis.transport.http;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.lang.reflect.Method;import java.lang.reflect.InvocationTargetException;import java.net.HttpURLConnection;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpUtils;import javax.xml.soap.MimeHeader;import javax.xml.soap.MimeHeaders;import javax.xml.soap.SOAPException;import javax.xml.soap.SOAPMessage;import org.apache.axis.AxisEngine;import org.apache.axis.AxisFault;import org.apache.axis.ConfigurationException;import org.apache.axis.Constants;import org.apache.axis.Handler;import org.apache.axis.Message;import org.apache.axis.MessageContext;import org.apache.axis.SimpleTargetedChain;import org.apache.axis.client.Service;import org.apache.axis.management.ServiceAdmin;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.security.servlet.ServletSecurityProvider;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.utils.XMLUtils;import org.apache.commons.logging.Log;import org.w3c.dom.Element;/** * * @author Doug Davis (dug@us.ibm.com) * @author Steve Loughran * xdoclet tags are not active yet; keep web.xml in sync. * To change the location of the services, change url-pattern in web.xml and * set parameter axis.servicesPath in server-config.wsdd. For more information see * <a href="http://ws.apache.org/axis/java/reference.html">Axis Reference Guide</a>. * * @web.servlet name="AxisServlet" display-name="Apache-Axis Servlet" * @web.servlet-mapping url-pattern="/servlet/AxisServlet" * @web.servlet-mapping url-pattern="*.jws" * @web.servlet-mapping url-pattern="/services/*" */public class AxisServlet extends AxisServletBase { protected static Log log = LogFactory.getLog(AxisServlet.class.getName()); /** * this log is for timing */ private static Log tlog = LogFactory.getLog(Constants.TIME_LOG_CATEGORY); /** * a separate log for exceptions lets users route them * differently from general low level debug info */ private static Log exceptionLog = LogFactory.getLog(Constants.EXCEPTION_LOG_CATEGORY); public static final String INIT_PROPERTY_TRANSPORT_NAME = "transport.name"; public static final String INIT_PROPERTY_USE_SECURITY = "use-servlet-security"; public static final String INIT_PROPERTY_ENABLE_LIST = "axis.enableListQuery"; public static final String INIT_PROPERTY_JWS_CLASS_DIR = "axis.jws.servletClassDir"; // This will turn off the list of available services public static final String INIT_PROPERTY_DISABLE_SERVICES_LIST = "axis.disableServiceList"; // Location of the services as defined by the servlet-mapping in web.xml public static final String INIT_PROPERTY_SERVICES_PATH = "axis.servicesPath"; // These have default values. private String transportName; private Handler transport; private ServletSecurityProvider securityProvider = null; private String servicesPath; /** * cache of logging debug option; only evaluated at init time. * So no dynamic switching of logging options with this servlet. */ private static boolean isDebug = false; /** * Should we enable the "?list" functionality on GETs? (off by * default because deployment information is a potential security * hole) */ private boolean enableList = false; /** * Should we turn off the list of services when we receive a GET * at the servlet root? */ private boolean disableServicesList = false; /** * Cached path to JWS output directory */ private String jwsClassDir = null; protected String getJWSClassDir() {return jwsClassDir; } /** * create a new servlet instance */ public AxisServlet() { } /** * Initialization method. */ public void init() throws javax.servlet.ServletException { super.init(); ServletContext context = getServletConfig().getServletContext(); isDebug = log.isDebugEnabled(); if (isDebug) { log.debug("In servlet init"); } transportName = getOption(context, INIT_PROPERTY_TRANSPORT_NAME, HTTPTransport.DEFAULT_TRANSPORT_NAME); if (JavaUtils.isTrueExplicitly(getOption(context, INIT_PROPERTY_USE_SECURITY, null))) { securityProvider = new ServletSecurityProvider(); } enableList = JavaUtils.isTrueExplicitly(getOption(context, INIT_PROPERTY_ENABLE_LIST, null)); jwsClassDir = getOption(context, INIT_PROPERTY_JWS_CLASS_DIR, null); // Should we list services? disableServicesList = JavaUtils.isTrue(getOption(context, INIT_PROPERTY_DISABLE_SERVICES_LIST, "false")); servicesPath = getOption(context, INIT_PROPERTY_SERVICES_PATH, "/services/"); /** * There are DEFINATE problems here if * getHomeDir and/or getDefaultJWSClassDir return null * (as they could with WebLogic). * This needs to be reexamined in the future, but this * should fix any NPE's in the mean time. */ if (jwsClassDir != null) { if (getHomeDir() != null) { jwsClassDir = getHomeDir() + jwsClassDir; } } else { jwsClassDir = getDefaultJWSClassDir(); } initQueryStringHandlers(); // Setup the service admin try { ServiceAdmin.setEngine(this.getEngine(), context.getServerInfo()); } catch (AxisFault af) { exceptionLog.info("Exception setting AxisEngine on ServiceAdmin " + af); } } /** * Process GET requests. This includes handoff of pseudo-SOAP requests * * @param request request in * @param response request out * @throws ServletException * @throws IOException */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (isDebug) { log.debug("Enter: doGet()"); } PrintWriter writer = new FilterPrintWriter(response); try { AxisEngine engine = getEngine(); ServletContext servletContext = getServletConfig().getServletContext(); String pathInfo = request.getPathInfo(); String realpath = servletContext.getRealPath(request.getServletPath()); if (realpath == null) { realpath = request.getServletPath(); } //JWS pages are special; they are the servlet path and there //is no pathinfo...we map the pathinfo to the servlet path to keep //it happy boolean isJWSPage = request.getRequestURI().endsWith(".jws"); if (isJWSPage) { pathInfo = request.getServletPath(); } // Try to execute a query string plugin and return upon success. if (processQuery(request, response, writer) == true) { return; } boolean hasNoPath = (pathInfo == null || pathInfo.equals("")); if (!disableServicesList) { if(hasNoPath) { // If the user requested the servlet (i.e. /axis/servlet/AxisServlet) // with no service name, present the user with a list of deployed // services to be helpful // Don't do this if has been turned off reportAvailableServices(response, writer, request); } else if (realpath != null) { // We have a pathname, so now we perform WSDL or list operations // get message context w/ various properties set MessageContext msgContext = createMessageContext(engine, request, response); // NOTE: HttpUtils.getRequestURL has been deprecated. // This line SHOULD be: // String url = req.getRequestURL().toString() // HOWEVER!!!! DON'T REPLACE IT! There's a bug in // req.getRequestURL that is not in HttpUtils.getRequestURL // req.getRequestURL returns "localhost" in the remote // scenario rather than the actual host name. // // But more importantly, getRequestURL() is a servlet 2.3 // API and to support servlet 2.2 (aka WebSphere 4) // we need to leave this in for a while longer. tomj 10/14/2004 // String url = HttpUtils.getRequestURL(request).toString(); msgContext.setProperty(MessageContext.TRANS_URL, url); // See if we can locate the desired service. If we // can't, return a 404 Not Found. Otherwise, just // print the placeholder message. String serviceName; if (pathInfo.startsWith("/")) { serviceName = pathInfo.substring(1); } else { serviceName = pathInfo; } SOAPService s = engine.getService(serviceName); if (s == null) { //no service: report it if (isJWSPage) { reportCantGetJWSService(request, response, writer); } else { reportCantGetAxisService(request, response, writer); } } else { //print a snippet of service info. reportServiceInfo(response, writer, s, serviceName); } } } else { // We didn't have a real path in the request, so just // print a message informing the user that they reached // the servlet. response.setContentType("text/html; charset=utf-8"); writer.println("<html><h1>Axis HTTP Servlet</h1>"); writer.println(Messages.getMessage("reachedServlet00"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -