Salome HOME
Siman-WS eclipse project is added
[tools/siman.git] / Workspace / Siman-WS / WebContent / axis2-web / include / httpbase.jsp
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
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" %>
25 <%!
26     private String frontendHostUrl;
27     private String hostname;
28
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();
36             }
37             Parameter hostnameParam = configctx.getAxisConfiguration().getParameter(TransportListener.HOST_ADDRESS);
38             if (hostnameParam != null) {
39                 hostname = (String) hostnameParam.getValue();
40             }
41         }
42     }
43
44     public String calculateHttpBase(HttpServletRequest aRequest) {
45         StringBuffer stringBuffer = new StringBuffer();
46         if (frontendHostUrl != null) {
47             stringBuffer.append(frontendHostUrl);
48         } else {
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());
56             }
57             // I think i saw web containers return null for root web context
58             if (aRequest.getContextPath() != null) {
59                 stringBuffer.append(aRequest.getContextPath());
60             }
61         }
62         // append / char if needed
63         if (stringBuffer.charAt(stringBuffer.length() - 1) != '/') {
64             stringBuffer.append("/");
65         }
66         String curentUrl = stringBuffer.toString();
67         aRequest.setAttribute("frontendHostUrl", curentUrl);
68         return curentUrl;
69     }
70 %>
71 <base href="<%= calculateHttpBase(request)%>"/>