1 16 17 package org.apache.axis.transport.http; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.lang.reflect.Method ; 23 import java.lang.reflect.InvocationTargetException ; 24 import java.net.HttpURLConnection ; 25 import java.util.ArrayList ; 26 import java.util.Enumeration ; 27 import java.util.Iterator ; 28 29 import javax.servlet.ServletContext ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import javax.servlet.http.HttpUtils ; 34 import javax.xml.soap.MimeHeader ; 35 import javax.xml.soap.MimeHeaders ; 36 import javax.xml.soap.SOAPException ; 37 import javax.xml.soap.SOAPMessage ; 38 39 import org.apache.axis.AxisEngine; 40 import org.apache.axis.AxisFault; 41 import org.apache.axis.ConfigurationException; 42 import org.apache.axis.Constants; 43 import org.apache.axis.Handler; 44 import org.apache.axis.Message; 45 import org.apache.axis.MessageContext; 46 import org.apache.axis.SimpleTargetedChain; 47 import org.apache.axis.client.Service; 48 import org.apache.axis.management.ServiceAdmin; 49 import org.apache.axis.components.logger.LogFactory; 50 import org.apache.axis.description.OperationDesc; 51 import org.apache.axis.description.ServiceDesc; 52 import org.apache.axis.handlers.soap.SOAPService; 53 import org.apache.axis.security.servlet.ServletSecurityProvider; 54 import org.apache.axis.utils.JavaUtils; 55 import org.apache.axis.utils.Messages; 56 import org.apache.axis.utils.XMLUtils; 57 import org.apache.commons.logging.Log; 58 import org.w3c.dom.Element ; 59 60 74 public class AxisServlet extends AxisServletBase { 75 protected static Log log = 76 LogFactory.getLog(AxisServlet.class.getName()); 77 78 81 private static Log tlog = 82 LogFactory.getLog(Constants.TIME_LOG_CATEGORY); 83 84 88 private static Log exceptionLog = 89 LogFactory.getLog(Constants.EXCEPTION_LOG_CATEGORY); 90 91 public static final String INIT_PROPERTY_TRANSPORT_NAME = 92 "transport.name"; 93 94 public static final String INIT_PROPERTY_USE_SECURITY = 95 "use-servlet-security"; 96 public static final String INIT_PROPERTY_ENABLE_LIST = 97 "axis.enableListQuery"; 98 99 public static final String INIT_PROPERTY_JWS_CLASS_DIR = 100 "axis.jws.servletClassDir"; 101 102 public static final String INIT_PROPERTY_DISABLE_SERVICES_LIST = 104 "axis.disableServiceList"; 105 106 public static final String INIT_PROPERTY_SERVICES_PATH = 108 "axis.servicesPath"; 109 110 private String transportName; 112 113 private Handler transport; 114 115 private ServletSecurityProvider securityProvider = null; 116 117 private String servicesPath; 118 119 123 private static boolean isDebug = false; 124 125 130 private boolean enableList = false; 131 132 136 private boolean disableServicesList = false; 137 138 141 private String jwsClassDir = null; 142 protected String getJWSClassDir() {return jwsClassDir; 143 } 144 145 146 149 public AxisServlet() { 150 } 151 152 155 public void init() throws javax.servlet.ServletException { 156 super.init(); 157 ServletContext context = getServletConfig().getServletContext(); 158 159 isDebug = log.isDebugEnabled(); 160 if (isDebug) { 161 log.debug("In servlet init"); 162 } 163 transportName = getOption(context, 164 INIT_PROPERTY_TRANSPORT_NAME, 165 HTTPTransport.DEFAULT_TRANSPORT_NAME); 166 167 if (JavaUtils.isTrueExplicitly(getOption(context, 168 INIT_PROPERTY_USE_SECURITY, null))) { 169 securityProvider = new ServletSecurityProvider(); 170 } 171 172 enableList = 173 JavaUtils.isTrueExplicitly(getOption(context, 174 INIT_PROPERTY_ENABLE_LIST, null)); 175 176 jwsClassDir = getOption(context, INIT_PROPERTY_JWS_CLASS_DIR, null); 177 178 disableServicesList = JavaUtils.isTrue(getOption(context, 180 INIT_PROPERTY_DISABLE_SERVICES_LIST, "false")); 181 182 servicesPath = getOption(context, INIT_PROPERTY_SERVICES_PATH, 183 "/services/"); 184 185 192 if (jwsClassDir != null) { 193 if (getHomeDir() != null) { 194 jwsClassDir = getHomeDir() + jwsClassDir; 195 } 196 } else { 197 jwsClassDir = getDefaultJWSClassDir(); 198 } 199 200 initQueryStringHandlers(); 201 202 try { 204 ServiceAdmin.setEngine(this.getEngine(), context.getServerInfo()); 205 } catch (AxisFault af) { 206 exceptionLog.info("Exception setting AxisEngine on ServiceAdmin " + 207 af); 208 } 209 } 210 211 212 220 public void doGet(HttpServletRequest request, HttpServletResponse response) throws 221 ServletException , IOException { 222 if (isDebug) { 223 log.debug("Enter: doGet()"); 224 225 } 226 PrintWriter writer = new FilterPrintWriter(response); 227 228 try { 229 AxisEngine engine = getEngine(); 230 ServletContext servletContext = 231 getServletConfig().getServletContext(); 232 233 String pathInfo = request.getPathInfo(); 234 String realpath = servletContext.getRealPath(request.getServletPath()); 235 if (realpath == null) { 236 realpath = request.getServletPath(); 237 } 238 239 boolean isJWSPage = request.getRequestURI().endsWith(".jws"); 243 if (isJWSPage) { 244 pathInfo = request.getServletPath(); 245 } 246 247 249 if (processQuery(request, response, writer) == true) { 250 return; 251 } 252 253 boolean hasNoPath = (pathInfo == null || pathInfo.equals("")); 254 if (!disableServicesList) { 255 if(hasNoPath) { 256 reportAvailableServices(response, writer, request); 261 } else if (realpath != null) { 262 264 MessageContext msgContext = createMessageContext(engine, 266 request, response); 267 268 String url = HttpUtils.getRequestURL(request).toString(); 281 282 msgContext.setProperty(MessageContext.TRANS_URL, url); 283 284 288 String serviceName; 289 if (pathInfo.startsWith("/")) { 290 serviceName = pathInfo.substring(1); 291 } else { 292 serviceName = pathInfo; 293 } 294 295 SOAPService s = engine.getService(serviceName); 296 if (s == null) { 297 if (isJWSPage) { 299 reportCantGetJWSService(request, response, writer); 300 } else { 301 reportCantGetAxisService(request, response, writer); 302 } 303 304 } else { 305 reportServiceInfo(response, writer, s, serviceName); 307 } 308 } 309 } else { 310 314 response.setContentType("text/html; charset=utf-8"); 315 writer.println("<html><h1>Axis HTTP Servlet</h1>"); 316 writer.println(Messages.getMessage("reachedServlet00")); 317 318 writer.println("<p>" + 319 Messages.getMessage("transportName00", 320 "<b>" + transportName + "</b>")); 321 writer.println("</html>"); 322 } 323 } catch (AxisFault fault) { 324 reportTroubleInGet(fault, response, writer); 325 } catch (Exception e) { 326 reportTroubleInGet(e, response, writer); 327 } finally { 328 writer.close(); 329 if (isDebug) { 330 log.debug("Exit: doGet()"); 331 } 332 } 333 } 334 335 344 private void reportTroubleInGet(Throwable exception, 345 HttpServletResponse response, 346 PrintWriter writer) { 347 response.setContentType("text/html; charset=utf-8"); 348 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 349 writer.println("<h2>" + 350 Messages.getMessage("error00") + 351 "</h2>"); 352 writer.println("<p>" + 353 Messages.getMessage("somethingWrong00") + 354 "</p>"); 355 if (exception instanceof AxisFault) { 356 AxisFault fault = (AxisFault) exception; 357 processAxisFault(fault); 358 writeFault(writer, fault); 359 } else { 360 logException(exception); 361 writer.println("<pre>Exception - " + exception + "<br>"); 362 if (isDevelopment()) { 364 writer.println(JavaUtils.stackToString(exception)); 365 } 366 writer.println("</pre>"); 367 } 368 } 369 370 376 protected void processAxisFault(AxisFault fault) { 377 Element runtimeException = fault.lookupFaultDetail( 379 Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 380 if (runtimeException != null) { 381 exceptionLog.info(Messages.getMessage("axisFault00"), fault); 382 fault.removeFaultDetail(Constants. 384 QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 385 } else if (exceptionLog.isDebugEnabled()) { 386 exceptionLog.debug(Messages.getMessage("axisFault00"), fault); 387 } 388 if (!isDevelopment()) { 390 fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE); 392 } 393 } 394 395 399 protected void logException(Throwable e) { 400 exceptionLog.info(Messages.getMessage("exception00"), e); 401 } 402 403 409 private void writeFault(PrintWriter writer, AxisFault axisFault) { 410 String localizedMessage = XMLUtils.xmlEncodeString(axisFault. 411 getLocalizedMessage()); 412 writer.println("<pre>Fault - " + localizedMessage + "<br>"); 413 writer.println(axisFault.dumpToString()); 414 writer.println("</pre>"); 415 } 416 417 423 424 protected void reportServiceInfo(HttpServletResponse response, 425 PrintWriter writer, SOAPService service, 426 String serviceName) { 427 response.setContentType("text/html; charset=utf-8"); 428 429 writer.println("<h1>" 430 + service.getName() 431 + "</h1>"); 432 writer.println( 433 "<p>" + 434 Messages.getMessage("axisService00") + 435 "</p>"); 436 writer.println( 437 "<i>" + 438 Messages.getMessage("perhaps00") + 439 "</i>"); 440 } 441 442 457 protected void reportNoWSDL(HttpServletResponse res, PrintWriter writer, 458 String moreDetailCode, AxisFault axisFault) { 459 } 460 461 462 471 protected void reportAvailableServices(HttpServletResponse response, 472 PrintWriter writer, 473 HttpServletRequest request) throws 474 ConfigurationException, AxisFault { 475 AxisEngine engine = getEngine(); 476 477 response.setContentType("text/html; charset=utf-8"); 478 writer.println("<h2>And now... Some Services</h2>"); 479 480 Iterator i; 481 try { 482 i = engine.getConfig().getDeployedServices(); 483 } catch (ConfigurationException configException) { 484 if (configException.getContainedException() instanceof AxisFault) { 487 throw (AxisFault) configException.getContainedException(); 488 } else { 489 throw configException; 490 } 491 } 492 String defaultBaseURL = getWebappBase(request) + servicesPath; 495 writer.println("<ul>"); 496 while (i.hasNext()) { 497 ServiceDesc sd = (ServiceDesc) i.next(); 498 StringBuffer sb = new StringBuffer (); 499 sb.append("<li>"); 500 String name = sd.getName(); 501 sb.append(name); 502 sb.append(" <a HREF=\""); 503 String endpointURL = sd.getEndpointURL(); 504 String baseURL = (endpointURL == null) ? defaultBaseURL : 505 endpointURL; 506 sb.append(baseURL); 507 sb.append(name); 508 sb.append("?wsdl\"><i>(wsdl)</i></a></li>"); 509 writer.println(sb.toString()); 510 ArrayList operations = sd.getOperations(); 511 if (!operations.isEmpty()) { 512 writer.println("<ul>"); 513 for (Iterator it = operations.iterator(); it.hasNext(); ) { 514 OperationDesc desc = (OperationDesc) it.next(); 515 writer.println("<li>" + desc.getName()); 516 } 517 writer.println("</ul>"); 518 } 519 } 520 writer.println("</ul>"); 521 } 522 523 529 protected void reportCantGetAxisService(HttpServletRequest request, 530 HttpServletResponse response, 531 PrintWriter writer) { 532 response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 534 response.setContentType("text/html; charset=utf-8"); 535 writer.println("<h2>" + 536 Messages.getMessage("error00") + "</h2>"); 537 writer.println("<p>" + 538 Messages.getMessage("noService06") + 539 "</p>"); 540 } 541 542 548 protected void reportCantGetJWSService(HttpServletRequest request, 549 HttpServletResponse response, 550 PrintWriter writer) { 551 String requestPath = request.getServletPath() + ((request.getPathInfo() != null) ? 555 request.getPathInfo() : ""); 556 String realpath = getServletConfig().getServletContext() 557 .getRealPath(requestPath); 558 log.debug("JWS real path: " + realpath); 559 boolean foundJWSFile = (new File (realpath).exists()) && 560 (realpath.endsWith(Constants. 561 JWS_DEFAULT_FILE_EXTENSION)); 562 response.setContentType("text/html; charset=utf-8"); 563 if (foundJWSFile) { 564 response.setStatus(HttpURLConnection.HTTP_OK); 565 writer.println(Messages.getMessage("foundJWS00") + "<p>"); 566 String url = request.getRequestURI(); 567 String urltext = Messages.getMessage("foundJWS01"); 568 writer.println("<a HREF='" + url + "?wsdl'>" + urltext + "</a>"); 569 } else { 570 response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 571 writer.println(Messages.getMessage("noService06")); 572 } 573 } 574 575 576 584 public void doPost(HttpServletRequest req, HttpServletResponse res) throws 585 ServletException , IOException { 586 long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0; 587 String soapAction = null; 588 MessageContext msgContext = null; 589 if (isDebug) { 590 log.debug("Enter: doPost()"); 591 } 592 if (tlog.isDebugEnabled()) { 593 t0 = System.currentTimeMillis(); 594 } 595 596 Message responseMsg = null; 597 String contentType = null; 598 599 try { 600 AxisEngine engine = getEngine(); 601 602 if (engine == null) { 603 ServletException se = 605 new ServletException (Messages.getMessage("noEngine00")); 606 log.debug("No Engine!", se); 607 throw se; 608 } 609 610 res.setBufferSize(1024 * 8); 612 614 msgContext = createMessageContext(engine, req, res); 615 616 if (securityProvider != null) { 619 if (isDebug) { 620 log.debug("securityProvider:" + securityProvider); 621 } 622 msgContext.setProperty(MessageContext.SECURITY_PROVIDER, 623 securityProvider); 624 } 625 626 628 Message requestMsg = 629 new Message (req.getInputStream(), 630 false, 631 req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE), 632 req.getHeader(HTTPConstants. 633 HEADER_CONTENT_LOCATION)); 634 MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders(); 636 for (Enumeration e = req.getHeaderNames(); e.hasMoreElements(); ) { 637 String headerName = (String ) e.nextElement(); 638 for (Enumeration f = req.getHeaders(headerName); 639 f.hasMoreElements(); ) { 640 String headerValue = (String ) f.nextElement(); 641 requestMimeHeaders.addHeader(headerName, headerValue); 642 } 643 } 644 645 if (isDebug) { 646 log.debug("Request Message:" + requestMsg); 647 648 649 650 } 651 msgContext.setRequestMessage(requestMsg); 652 String url = HttpUtils.getRequestURL(req).toString(); 653 msgContext.setProperty(MessageContext.TRANS_URL, url); 654 String requestEncoding; 657 try { 658 requestEncoding = (String ) requestMsg.getProperty(SOAPMessage. 659 CHARACTER_SET_ENCODING); 660 if (requestEncoding != null) { 661 msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, 662 requestEncoding); 663 } 664 } catch (SOAPException e1) { 665 } 666 667 try { 668 676 678 soapAction = getSoapAction(req); 679 680 if (soapAction != null) { 681 msgContext.setUseSOAPAction(true); 682 msgContext.setSOAPActionURI(soapAction); 683 } 684 685 msgContext.setSession(new AxisHttpSession(req)); 689 690 if (tlog.isDebugEnabled()) { 691 t1 = System.currentTimeMillis(); 692 } 693 694 695 if (isDebug) { 696 log.debug("Invoking Axis Engine."); 697 } 699 engine.invoke(msgContext); 700 if (isDebug) { 701 log.debug("Return from Axis Engine."); 702 } 703 if (tlog.isDebugEnabled()) { 704 t2 = System.currentTimeMillis(); 705 } 706 responseMsg = msgContext.getResponseMessage(); 707 708 } catch (AxisFault fault) { 714 processAxisFault(fault); 716 configureResponseFromAxisFault(res, fault); 717 responseMsg = msgContext.getResponseMessage(); 718 if (responseMsg == null) { 719 responseMsg = new Message (fault); 720 ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()). 721 getMessage().setMessageContext(msgContext); 722 } 723 } catch (Exception e) { 724 responseMsg = msgContext.getResponseMessage(); 726 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 727 responseMsg = convertExceptionToAxisFault(e, responseMsg); 728 ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()). 729 getMessage().setMessageContext(msgContext); 730 } catch (Throwable t) { 731 logException(t); 732 responseMsg = msgContext.getResponseMessage(); 734 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 735 responseMsg = new Message (new AxisFault(t.toString(),t)); 736 ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()). 737 getMessage().setMessageContext(msgContext); 738 } 739 } catch (AxisFault fault) { 740 processAxisFault(fault); 741 configureResponseFromAxisFault(res, fault); 742 responseMsg = msgContext.getResponseMessage(); 743 if (responseMsg == null) { 744 responseMsg = new Message (fault); 745 ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()). 746 getMessage().setMessageContext(msgContext); 747 } 748 } 749 750 if (tlog.isDebugEnabled()) { 751 t3 = System.currentTimeMillis(); 752 } 753 754 755 756 if (responseMsg != null) { 757 MimeHeaders responseMimeHeaders = responseMsg.getMimeHeaders(); 759 for (Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) { 760 MimeHeader responseMimeHeader = (MimeHeader ) i.next(); 761 res.addHeader(responseMimeHeader.getName(), 762 responseMimeHeader.getValue()); 763 } 764 String responseEncoding = (String ) msgContext.getProperty( 766 SOAPMessage.CHARACTER_SET_ENCODING); 767 if (responseEncoding != null) { 768 try { 769 responseMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, 770 responseEncoding); 771 } catch (SOAPException e) { 772 } 773 } 774 contentType = responseMsg.getContentType(msgContext. 776 getSOAPConstants()); 777 sendResponse(contentType, res, responseMsg); 778 } else { 779 res.setStatus(202); 781 } 782 783 if (isDebug) { 784 log.debug("Response sent."); 785 log.debug("Exit: doPost()"); 786 } 787 if (tlog.isDebugEnabled()) { 788 t4 = System.currentTimeMillis(); 789 tlog.debug("axisServlet.doPost: " + soapAction + 790 " pre=" + (t1 - t0) + 791 " invoke=" + (t2 - t1) + 792 " post=" + (t3 - t2) + 793 " send=" + (t4 - t3) + 794 " " + msgContext.getTargetService() + "." + 795 ((msgContext.getOperation() == null) ? 796 "" : msgContext.getOperation().getName())); 797 } 798 799 } 800 801 807 private void configureResponseFromAxisFault(HttpServletResponse response, 808 AxisFault fault) { 809 int status = getHttpServletResponseStatus(fault); 813 if (status == HttpServletResponse.SC_UNAUTHORIZED) { 814 response.setHeader("WWW-Authenticate", "Basic realm=\"AXIS\""); 817 } 818 response.setStatus(status); 819 } 820 821 831 private Message convertExceptionToAxisFault(Exception exception, 832 Message responseMsg) { 833 logException(exception); 834 if (responseMsg == null) { 835 AxisFault fault = AxisFault.makeFault(exception); 836 processAxisFault(fault); 837 responseMsg = new Message (fault); 838 } 839 return responseMsg; 840 } 841 842 848 protected int getHttpServletResponseStatus(AxisFault af) { 849 return af.getFaultCode().getLocalPart().startsWith("Server.Unauth") 852 ? HttpServletResponse.SC_UNAUTHORIZED 853 : HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 854 } 857 858 866 private void sendResponse(String contentType, 867 HttpServletResponse res, 868 Message responseMsg) throws AxisFault, 869 IOException { 870 if (responseMsg == null) { 871 res.setStatus(HttpServletResponse.SC_NO_CONTENT); 872 if (isDebug) { 873 log.debug("NO AXIS MESSAGE TO RETURN!"); 874 } 878 } else { 879 if (isDebug) { 880 log.debug("Returned Content-Type:" + 881 contentType); 882 } 885 886 try { 887 res.setContentType(contentType); 888 889 898 899 902 responseMsg.writeTo(res.getOutputStream()); 903 } catch (SOAPException e) { 904 logException(e); 905 } 906 } 907 908 if (!res.isCommitted()) { 909 res.flushBuffer(); } 911 } 912 913 921 private MessageContext createMessageContext(AxisEngine engine, 922 HttpServletRequest req, 923 HttpServletResponse res) { 924 MessageContext msgContext = new MessageContext(engine); 925 926 String requestPath = getRequestPath(req); 927 928 if (isDebug) { 929 log.debug("MessageContext:" + msgContext); 930 log.debug("HEADER_CONTENT_TYPE:" + 931 req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE)); 932 log.debug("HEADER_CONTENT_LOCATION:" + 933 req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION)); 934 log.debug("Constants.MC_HOME_DIR:" + String.valueOf(getHomeDir())); 935 log.debug("Constants.MC_RELATIVE_PATH:" + requestPath); 936 log.debug("HTTPConstants.MC_HTTP_SERVLETLOCATION:" + 937 String.valueOf(getWebInfPath())); 938 log.debug("HTTPConstants.MC_HTTP_SERVLETPATHINFO:" + 939 req.getPathInfo()); 940 log.debug("HTTPConstants.HEADER_AUTHORIZATION:" + 941 req.getHeader(HTTPConstants.HEADER_AUTHORIZATION)); 942 log.debug("Constants.MC_REMOTE_ADDR:" + req.getRemoteAddr()); 943 log.debug("configPath:" + String.valueOf(getWebInfPath())); 944 } 945 946 947 948 msgContext.setTransportName(transportName); 949 950 951 952 msgContext.setProperty(Constants.MC_JWS_CLASSDIR, jwsClassDir); 953 msgContext.setProperty(Constants.MC_HOME_DIR, getHomeDir()); 954 msgContext.setProperty(Constants.MC_RELATIVE_PATH, requestPath); 955 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLET, this); 956 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, req); 957 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, res); 958 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION, 959 getWebInfPath()); 960 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, 961 req.getPathInfo()); 962 msgContext.setProperty(HTTPConstants.HEADER_AUTHORIZATION, 963 req.getHeader(HTTPConstants.HEADER_AUTHORIZATION)); 964 msgContext.setProperty(Constants.MC_REMOTE_ADDR, req.getRemoteAddr()); 965 966 ServletEndpointContextImpl sec = new ServletEndpointContextImpl(); 968 969 msgContext.setProperty(Constants.MC_SERVLET_ENDPOINT_CONTEXT, sec); 970 971 972 String realpath = getServletConfig().getServletContext() 973 .getRealPath(requestPath); 974 975 if (realpath != null) { 976 msgContext.setProperty(Constants.MC_REALPATH, realpath); 977 } 978 979 msgContext.setProperty(Constants.MC_CONFIGPATH, getWebInfPath()); 980 981 return msgContext; 982 } 983 984 992 private String getSoapAction(HttpServletRequest req) throws AxisFault { 993 String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION); 994 995 if (isDebug) { 996 log.debug("HEADER_SOAP_ACTION:" + soapAction); 997 998 1002 } 1003 if (soapAction == null) { 1004 AxisFault af = new AxisFault("Client.NoSOAPAction", 1005 Messages.getMessage("noHeader00", 1006 "SOAPAction"), 1007 null, null); 1008 1009 exceptionLog.error(Messages.getMessage("genFault00"), af); 1010 1011 throw af; 1012 } 1013 if (soapAction.startsWith("\"") && soapAction.endsWith("\"") 1018 && soapAction.length() >= 2) { 1019 int end = soapAction.length() - 1; 1020 soapAction = soapAction.substring(1, end); 1021 } 1022 1023 if (soapAction.length() == 0) { 1024 soapAction = req.getContextPath(); 1026 } 1027 return soapAction; 1028 } 1029 1030 1035 protected String getDefaultJWSClassDir() { 1036 return (getWebInfPath() == null) 1037 ? null : getWebInfPath() + File.separator + "jwsClasses"; 1039 } 1040 1041 1045 1046 public void initQueryStringHandlers() { 1047 try { 1048 this.transport = getEngine().getTransport(this.transportName); 1049 1050 if (this.transport == null) { 1051 1054 this.transport = new SimpleTargetedChain(); 1055 1056 this.transport.setOption("qs.list", 1057 "org.apache.axis.transport.http.QSListHandler"); 1058 this.transport.setOption("qs.method", 1059 "org.apache.axis.transport.http.QSMethodHandler"); 1060 this.transport.setOption("qs.wsdl", 1061 "org.apache.axis.transport.http.QSWSDLHandler"); 1062 1063 return; 1064 } 1065 1066 else { 1067 1070 boolean defaultQueryStrings = true; 1071 String useDefaults = (String )this.transport.getOption( 1072 "useDefaultQueryStrings"); 1073 1074 if ((useDefaults != null) && 1075 useDefaults.toLowerCase().equals("false")) { 1076 defaultQueryStrings = false; 1077 } 1078 1079 if (defaultQueryStrings == true) { 1080 1082 this.transport.setOption("qs.list", 1083 "org.apache.axis.transport.http.QSListHandler"); 1084 this.transport.setOption("qs.method", 1085 "org.apache.axis.transport.http.QSMethodHandler"); 1086 this.transport.setOption("qs.wsdl", 1087 "org.apache.axis.transport.http.QSWSDLHandler"); 1088 } 1089 } 1090 } 1091 1092 catch (AxisFault e) { 1093 1095 this.transport = new SimpleTargetedChain(); 1096 1097 this.transport.setOption("qs.list", 1098 "org.apache.axis.transport.http.QSListHandler"); 1099 this.transport.setOption("qs.method", 1100 "org.apache.axis.transport.http.QSMethodHandler"); 1101 this.transport.setOption("qs.wsdl", 1102 "org.apache.axis.transport.http.QSWSDLHandler"); 1103 1104 return; 1105 } 1106 } 1107 1108 1115 1116 private boolean processQuery(HttpServletRequest request, 1117 HttpServletResponse response, 1118 PrintWriter writer) throws AxisFault { 1119 1122 String path = request.getServletPath(); 1123 String queryString = request.getQueryString(); 1124 String serviceName; 1125 AxisEngine engine = getEngine(); 1126 Iterator i = this.transport.getOptions().keySet().iterator(); 1127 1128 if (queryString == null) { 1129 return false; 1130 } 1131 1132 String servletURI = request.getContextPath() + path; 1133 String reqURI = request.getRequestURI(); 1134 if (servletURI.length() + 1 < reqURI.length()) { 1136 serviceName = reqURI.substring(servletURI.length() + 1); 1137 } else { 1138 serviceName = ""; 1139 } while (i.hasNext() == true) { 1140 String queryHandler = (String ) i.next(); 1141 1142 if (queryHandler.startsWith("qs.") == true) { 1143 1146 String handlerName = queryHandler.substring 1147 (queryHandler.indexOf(".") + 1). 1148 toLowerCase(); 1149 1150 1154 int length = 0; 1155 boolean firstParamFound = false; 1156 1157 while (firstParamFound == false && length < queryString.length()) { 1158 char ch = queryString.charAt(length++); 1159 1160 if (ch == '&' || ch == '=') { 1161 firstParamFound = true; 1162 1163 --length; 1164 } 1165 } 1166 1167 if (length < queryString.length()) { 1168 queryString = queryString.substring(0, length); 1169 } 1170 1171 if (queryString.toLowerCase().equals(handlerName) == true) { 1172 1174 1177 if (this.transport.getOption(queryHandler).equals("")) { 1178 return false; 1179 } 1180 1181 try { 1182 1185 MessageContext msgContext = createMessageContext(engine, 1186 request, response); 1187 Class plugin = Class.forName((String )this.transport. 1188 getOption(queryHandler)); 1189 Method pluginMethod = plugin.getDeclaredMethod("invoke", 1190 new Class [] {msgContext.getClass()}); 1191 String url = HttpUtils.getRequestURL(request).toString(); 1192 1193 msgContext.setProperty(MessageContext.TRANS_URL, url); 1197 msgContext.setProperty(HTTPConstants. 1198 PLUGIN_SERVICE_NAME, serviceName); 1199 msgContext.setProperty(HTTPConstants.PLUGIN_NAME, 1200 handlerName); 1201 msgContext.setProperty(HTTPConstants. 1202 PLUGIN_IS_DEVELOPMENT, 1203 new Boolean (isDevelopment())); 1204 msgContext.setProperty(HTTPConstants.PLUGIN_ENABLE_LIST, 1205 new Boolean (enableList)); 1206 msgContext.setProperty(HTTPConstants.PLUGIN_ENGINE, 1207 engine); 1208 msgContext.setProperty(HTTPConstants.PLUGIN_WRITER, 1209 writer); 1210 msgContext.setProperty(HTTPConstants.PLUGIN_LOG, log); 1211 msgContext.setProperty(HTTPConstants. 1212 PLUGIN_EXCEPTION_LOG, 1213 exceptionLog); 1214 1215 1217 pluginMethod.invoke(plugin.newInstance(), 1218 new Object [] {msgContext}); 1219 1220 writer.close(); 1221 1222 return true; 1223 } catch (InvocationTargetException ie) { 1224 reportTroubleInGet(ie.getTargetException(), response, 1225 writer); 1226 return true; 1228 } catch (Exception e) { 1229 reportTroubleInGet(e, response, writer); 1230 return true; 1232 } 1233 } 1234 } 1235 } 1236 1237 return false; 1238 } 1239 1240 1249 private static String getRequestPath(HttpServletRequest request) { 1250 return request.getServletPath() + ((request.getPathInfo() != null) ? 1251 request.getPathInfo() : ""); 1252 } 1253} 1254 | Popular Tags |