1 55 56 package org.jboss.axis.transport.http; 57 58 import java.io.ByteArrayInputStream ; 59 import java.io.File ; 60 import java.io.IOException ; 61 import java.io.InputStream ; 62 import java.io.PrintWriter ; 63 import java.net.HttpURLConnection ; 64 import java.util.ArrayList ; 65 import java.util.Enumeration ; 66 import java.util.Iterator ; 67 import java.util.StringTokenizer ; 68 69 import javax.servlet.ServletContext ; 70 import javax.servlet.ServletException ; 71 import javax.servlet.http.HttpServletRequest ; 72 import javax.servlet.http.HttpServletResponse ; 73 import javax.xml.soap.MimeHeader ; 74 import javax.xml.soap.MimeHeaders ; 75 import javax.xml.soap.SOAPException ; 76 77 import org.jboss.axis.AxisEngine; 78 import org.jboss.axis.AxisFault; 79 import org.jboss.axis.ConfigurationException; 80 import org.jboss.axis.Constants; 81 import org.jboss.axis.Message; 82 import org.jboss.axis.MessageContext; 83 import org.jboss.axis.MessagePart; 84 import org.jboss.axis.description.OperationDesc; 85 import org.jboss.axis.description.ServiceDesc; 86 import org.jboss.axis.handlers.soap.SOAPService; 87 import org.jboss.axis.security.servlet.ServletSecurityProvider; 88 import org.jboss.axis.utils.JavaUtils; 89 import org.jboss.axis.utils.Messages; 90 import org.jboss.axis.utils.XMLUtils; 91 import org.jboss.logging.Logger; 92 import org.w3c.dom.Document ; 93 import org.w3c.dom.Element ; 94 95 99 public class AxisServlet extends AxisServletBase 100 { 101 102 private static Logger log = Logger.getLogger(AxisServlet.class.getName()); 103 104 107 private static Logger tlog = Logger.getLogger(Constants.TIME_LOG_CATEGORY); 108 109 public static final String INIT_PROPERTY_TRANSPORT_NAME = "transport.name"; 110 111 public static final String INIT_PROPERTY_USE_SECURITY = "use-servlet-security"; 112 public static final String INIT_PROPERTY_ENABLE_LIST = "axis.enableListQuery"; 113 114 public static final String INIT_PROPERTY_JWS_CLASS_DIR = "axis.jws.servletClassDir"; 115 116 private String transportName; 118 119 private ServletSecurityProvider securityProvider = null; 120 121 124 private String jwsClassDir = null; 125 126 protected String getJWSClassDir() 127 { 128 return jwsClassDir; 129 } 130 131 132 135 public AxisServlet() 136 { 137 } 138 139 142 public void init() 143 { 144 super.init(); 145 ServletContext context = getServletConfig().getServletContext(); 146 147 148 log.debug("In servlet init"); 149 150 transportName = getOption(context, 151 INIT_PROPERTY_TRANSPORT_NAME, 152 HTTPTransport.DEFAULT_TRANSPORT_NAME); 153 154 if (JavaUtils.isTrueExplicitly(getOption(context, INIT_PROPERTY_USE_SECURITY, null))) 155 { 156 securityProvider = new ServletSecurityProvider(); 157 } 158 159 jwsClassDir = getOption(context, INIT_PROPERTY_JWS_CLASS_DIR, null); 160 161 168 if (jwsClassDir != null) 169 { 170 if (getHomeDir() != null) 171 { 172 jwsClassDir = getHomeDir() + jwsClassDir; 173 } 174 } 175 else 176 { 177 jwsClassDir = getDefaultJWSClassDir(); 178 } 179 } 180 181 182 190 public void doGet(HttpServletRequest request, HttpServletResponse response) 191 throws ServletException , IOException 192 { 193 log.debug("Enter: doGet()"); 194 195 PrintWriter writer = response.getWriter(); 196 197 try 198 { 199 AxisEngine engine = getEngine(); 200 ServletContext servletContext = 201 getServletConfig().getServletContext(); 202 203 String pathInfo = request.getPathInfo(); 204 String realpath = servletContext.getRealPath(request.getServletPath()); 205 if (realpath == null) 206 { 207 realpath = request.getServletPath(); 208 } 209 210 boolean wsdlRequested = false; 211 boolean hasParameters = request.getParameterNames().hasMoreElements(); 212 213 boolean isJWSPage = request.getRequestURI().endsWith(".jws"); 217 if (isJWSPage) 218 { 219 pathInfo = request.getServletPath(); 220 } 221 222 String queryString = request.getQueryString(); 224 if (queryString != null) 225 { 226 if (queryString.equalsIgnoreCase("wsdl")) 227 { 228 wsdlRequested = true; 229 } 230 } 231 232 boolean hasNoPath = (pathInfo == null || pathInfo.equals("")); 233 if (!wsdlRequested && hasNoPath) 234 { 235 reportAvailableServices(response, writer, request); 240 } 241 else if (realpath != null) 242 { 243 245 MessageContext msgContext = createMessageContext(engine, request, response); 247 248 String url = request.getRequestURL().toString(); 249 250 msgContext.setProperty(MessageContext.TRANS_URL, url); 251 252 if (wsdlRequested) 253 { 254 processWsdlRequest(msgContext, response, writer); 256 } 257 else if (hasParameters) 258 { 259 263 processMethodRequest(msgContext, request, response, writer); 264 265 } 266 else 267 { 268 269 273 String serviceName; 274 if (pathInfo.startsWith("/")) 275 { 276 serviceName = pathInfo.substring(1); 277 } 278 else 279 { 280 serviceName = pathInfo; 281 } 282 283 SOAPService s = engine.getService(serviceName); 284 if (s == null) 285 { 286 if (isJWSPage) 288 { 289 reportCantGetJWSService(request, response, writer); 290 } 291 else 292 { 293 reportCantGetAxisService(request, response, writer); 294 } 295 296 } 297 else 298 { 299 reportServiceInfo(response, writer, s, serviceName); 301 } 302 } 303 } 304 else 305 { 306 310 response.setContentType("text/html"); 311 writer.println("<html><h1>Axis HTTP Servlet</h1>"); 312 writer.println(Messages.getMessage("reachedServlet00")); 313 314 writer.println("<p>" + 315 Messages.getMessage("transportName00", 316 "<b>" + transportName + "</b>")); 317 writer.println("</html>"); 318 } 319 } 320 catch (AxisFault fault) 321 { 322 reportTrouble(fault, response, writer); 323 } 324 catch (Exception e) 325 { 326 reportTrouble(e, response, writer); 327 } 328 finally 329 { 330 AxisEngine.setCurrentMessageContext(null); 332 333 writer.close(); 334 log.debug("Exit: doGet()"); 335 } 336 } 337 338 348 protected void reportTrouble(Exception exception, HttpServletResponse response, PrintWriter writer) 349 { 350 response.setContentType("text/html"); 351 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 352 353 setupHTMLResponseHeader(response, writer); 354 355 writer.println("<h2>" + Messages.getMessage("error00") + "</h2>"); 356 writer.println("<p>" + Messages.getMessage("somethingWrong00") + "</p>"); 357 358 if (exception instanceof AxisFault) 359 { 360 AxisFault fault = (AxisFault)exception; 361 processAxisFault(fault); 362 writeFault(writer, fault); 363 } 364 else 365 { 366 logException(exception); 367 writer.println("<pre>" + exception + "<br>"); 368 if (isDevelopment()) 370 { 371 writer.println(JavaUtils.stackToString(exception)); 372 } 373 writer.println("</pre>"); 374 } 375 } 376 377 protected void setupHTMLResponseHeader(HttpServletResponse response, PrintWriter writer) 378 { 379 } 380 381 388 protected void processAxisFault(AxisFault fault) 389 { 390 Element runtimeException = fault.lookupFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 392 if (runtimeException != null) 393 { 394 fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 395 } 396 397 if (!isDevelopment()) 399 { 400 fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE); 402 } 403 404 log.info(fault.detail != null ? fault.detail : fault); 405 } 406 407 412 protected void logException(Exception e) 413 { 414 log.info(Messages.getMessage("exception00"), e); 415 } 416 417 424 private void writeFault(PrintWriter writer, AxisFault axisFault) 425 { 426 String localizedMessage = XMLUtils.xmlEncodeString(axisFault.getLocalizedMessage()); 427 writer.println("<pre>Fault - " + localizedMessage + "<br>"); 428 writer.println(axisFault.dumpToString()); 429 writer.println("</pre>"); 430 } 431 432 443 protected void processMethodRequest(MessageContext msgContext, 444 HttpServletRequest request, 445 HttpServletResponse response, 446 PrintWriter writer) throws AxisFault 447 { 448 Enumeration en = request.getParameterNames(); 449 String method = null; 450 String args = ""; 451 while (en.hasMoreElements()) 452 { 453 String param = (String )en.nextElement(); 454 if (param.equalsIgnoreCase("method")) 455 { 456 method = request.getParameter(param); 457 } 458 else 459 { 460 args += "<" + param + ">" + 461 request.getParameter(param) + 462 "</" + param + ">"; 463 } 464 } 465 466 if (method == null) 467 { 468 response.setContentType("text/html"); 469 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 470 writer.println("<h2>" + 471 Messages.getMessage("error00") + 472 ": " + 473 Messages.getMessage("invokeGet00") + 474 "</h2>"); 475 writer.println("<p>" + 476 Messages.getMessage("noMethod01") + 477 "</p>"); 478 } 479 else 480 { 481 invokeEndpointFromGet(msgContext, response, writer, method, args); 482 483 } 484 } 485 486 495 protected void processWsdlRequest(MessageContext msgContext, 496 HttpServletResponse response, 497 PrintWriter writer) throws AxisFault 498 { 499 AxisEngine engine = getEngine(); 500 try 501 { 502 engine.generateWSDL(msgContext); 503 Document doc = (Document )msgContext.getProperty("WSDL"); 504 if (doc != null) 505 { 506 response.setContentType("text/xml"); 507 XMLUtils.DocumentToWriter(doc, writer); 508 } 509 else 510 { 511 if (log.isDebugEnabled()) 512 { 513 log.debug("processWsdlRequest: failed to create WSDL"); 514 } 515 reportNoWSDL(response, writer, "noWSDL02", null); 516 } 517 } 518 catch (AxisFault axisFault) 519 { 520 if (axisFault.getFaultCode().equals(Constants.QNAME_NO_SERVICE_FAULT_CODE)) 522 { 523 processAxisFault(axisFault); 525 response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 527 reportNoWSDL(response, writer, "noWSDL01", axisFault); 528 } 529 else 530 { 531 throw axisFault; 533 } 534 } 535 } 536 537 550 protected void invokeEndpointFromGet(MessageContext msgContext, 551 HttpServletResponse response, 552 PrintWriter writer, 553 String method, 554 String args) throws AxisFault 555 { 556 String body = 557 "<" + method + ">" + args + "</" + method + ">"; 558 559 String msgtxt = 560 "<SOAP-ENV:Envelope" + 561 " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 562 "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" + 563 "</SOAP-ENV:Envelope>"; 564 565 Message responseMsg = null; 566 try 567 { 568 ByteArrayInputStream istream = 569 new ByteArrayInputStream (msgtxt.getBytes(XMLUtils.httpAuthCharEncoding)); 570 571 AxisEngine engine = getEngine(); 572 Message msg = new Message(istream, false); 573 msgContext.setRequestMessage(msg); 574 engine.invoke(msgContext); 575 responseMsg = msgContext.getResponseMessage(); 576 response.setHeader("Cache-Control", "no-cache"); 578 response.setHeader("Pragma", "no-cache"); 579 if (responseMsg == null) 580 { 581 throw new Exception (Messages.getMessage("noResponse01")); 583 } 584 } 585 catch (AxisFault fault) 586 { 587 processAxisFault(fault); 588 configureResponseFromAxisFault(response, fault); 589 if (responseMsg == null) 590 { 591 responseMsg = new Message(fault); 592 msgContext.setResponseMessage(responseMsg); 593 } 594 } 595 catch (Exception e) 596 { 597 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 598 responseMsg = convertExceptionToAxisFault(e, responseMsg); 599 } 600 response.setContentType("text/xml"); 603 writer.println(responseMsg.getSOAPPartAsString()); 604 } 605 606 613 614 protected void reportServiceInfo(HttpServletResponse response, PrintWriter writer, SOAPService service, String serviceName) 615 { 616 response.setContentType("text/html"); 617 618 writer.println("<h1>" 619 + service.getName() 620 + "</h1>"); 621 writer.println("<p>" + 622 Messages.getMessage("axisService00") + 623 "</p>"); 624 writer.println("<i>" + 625 Messages.getMessage("perhaps00") + 626 "</i>"); 627 } 628 629 637 protected void reportNoWSDL(HttpServletResponse res, PrintWriter writer, 638 String moreDetailCode, AxisFault axisFault) 639 { 640 res.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 641 res.setContentType("text/html"); 642 writer.println("<h2>" + 643 Messages.getMessage("error00") + 644 "</h2>"); 645 writer.println("<p>" + 646 Messages.getMessage("noWSDL00") + 647 "</p>"); 648 if (moreDetailCode != null) 649 { 650 writer.println("<p>" 651 + Messages.getMessage(moreDetailCode) 652 + "</p>"); 653 } 654 655 if (axisFault != null && isDevelopment()) 656 { 657 writeFault(writer, axisFault); 659 } 660 } 661 662 663 673 protected void reportAvailableServices(HttpServletResponse response, 674 PrintWriter writer, 675 HttpServletRequest request) 676 throws ConfigurationException, AxisFault 677 { 678 AxisEngine engine = getEngine(); 679 response.setContentType("text/html"); 680 writer.println("<h2>And now... Some Services</h2>"); 681 682 Iterator i; 683 try 684 { 685 i = engine.getConfig().getDeployedServices(); 686 } 687 catch (ConfigurationException configException) 688 { 689 if (configException.getContainedException() instanceof AxisFault) 692 { 693 throw (AxisFault)configException.getContainedException(); 694 } 695 else 696 { 697 throw configException; 698 } 699 } 700 String baseURL = getWebappBase(request) + "/services/"; 701 writer.println("<ul>"); 702 while (i.hasNext()) 703 { 704 ServiceDesc sd = (ServiceDesc)i.next(); 705 StringBuffer sb = new StringBuffer (); 706 sb.append("<li>"); 707 String name = sd.getName(); 708 sb.append(name); 709 sb.append(" <a HREF=\""); 710 sb.append(baseURL); 711 sb.append(name); 712 sb.append("?wsdl\"><i>(wsdl)</i></a></li>"); 713 writer.println(sb.toString()); 714 ArrayList operations = sd.getOperations(); 715 if (!operations.isEmpty()) 716 { 717 writer.println("<ul>"); 718 for (Iterator it = operations.iterator(); it.hasNext();) 719 { 720 OperationDesc desc = (OperationDesc)it.next(); 721 writer.println("<li>" + desc.getName()); 722 } 723 writer.println("</ul>"); 724 } 725 } 726 writer.println("</ul>"); 727 } 728 729 736 protected void reportCantGetAxisService(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) 737 { 738 response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 740 response.setContentType("text/html"); 741 writer.println("<h2>" + 742 Messages.getMessage("error00") + "</h2>"); 743 writer.println("<p>" + 744 Messages.getMessage("noService06") + 745 "</p>"); 746 } 747 748 755 protected void reportCantGetJWSService(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) 756 { 757 String realpath = 759 getServletConfig().getServletContext() 760 .getRealPath(request.getServletPath()); 761 boolean foundJWSFile = (new File (realpath).exists()) && 762 (realpath.endsWith(Constants.JWS_DEFAULT_FILE_EXTENSION)); 763 response.setContentType("text/html"); 764 if (foundJWSFile) 765 { 766 response.setStatus(HttpURLConnection.HTTP_OK); 767 writer.println(Messages.getMessage("foundJWS00") + "<p>"); 768 String url = request.getRequestURI(); 769 String urltext = Messages.getMessage("foundJWS01"); 770 writer.println("<a HREF='" + url + "?wsdl'>" + urltext + "</a>"); 771 } 772 else 773 { 774 response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); 775 writer.println(Messages.getMessage("noService06")); 776 } 777 } 778 779 780 799 public void doPost(HttpServletRequest req, HttpServletResponse res) 800 throws ServletException , IOException 801 { 802 long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0; 803 String soapAction = null; 804 MessageContext msgContext = null; 805 log.debug("Enter: doPost()"); 806 807 if (tlog.isDebugEnabled()) 808 { 809 t0 = System.currentTimeMillis(); 810 } 811 812 Message responseMsg = null; 813 String contentType = null; 814 815 try 816 { 817 AxisEngine engine = getEngine(); 818 819 if (engine == null) 820 { 821 ServletException se = 823 new ServletException (Messages.getMessage("noEngine00")); 824 log.debug("No Engine!", se); 825 throw se; 826 } 827 828 res.setBufferSize(1024 * 8); 830 832 msgContext = createMessageContext(engine, req, res); 833 String serviceName = getServiceName(req); 834 log.debug("serviceName: " + serviceName); 835 836 SOAPService service = (serviceName != null ? engine.getService(serviceName) : null); 838 if (service != null) 839 msgContext.setTargetService(serviceName); 840 841 if (securityProvider != null) 844 { 845 log.debug("securityProvider:" + securityProvider); 846 msgContext.setProperty(MessageContext.SECURITY_PROVIDER, securityProvider); 847 } 848 849 InputStream inputStream = req.getInputStream(); 850 851 MimeHeaders headers = extractHttpHeaders(req); 852 853 855 Message requestMsg = 856 new Message(inputStream, false, headers); 857 858 861 if (log.isDebugEnabled()) 862 { 863 log.debug("XML request received"); 864 log.debug("----------------------------------------------"); 865 MessagePart msgPart = (MessagePart)requestMsg.getSOAPPart(); 866 String xmlMessage = new String (msgPart.getAsBytes()); 867 log.debug("----------------------------------------------"); 868 log.debug(xmlMessage); 869 log.debug("----------------------------------------------"); 870 } 871 872 873 874 msgContext.setRequestMessage(requestMsg); 875 String url = req.getRequestURL().toString(); 876 msgContext.setProperty(MessageContext.TRANS_URL, url); 877 878 try 879 { 880 888 890 soapAction = getSoapAction(req); 891 892 if (soapAction != null) 893 { 894 msgContext.setUseSOAPAction(true); 895 msgContext.setSOAPActionURI(soapAction); 896 } 897 898 msgContext.setSession(new AxisHttpSession(req)); 902 903 if (tlog.isDebugEnabled()) 904 { 905 t1 = System.currentTimeMillis(); 906 } 907 908 909 910 log.debug("Invoking Axis Engine."); 911 engine.invoke(msgContext); 912 913 914 log.debug("Return from Axis Engine."); 915 if (tlog.isDebugEnabled()) 916 { 917 t2 = System.currentTimeMillis(); 918 } 919 920 OperationDesc opDesc = msgContext.getOperation(); 921 boolean isOneWay = opDesc != null && opDesc.isOneWay(); 922 923 responseMsg = msgContext.getResponseMessage(); 924 if (responseMsg == null && isOneWay == false) 925 { 926 throw new Exception (Messages.getMessage("noResponse01")); 928 } 929 } 930 catch (AxisFault fault) 931 { 932 processAxisFault(fault); 934 configureResponseFromAxisFault(res, fault); 935 responseMsg = msgContext.getResponseMessage(); 936 if (responseMsg == null) 937 { 938 responseMsg = new Message(fault); 939 msgContext.setResponseMessage(responseMsg); 940 } 941 } 942 catch (Exception e) 943 { 944 responseMsg = msgContext.getResponseMessage(); 946 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 947 responseMsg = convertExceptionToAxisFault(e, responseMsg); 948 } 949 } 950 catch (AxisFault fault) 951 { 952 processAxisFault(fault); 953 configureResponseFromAxisFault(res, fault); 954 responseMsg = msgContext.getResponseMessage(); 955 if (responseMsg == null) 956 { 957 responseMsg = new Message(fault); 958 msgContext.setResponseMessage(responseMsg); 959 } 960 } 961 finally 962 { 963 AxisEngine.setCurrentMessageContext(null); 965 } 966 967 if (tlog.isDebugEnabled()) 969 { 970 t3 = System.currentTimeMillis(); 971 } 972 973 974 975 if (responseMsg != null) 976 { 977 contentType = responseMsg.getContentType(msgContext.getSOAPConstants()); 978 sendResponse(contentType, 979 res, responseMsg); 980 } 981 982 log.debug("Response sent."); 983 log.debug("Exit: doPost()"); 984 985 if (tlog.isDebugEnabled()) 986 { 987 t4 = System.currentTimeMillis(); 988 tlog.debug("axisServlet.doPost: " + soapAction + 989 " pre=" + (t1 - t0) + 990 " invoke=" + (t2 - t1) + 991 " post=" + (t3 - t2) + 992 " send=" + (t4 - t3) + 993 " " + msgContext.getTargetService() + "." + 994 ((msgContext.getOperation() == null) ? 995 "" : msgContext.getOperation().getName())); 996 } 997 998 } 999 1000 1003 protected String getServiceName(HttpServletRequest request) 1004 { 1005 String path = request.getPathInfo(); 1006 if (path != null) 1007 { 1008 StringTokenizer st = new StringTokenizer (path, "/"); 1009 if (st.hasMoreTokens()) 1010 { 1011 return st.nextToken(); 1012 } 1013 } 1014 return null; 1015 } 1016 1017 1024 private void configureResponseFromAxisFault(HttpServletResponse response, 1025 AxisFault fault) 1026 { 1027 int status = getHttpServletResponseStatus(fault); 1031 if (status == HttpServletResponse.SC_UNAUTHORIZED) 1032 { 1033 response.setHeader("WWW-Authenticate", "Basic realm=\"AXIS\""); 1036 } 1037 response.setStatus(status); 1038 } 1039 1040 1050 private Message convertExceptionToAxisFault(Exception exception, 1051 Message responseMsg) 1052 { 1053 logException(exception); 1054 if (responseMsg == null) 1055 { 1056 AxisFault fault = AxisFault.makeFault(exception); 1057 processAxisFault(fault); 1058 responseMsg = new Message(fault); 1059 } 1060 return responseMsg; 1061 } 1062 1063 1069 protected int getHttpServletResponseStatus(AxisFault af) 1070 { 1071 return af.getFaultCode().getLocalPart().startsWith("Server.Unauth") 1074 ? HttpServletResponse.SC_UNAUTHORIZED 1075 : HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 1076 } 1079 1080 1089 private void sendResponse(String contentType, HttpServletResponse res, Message responseMsg) 1090 throws AxisFault, IOException 1091 { 1092 1093 if (responseMsg == null) 1094 { 1095 res.setStatus(HttpServletResponse.SC_NO_CONTENT); 1096 log.debug("NO AXIS MESSAGE TO RETURN!"); 1097 } 1101 else 1102 { 1103 log.debug("Returned Content-Type:" + contentType); 1104 1107 try 1108 { 1109 res.setContentType(contentType); 1110 1111 1120 1121 1124 MimeHeaders headers = responseMsg.getMimeHeaders(); 1126 if (headers != null) 1127 { 1128 Iterator i = headers.getAllHeaders(); 1129 while (i.hasNext()) 1130 { 1131 MimeHeader header = (MimeHeader )i.next(); 1132 res.addHeader(header.getName(), header.getValue()); 1133 } 1134 } 1135 1136 responseMsg.writeTo(res.getOutputStream()); 1137 1138 if (log.isDebugEnabled()) 1139 { 1140 log.debug("XML response sent"); 1141 log.debug("----------------------------------------------"); 1142 MessagePart msgPart = (MessagePart)responseMsg.getSOAPPart(); 1143 String xmlMessage = msgPart.getAsString(); 1144 log.debug("----------------------------------------------"); 1145 log.debug(xmlMessage); 1146 log.debug("----------------------------------------------"); 1147 } 1148 } 1149 catch (SOAPException e) 1150 { 1151 logException(e); 1152 } 1153 } 1154 1155 if (!res.isCommitted()) 1156 { 1157 res.flushBuffer(); } 1159 } 1160 1161 1170 protected MessageContext createMessageContext(AxisEngine engine, 1171 HttpServletRequest req, 1172 HttpServletResponse res) 1173 { 1174 MessageContext msgContext = new MessageContext(engine); 1175 AxisEngine.setCurrentMessageContext(msgContext); 1176 1177 if (log.isDebugEnabled()) 1178 { 1179 log.debug("MessageContext:" + msgContext); 1180 log.debug("HEADER_CONTENT_TYPE:" + 1181 req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE)); 1182 log.debug("HEADER_CONTENT_LOCATION:" + 1183 req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION)); 1184 log.debug("Constants.MC_HOME_DIR:" + String.valueOf(getHomeDir())); 1185 log.debug("Constants.MC_RELATIVE_PATH:" + req.getServletPath()); 1186 1187 log.debug("HTTPConstants.MC_HTTP_SERVLETLOCATION:" + String.valueOf(getWebInfPath())); 1188 log.debug("HTTPConstants.MC_HTTP_SERVLETPATHINFO:" + 1189 req.getPathInfo()); 1190 log.debug("HTTPConstants.HEADER_AUTHORIZATION:" + 1191 req.getHeader(HTTPConstants.HEADER_AUTHORIZATION)); 1192 log.debug("Constants.MC_REMOTE_ADDR:" + req.getRemoteAddr()); 1193 log.debug("configPath:" + String.valueOf(getWebInfPath())); 1194 } 1195 1196 1197 1198 msgContext.setTransportName(transportName); 1199 1200 1201 1202 msgContext.setProperty(Constants.MC_JWS_CLASSDIR, jwsClassDir); 1203 msgContext.setProperty(Constants.MC_HOME_DIR, getHomeDir()); 1204 msgContext.setProperty(Constants.MC_RELATIVE_PATH, 1205 req.getServletPath()); 1206 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLET, this); 1207 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, req); 1208 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, res); 1209 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION, 1210 getWebInfPath()); 1211 msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, 1212 req.getPathInfo()); 1213 msgContext.setProperty(HTTPConstants.HEADER_AUTHORIZATION, 1214 req.getHeader(HTTPConstants.HEADER_AUTHORIZATION)); 1215 msgContext.setProperty(Constants.MC_REMOTE_ADDR, req.getRemoteAddr()); 1216 1217 ServletEndpointContextImpl sec = new ServletEndpointContextImpl(); 1219 1220 msgContext.setProperty(Constants.MC_SERVLET_ENDPOINT_CONTEXT, sec); 1221 1222 1223 String realpath = 1224 getServletConfig().getServletContext() 1225 .getRealPath(req.getServletPath()); 1226 1227 if (realpath != null) 1228 { 1229 msgContext.setProperty(Constants.MC_REALPATH, realpath); 1230 } 1231 1232 msgContext.setProperty(Constants.MC_CONFIGPATH, getWebInfPath()); 1233 1234 return msgContext; 1235 } 1236 1237 1246 private String getSoapAction(HttpServletRequest req) 1247 throws AxisFault 1248 { 1249 String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION); 1250 1251 log.debug("HEADER_SOAP_ACTION:" + soapAction); 1252 1253 1257 if (soapAction == null) 1258 { 1259 AxisFault af = new AxisFault("Client.NoSOAPAction", 1260 Messages.getMessage("noHeader00", 1261 "SOAPAction"), 1262 null, null); 1263 1264 log.error(Messages.getMessage("genFault00"), af); 1265 1266 throw af; 1267 } 1268 1269 if (soapAction.length() == 0) 1270 soapAction = req.getContextPath(); 1272 return soapAction; 1273 } 1274 1275 1281 protected String getDefaultJWSClassDir() 1282 { 1283 return (getWebInfPath() == null) 1284 ? null : getWebInfPath() + File.separator + "jwsClasses"; 1286 } 1287 1288 1294 protected String getProtocolVersion(HttpServletRequest req) 1295 { 1296 String ret = HTTPConstants.HEADER_PROTOCOL_V10; 1297 String prot = req.getProtocol(); 1298 if (prot != null) 1299 { 1300 int sindex = prot.indexOf('/'); 1301 if (-1 != sindex) 1302 { 1303 String ver = prot.substring(sindex + 1); 1304 if (HTTPConstants.HEADER_PROTOCOL_V11.equals(ver.trim())) 1305 { 1306 ret = HTTPConstants.HEADER_PROTOCOL_V11; 1307 } 1308 } 1309 } 1310 return ret; 1311 } 1312 1313 private MimeHeaders extractHttpHeaders(HttpServletRequest req) 1314 { 1315 Enumeration headers = req.getHeaderNames(); 1316 MimeHeaders mimeHeaders = new MimeHeaders (); 1317 while (headers.hasMoreElements()) 1318 { 1319 String name = (String )headers.nextElement(); 1320 Enumeration values = req.getHeaders(name); 1321 while (values.hasMoreElements()) 1322 mimeHeaders.addHeader(name, (String )values.nextElement()); 1323 } 1324 1325 return mimeHeaders; 1326 } 1327} 1328 | Popular Tags |