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
10 ~ http://www.apache.org/licenses/LICENSE-2.0
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
20 <%@ page import="org.apache.axis2.Constants" %>
21 <%@ page import="org.apache.axis2.context.ConfigurationContext" %>
22 <%@ page import="org.apache.axis2.description.Parameter" %>
23 <%@ page import="org.apache.axis2.transport.http.AxisServlet" %>
24 <%@ page import="org.apache.axis2.transport.TransportListener" %>
26 private String frontendHostUrl;
27 private String hostname;
29 public void jspInit() {
30 ServletContext context = this.getServletConfig().getServletContext();
31 ConfigurationContext configctx = (ConfigurationContext) context.getAttribute(AxisServlet.CONFIGURATION_CONTEXT);
32 if (configctx != null) {
33 Parameter parameter = configctx.getAxisConfiguration().getParameter(Constants.HTTP_FRONTEND_HOST_URL);
34 if (parameter != null) {
35 frontendHostUrl = (String) parameter.getValue();
37 Parameter hostnameParam = configctx.getAxisConfiguration().getParameter(TransportListener.HOST_ADDRESS);
38 if (hostnameParam != null) {
39 hostname = (String) hostnameParam.getValue();
44 public String calculateHttpBase(HttpServletRequest aRequest) {
45 StringBuffer stringBuffer = new StringBuffer();
46 if (frontendHostUrl != null) {
47 stringBuffer.append(frontendHostUrl);
49 String scheme = aRequest.getScheme();
50 stringBuffer.append(scheme);
51 stringBuffer.append("://");
52 stringBuffer.append(hostname != null ? hostname : aRequest.getServerName());
53 if (("http".equalsIgnoreCase(scheme) && aRequest.getServerPort() != 80) || "https".equalsIgnoreCase(scheme) && aRequest.getServerPort() != 443) {
54 stringBuffer.append(":");
55 stringBuffer.append(aRequest.getServerPort());
57 // I think i saw web containers return null for root web context
58 if (aRequest.getContextPath() != null) {
59 stringBuffer.append(aRequest.getContextPath());
62 // append / char if needed
63 if (stringBuffer.charAt(stringBuffer.length() - 1) != '/') {
64 stringBuffer.append("/");
66 String curentUrl = stringBuffer.toString();
67 aRequest.setAttribute("frontendHostUrl", curentUrl);
71 <base href="<%= calculateHttpBase(request)%>"/>