📄 simpleaxisworker.java
字号:
if (filePart.startsWith("axis/services/")) { String servicePart = filePart.substring(14); int separator = servicePart.indexOf('/'); if (separator > -1) { msgContext.setProperty("objectID", servicePart.substring(separator + 1)); servicePart = servicePart.substring(0, separator); } msgContext.setTargetService(servicePart); } if (authInfo.length() > 0) { // Process authentication info //authInfo = new StringBuffer("dXNlcjE6cGFzczE="); byte[] decoded = Base64.decode(authInfo.toString()); StringBuffer userBuf = new StringBuffer(); StringBuffer pwBuf = new StringBuffer(); StringBuffer authBuf = userBuf; for (int i = 0; i < decoded.length; i++) { if ((char) (decoded[i] & 0x7f) == ':') { authBuf = pwBuf; continue; } authBuf.append((char) (decoded[i] & 0x7f)); } if (log.isDebugEnabled()) { log.debug(Messages.getMessage("user00", userBuf.toString())); } msgContext.setUsername(userBuf.toString()); msgContext.setPassword(pwBuf.toString()); } // if get, then return simpleton document as response if (httpRequest.toString().equals("GET")) { OutputStream out = socket.getOutputStream(); out.write(HTTP); if(fileName.length()==0) { out.write("301 Redirect\nLocation: /axis/\n\n".getBytes()); out.flush(); return; } out.write(status); if (methodName != null) { String body = "<" + methodName + ">" +// args + "</" + methodName + ">"; String msgtxt = "<SOAP-ENV:Envelope" + " xmlns:SOAP-ENV=\"" + Constants.URI_SOAP12_ENV + "\">" + "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>"; ByteArrayInputStream istream = new ByteArrayInputStream(msgtxt.getBytes()); requestMsg = new Message(istream); } else if (doWsdl) { engine.generateWSDL(msgContext); Document doc = (Document) msgContext.getProperty("WSDL"); if (doc != null) { XMLUtils.normalize(doc.getDocumentElement()); String response = XMLUtils.PrettyDocumentToString(doc); byte[] respBytes = response.getBytes(); out.write(XML_MIME_STUFF); putInt(buf, out, respBytes.length); out.write(SEPARATOR); out.write(respBytes); out.flush(); return; } } else { StringBuffer sb = new StringBuffer(); sb.append("<h2>And now... Some Services</h2>\n"); Iterator i = engine.getConfig().getDeployedServices(); sb.append("<ul>\n"); while (i.hasNext()) { ServiceDesc sd = (ServiceDesc)i.next(); sb.append("<li>\n"); sb.append(sd.getName()); sb.append(" <a href=\"services/"); sb.append(sd.getName()); sb.append("?wsdl\"><i>(wsdl)</i></a></li>\n"); ArrayList operations = sd.getOperations(); if (!operations.isEmpty()) { sb.append("<ul>\n"); for (Iterator it = operations.iterator(); it.hasNext();) { OperationDesc desc = (OperationDesc) it.next(); sb.append("<li>" + desc.getName()); } sb.append("</ul>\n"); } } sb.append("</ul>\n"); byte [] bytes = sb.toString().getBytes(); out.write(HTML_MIME_STUFF); putInt(buf, out, bytes.length); out.write(SEPARATOR); out.write(bytes); out.flush(); return; } } else { // this may be "" if either SOAPAction: "" or if no SOAPAction at all. // for now, do not complain if no SOAPAction at all String soapActionString = soapAction.toString(); if (soapActionString != null) { msgContext.setUseSOAPAction(true); msgContext.setSOAPActionURI(soapActionString); } requestMsg = new Message(is, false, contentType.toString(), contentLocation.toString() ); } // Transfer HTTP headers to MIME headers for request message. MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders(); for (Iterator i = requestHeaders.getAllHeaders(); i.hasNext(); ) { MimeHeader requestHeader = (MimeHeader) i.next(); requestMimeHeaders.addHeader(requestHeader.getName(), requestHeader.getValue()); } msgContext.setRequestMessage(requestMsg); // put character encoding of request to message context // in order to reuse it during the whole process. String requestEncoding = (String) requestMsg.getProperty(SOAPMessage.CHARACTER_SET_ENCODING); if (requestEncoding != null) { msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); } // set up session, if any if (server.isSessionUsed()) { // did we get a cookie? if (cookie.length() > 0) { cooky = cookie.toString().trim(); } else if (cookie2.length() > 0) { cooky = cookie2.toString().trim(); } // if cooky is null, cook up a cooky if (cooky == null) { // fake one up! // make it be an arbitrarily increasing number // (no this is not thread safe because ++ isn't atomic) int i = SimpleAxisServer.sessionIndex++; cooky = "" + i; } msgContext.setSession(server.createSession(cooky)); } // invoke the Axis engine engine.invoke(msgContext); // Retrieve the response from Axis responseMsg = msgContext.getResponseMessage(); if (responseMsg == null) { status = NOCONTENT; } } catch (Exception e) { AxisFault af; if (e instanceof AxisFault) { af = (AxisFault) e; log.debug(Messages.getMessage("serverFault00"), af); QName faultCode = af.getFaultCode(); if (Constants.FAULT_SOAP12_SENDER.equals(faultCode)) { status = SENDER; } else if ("Server.Unauthorized".equals(af.getFaultCode().getLocalPart())) { status = UNAUTH; // SC_UNAUTHORIZED } else { status = ISE; // SC_INTERNAL_SERVER_ERROR } } else { status = ISE; // SC_INTERNAL_SERVER_ERROR af = AxisFault.makeFault(e); } // There may be headers we want to preserve in the // response message - so if it's there, just add the // FaultElement to it. Otherwise, make a new one. responseMsg = msgContext.getResponseMessage(); if (responseMsg == null) { responseMsg = new Message(af); responseMsg.setMessageContext(msgContext); } else { try { SOAPEnvelope env = responseMsg.getSOAPEnvelope(); env.clearBody(); env.addBodyElement(new SOAPFault((AxisFault) e)); } catch (AxisFault fault) { // Should never reach here! } } } // synchronize the character encoding of request and response String responseEncoding = (String) msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING); if (responseEncoding != null && responseMsg != null) { responseMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, responseEncoding); } // Send it on its way... OutputStream out = socket.getOutputStream(); out.write(HTTP); out.write(status); if (responseMsg != null) { if (server.isSessionUsed() && null != cooky && 0 != cooky.trim().length()) { // write cookie headers, if any // don't sweat efficiency *too* badly // optimize at will StringBuffer cookieOut = new StringBuffer(); cookieOut.append("\r\nSet-Cookie: ") .append(cooky) .append("\r\nSet-Cookie2: ") .append(cooky); // OH, THE HUMILITY! yes this is inefficient. out.write(cookieOut.toString().getBytes()); } //out.write(XML_MIME_STUFF); out.write(("\r\n" + HTTPConstants.HEADER_CONTENT_TYPE + ": " + responseMsg.getContentType(msgContext.getSOAPConstants())).getBytes()); // Writing the length causes the entire message to be decoded twice. //out.write(("\r\n" + HTTPConstants.HEADER_CONTENT_LENGTH + ": " + responseMsg.getContentLength()).getBytes()); // putInt(out, response.length); // Transfer MIME headers to HTTP headers for response message. for (Iterator i = responseMsg.getMimeHeaders().getAllHeaders(); i.hasNext(); ) { MimeHeader responseHeader = (MimeHeader) i.next(); out.write('\r'); out.write('\n'); out.write(responseHeader.getName().getBytes()); out.write(headerEnder); out.write(responseHeader.getValue().getBytes()); } out.write(SEPARATOR); responseMsg.writeTo(out); } // out.write(response); out.flush(); } catch (Exception e) { log.info(Messages.getMessage("exception00"), e); } finally { try { if (socket != null) socket.close(); } catch (Exception e) { } } if (msgContext.getProperty(MessageContext.QUIT_REQUESTED) != null) { // why then, quit! try { server.stop();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -