⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleaxisworker.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * 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 org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.Message;import org.apache.axis.MessageContext;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.encoding.Base64;import org.apache.axis.message.SOAPEnvelope;import org.apache.axis.message.SOAPFault;import org.apache.axis.server.AxisServer;import org.apache.axis.utils.Messages;import org.apache.axis.utils.XMLUtils;import org.apache.axis.utils.NetworkUtils;import org.apache.commons.logging.Log;import org.w3c.dom.Document;import javax.xml.namespace.QName;import javax.xml.soap.MimeHeader;import javax.xml.soap.MimeHeaders;import javax.xml.soap.SOAPMessage;import java.io.OutputStream;import java.io.ByteArrayInputStream;import java.net.Socket;import java.util.ArrayList;import java.util.Iterator;public class SimpleAxisWorker implements Runnable {    protected static Log log =            LogFactory.getLog(SimpleAxisWorker.class.getName());    private SimpleAxisServer server;    private Socket socket;    // Axis specific constants    private static String transportName = "SimpleHTTP";    // HTTP status codes    private static byte OK[] = ("200 " + Messages.getMessage("ok00")).getBytes();    private static byte NOCONTENT[] = ("202 " + Messages.getMessage("ok00") + "\n\n").getBytes();    private static byte UNAUTH[] = ("401 " + Messages.getMessage("unauth00")).getBytes();    private static byte SENDER[] = "400".getBytes();    private static byte ISE[] = ("500 " + Messages.getMessage("internalError01")).getBytes();    // HTTP prefix    private static byte HTTP[] = "HTTP/1.0 ".getBytes();    // Standard MIME headers for XML payload    private static byte XML_MIME_STUFF[] =            ("\r\nContent-Type: text/xml; charset=utf-8\r\n" +            "Content-Length: ").getBytes();    // Standard MIME headers for HTML payload    private static byte HTML_MIME_STUFF[] =            ("\r\nContent-Type: text/html; charset=utf-8\r\n" +            "Content-Length: ").getBytes();    // Mime/Content separator    private static byte SEPARATOR[] = "\r\n\r\n".getBytes();    // Tiddly little response//    private static final String responseStr =//            "<html><head><title>SimpleAxisServer</title></head>" +//            "<body><h1>SimpleAxisServer</h1>" +//            Messages.getMessage("reachedServer00") +//            "</html>";//    private static byte cannedHTMLResponse[] = responseStr.getBytes();    // ASCII character mapping to lower case    private static final byte[] toLower = new byte[256];    static {        for (int i = 0; i < 256; i++) {            toLower[i] = (byte) i;        }        for (int lc = 'a'; lc <= 'z'; lc++) {            toLower[lc + 'A' - 'a'] = (byte) lc;        }    }    // buffer for IO    private static final int BUFSIZ = 4096;    // mime header for content length    private static final byte lenHeader[] = "content-length: ".getBytes();    private static final int lenLen = lenHeader.length;    // mime header for content type    private static final byte typeHeader[] = (HTTPConstants.HEADER_CONTENT_TYPE.toLowerCase() + ": ").getBytes();    private static final int typeLen = typeHeader.length;    // mime header for content location    private static final byte locationHeader[] = (HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase() + ": ").getBytes();    private static final int locationLen = locationHeader.length;    // mime header for soap action    private static final byte actionHeader[] = "soapaction: ".getBytes();    private static final int actionLen = actionHeader.length;    // mime header for cookie    private static final byte cookieHeader[] = "cookie: ".getBytes();    private static final int cookieLen = cookieHeader.length;    // mime header for cookie2    private static final byte cookie2Header[] = "cookie2: ".getBytes();    private static final int cookie2Len = cookie2Header.length;    // HTTP header for authentication    private static final byte authHeader[] = "authorization: ".getBytes();    private static final int authLen = authHeader.length;    // mime header for GET    private static final byte getHeader[] = "GET".getBytes();    // mime header for POST    private static final byte postHeader[] = "POST".getBytes();    // header ender    private static final byte headerEnder[] = ": ".getBytes();    // "Basic" auth string    private static final byte basicAuth[] = "basic ".getBytes();    public SimpleAxisWorker(SimpleAxisServer server, Socket socket) {        this.server = server;        this.socket = socket;    }    /**     * Run method     */     public void run() {        try {            execute();        } finally {            SimpleAxisServer.getPool().workerDone(this, false);        }    }        /**     * The main workhorse method.     */    public void execute () {        byte buf[] = new byte[BUFSIZ];        // create an Axis server        AxisServer engine = server.getAxisServer();        // create and initialize a message context        MessageContext msgContext = new MessageContext(engine);        Message requestMsg = null;        // Reusuable, buffered, content length controlled, InputStream        NonBlockingBufferedInputStream is =                new NonBlockingBufferedInputStream();        // buffers for the headers we care about        StringBuffer soapAction = new StringBuffer();        StringBuffer httpRequest = new StringBuffer();        StringBuffer fileName = new StringBuffer();        StringBuffer cookie = new StringBuffer();        StringBuffer cookie2 = new StringBuffer();        StringBuffer authInfo = new StringBuffer();        StringBuffer contentType = new StringBuffer();        StringBuffer contentLocation = new StringBuffer();        Message responseMsg = null;        // prepare request (do as much as possible while waiting for the        // next connection).  Note the next two statements are commented        // out.  Uncomment them if you experience any problems with not        // resetting state between requests:        //   msgContext = new MessageContext();        //   requestMsg = new Message("", "String");        //msgContext.setProperty("transport", "HTTPTransport");        msgContext.setTransportName(transportName);        responseMsg = null;        try {            // assume the best            byte[] status = OK;            // assume we're not getting WSDL            boolean doWsdl = false;            // cookie for this session, if any            String cooky = null;            String methodName = null;            try {                // wipe cookies if we're doing sessions                if (server.isSessionUsed()) {                    cookie.delete(0, cookie.length());                    cookie2.delete(0, cookie2.length());                }                authInfo.delete(0, authInfo.length());                // read headers                is.setInputStream(socket.getInputStream());                // parse all headers into hashtable                MimeHeaders requestHeaders = new MimeHeaders();                int contentLength = parseHeaders(is, buf, contentType,                        contentLocation, soapAction,                        httpRequest, fileName,                        cookie, cookie2, authInfo, requestHeaders);                is.setContentLength(contentLength);                int paramIdx = fileName.toString().indexOf('?');                if (paramIdx != -1) {                    // Got params                    String params = fileName.substring(paramIdx + 1);                    fileName.setLength(paramIdx);                    log.debug(Messages.getMessage("filename00",                            fileName.toString()));                    log.debug(Messages.getMessage("params00",                            params));                    if ("wsdl".equalsIgnoreCase(params))                        doWsdl = true;                    if (params.startsWith("method=")) {                        methodName = params.substring(7);                    }                }                // Real and relative paths are the same for the                // SimpleAxisServer                msgContext.setProperty(Constants.MC_REALPATH,                        fileName.toString());                msgContext.setProperty(Constants.MC_RELATIVE_PATH,                        fileName.toString());                msgContext.setProperty(Constants.MC_JWS_CLASSDIR,                        "jwsClasses");                msgContext.setProperty(Constants.MC_HOME_DIR, ".");                // !!! Fix string concatenation                String url = "http://" + getLocalHost() + ":" +                        server.getServerSocket().getLocalPort() + "/" +                        fileName.toString();                msgContext.setProperty(MessageContext.TRANS_URL, url);                String filePart = fileName.toString();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -