Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
Future
-
None
-
Operating System: All
Platform: All
-
33701
Description
Is not posible to have a load balancer listening in a port different that the
port in which my server is.
looking at http header you can find the real values of your balancer (not only
the server name as with request.getServerName()).
this is my notation.
> include
< exclude
/*
- $Id$
* - Copyright 1999-2004 The Apache Software Foundation.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
*/
package org.apache.struts.taglib.html;
import java.io.IOException;
>import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.Globals;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
/**
- Renders an HTML <base> element with an href
- attribute pointing to the absolute location of the enclosing JSP page. This
- tag is only valid when nested inside a head tag body. The presence
- of this tag allows the browser to resolve relative URL's to images,
- CSS stylesheets and other resources in a manner independent of the URL
- used to call the ActionServlet.
* - @version $Rev$ $Date$
*/
public class BaseTag extends TagSupport {
/**
- The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
/**
- The server name to use instead of request.getServerName().
*/
protected String server = null;
/**
- The target window for this base reference.
*/
protected String target = null;
public String getTarget()
{ return (this.target); }public void setTarget(String target)
{ this.target = target; }/**
- Process the start of this tag.
* - @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
String serverName = (this.server == null) ? request.getServerName() :
this.server;
> int port=request.getServerPort();
> String headerHost=request.getHeader("Host");
> if (headerHost!=null) {
> StringTokenizer tokenizer=new StringTokenizer(headerHost,":");
> serverName=tokenizer.nextToken();
> if (tokenizer.hasMoreTokens()) {
> String portS=tokenizer.nextToken();
> try
catch (Exception e)
{ > port=80; > }> } else
{ > port=80; > }> }
> String baseTag = renderBaseElement(request.getScheme(), serverName,
port, request.getRequestURI());
< String baseTag =
< renderBaseElement(
< request.getScheme(),
< serverName,
< request.getServerPort(),
< request.getRequestURI());
JspWriter out = pageContext.getOut();
try
catch (IOException e)
{ pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw new JspException(messages.getMessage("common.io", e.toString())); } return EVAL_BODY_INCLUDE;
}
/**
- Render a fully formed HTML <base> element and return it as a String.
- @param scheme The scheme used in the url (ie. http or https).
- @param serverName
- @param port
- @param uri The portion of the url from the protocol name up to the query
- string.
- @return String An HTML <base> element.
- @since Struts 1.1
*/
protected String renderBaseElement(
String scheme,
String serverName,
int port,
String uri) {
StringBuffer tag = new StringBuffer("<base href=\"");
tag.append(RequestUtils.createServerUriStringBuffer(scheme,serverName,port,uri).toString());
tag.append("\"");
if (this.target != null)
{ tag.append(" target=\""); tag.append(this.target); tag.append("\""); }if (TagUtils.getInstance().isXhtml(this.pageContext))
{ tag.append(" />"); }else
{ tag.append(">"); } return tag.toString();
}
/**
- Returns the server.
- @return String
*/
public String getServer() { return this.server; }
/**
- Sets the server.
- @param server The server to set
*/
public void setServer(String server) { this.server = server; }
}