httpbase.jsp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <%--
  2. ~ Licensed to the Apache Software Foundation (ASF) under one
  3. ~ or more contributor license agreements. See the NOTICE file
  4. ~ distributed with this work for additional information
  5. ~ regarding copyright ownership. The ASF licenses this file
  6. ~ to you under the Apache License, Version 2.0 (the
  7. ~ "License"); you may not use this file except in compliance
  8. ~ with the License. You may obtain a copy of the License at
  9. ~
  10. ~ http://www.apache.org/licenses/LICENSE-2.0
  11. ~
  12. ~ Unless required by applicable law or agreed to in writing,
  13. ~ software distributed under the License is distributed on an
  14. ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. ~ KIND, either express or implied. See the License for the
  16. ~ specific language governing permissions and limitations
  17. ~ under the License.
  18. --%>
  19. <%@ page import="org.apache.axis2.Constants" %>
  20. <%@ page import="org.apache.axis2.context.ConfigurationContext" %>
  21. <%@ page import="org.apache.axis2.description.Parameter" %>
  22. <%@ page import="org.apache.axis2.transport.http.AxisServlet" %>
  23. <%@ page import="org.apache.axis2.transport.TransportListener" %>
  24. <%!
  25. private static String frontendHostUrl;
  26. private static String hostname;
  27. public void jspInit() {
  28. ServletContext context = this.getServletConfig().getServletContext();
  29. ConfigurationContext configctx = (ConfigurationContext) context.getAttribute(AxisServlet.CONFIGURATION_CONTEXT);
  30. if (configctx != null) {
  31. Parameter parameter = configctx.getAxisConfiguration().getParameter(Constants.HTTP_FRONTEND_HOST_URL);
  32. if (parameter != null) {
  33. frontendHostUrl = (String) parameter.getValue();
  34. }
  35. Parameter hostnameParam = configctx.getAxisConfiguration().getParameter(TransportListener.HOST_ADDRESS);
  36. if (hostnameParam != null) {
  37. hostname = (String) hostnameParam.getValue();
  38. }
  39. }
  40. }
  41. public String calculateHttpBase(HttpServletRequest aRequest) {
  42. StringBuffer stringBuffer = new StringBuffer();
  43. if (frontendHostUrl != null) {
  44. stringBuffer.append(frontendHostUrl);
  45. } else {
  46. String scheme = aRequest.getScheme();
  47. stringBuffer.append(scheme);
  48. stringBuffer.append("://");
  49. stringBuffer.append(hostname != null ? hostname : aRequest.getServerName());
  50. if (("http".equalsIgnoreCase(scheme) && aRequest.getServerPort() != 80) || "https".equalsIgnoreCase(scheme) && aRequest.getServerPort() != 443) {
  51. stringBuffer.append(":");
  52. stringBuffer.append(aRequest.getServerPort());
  53. }
  54. // I think i saw web containers return null for root web context
  55. if (aRequest.getContextPath() != null) {
  56. stringBuffer.append(aRequest.getContextPath());
  57. }
  58. }
  59. // append / char if needed
  60. if (stringBuffer.charAt(stringBuffer.length() - 1) != '/') {
  61. stringBuffer.append("/");
  62. }
  63. String curentUrl = stringBuffer.toString();
  64. aRequest.setAttribute("frontendHostUrl", curentUrl);
  65. return curentUrl;
  66. }
  67. %>
  68. <%
  69. String basePath=calculateHttpBase(request);
  70. %>
  71. <base href="<%=basePath%>"/>