Stripes

Support for protocol, host, port and context stripes:form, stripes:link and stripes:url tags

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4.3
  • Fix Version/s: None
  • Component/s: Tag Library
  • Labels:
    None

Description

It would be great if stripes:form, stripes:link and stripes:url tags supported additional attributes to make the rendered URL absolute. This is very handy in situations when the user is on a page that got loaded via HTTP and you need to point them to an action over HTTPS.

This is very common for title pages containing user login forms that should be submitted over HTTPS. Redirecting the user to HTTPS as soon as they hit the title page is not desirable. Most of the functionality on the title page is typically available to non-authenticated users and there is no need to further stress the HTTP server with unnecessary HTTPS traffic.

Stripes tags should be intelligent enough to calculate sane defaults (e.g. if protocol="https" is specified and no port is specified, then the port should be set to 443) and normalize the generated URLs (when a standard port is used for the chosen protocol, then the port number is dropped from the URL).

According to the reactions on the mailing list (search for "Force HTTPS for submit"), there are users who would appreciate this functionality.

I have already implemented an extension of the stripes:form tag + normalization routines etc. to support the 4 above-mentioned attributes so I can possibly extract the relevant code and post it.

Jan

Activity

Hide
Kai Grabfelder added a comment - 07/Oct/07 11:40 PM

Sounds reasonable for me. Could you create a patch against the trunk and attach it to this issue?

Show
Kai Grabfelder added a comment - 07/Oct/07 11:40 PM Sounds reasonable for me. Could you create a patch against the trunk and attach it to this issue?
Hide
Jan Moravec added a comment - 10/Oct/07 6:56 AM

The form tag that supports, protocol, host, port and context attributes to customize the form's action URL. Primarily used to make forms loaded via HTTP point to Stripes actions over HTTPS.

The context attribute allows one to change the target web context. I do not use it, but some users on the mailing list indicated that it might be useful sometimes (when Apache proxying/rewriting is used). Basically it gives you complete control over the created action URL....

Show
Jan Moravec added a comment - 10/Oct/07 6:56 AM The form tag that supports, protocol, host, port and context attributes to customize the form's action URL. Primarily used to make forms loaded via HTTP point to Stripes actions over HTTPS. The context attribute allows one to change the target web context. I do not use it, but some users on the mailing list indicated that it might be useful sometimes (when Apache proxying/rewriting is used). Basically it gives you complete control over the created action URL....
Hide
Jan Moravec added a comment - 10/Oct/07 7:14 AM

Ops, it seems that JIRA mixes up file comments with normal comments. Anyway.

I am currently very short of time and stressed with my projects. So I am afraid I cannot possibly devote any time to patching 1.5. We are still on 1.4.3 and that's where I implemented the desired functionality by extending the stripes:form tag and adding additional attributes to adjust the form's action URL. I have not customized stripes:url and stripes:link tags because I can currently live with the customized form tag.

I am attaching the source code for the customized stripes:form tag just in case anyone wants to take this further and create a patch for 1.5.

The customized form tag calls a URL normalization method outside the attached FormTag.java source. This is the normalization method as it stands right now:

/**

  • Normalizes the specified URL.
    *
  • @param url an input URL.
  • @return the normalized URL.
  • @see #normalizeUrl(java.net.URL)
    */
    public static URL normalizeUrl( String url )
    Unknown macro: { try { return normalizeUrl( new URL( url ) ); } catch ( MalformedURLException e ) { throw new IllegalArgumentException( "Invalid URL: " + url, e ); } }

/**

  • Normalizes the specified URL by:
  • <ol>
  • <li>Converting the host name and protocol
  • name to lower-case.</li>
  • <li>Dropping the port number in case it is a default port number
  • for the specified protocol.</li>
  • <li>If the input URL's file path is set to "/", then it is removed.</li>
  • <li>The input URL's ref path is disregarded.</li>
  • <li>The input URL's user info path is disregarded.</li>
  • </ol>
    *
  • @param url an input URL.
  • @return the normalized URL.
    */
    public static URL normalizeUrl( URL url )
    {
    String protocol = url.getProtocol().toLowerCase();
    String host = url.getHost().toLowerCase();

// if a standard port is used, set port to -1
int port = url.getPort();
if ( ( port == WebConst.URL_STANDARD_PORT_HTTP && WebConst.URL_SCHEME_HTTP.equals( protocol ) ) ||
( port == WebConst.URL_STANDARD_PORT_HTTPS && WebConst.URL_SCHEME_HTTPS.equals( protocol ) ) )
port = -1;

String file = url.getFile();
if ( "/".equals( file ) )
file = CommonConst.EMPTY_STRING;

try

{ return new URL( protocol, host, port, file ); }

catch ( MalformedURLException e )

{ throw new ShouldNeverHappenException( "Error normalizing URL: " + url, e ); }

}

Jan

Show
Jan Moravec added a comment - 10/Oct/07 7:14 AM Ops, it seems that JIRA mixes up file comments with normal comments. Anyway. I am currently very short of time and stressed with my projects. So I am afraid I cannot possibly devote any time to patching 1.5. We are still on 1.4.3 and that's where I implemented the desired functionality by extending the stripes:form tag and adding additional attributes to adjust the form's action URL. I have not customized stripes:url and stripes:link tags because I can currently live with the customized form tag. I am attaching the source code for the customized stripes:form tag just in case anyone wants to take this further and create a patch for 1.5. The customized form tag calls a URL normalization method outside the attached FormTag.java source. This is the normalization method as it stands right now: /**
  • Normalizes the specified URL. *
  • @param url an input URL.
  • @return the normalized URL.
  • @see #normalizeUrl(java.net.URL) */ public static URL normalizeUrl( String url )
    Unknown macro: { try { return normalizeUrl( new URL( url ) ); } catch ( MalformedURLException e ) { throw new IllegalArgumentException( "Invalid URL: " + url, e ); } }
/**
  • Normalizes the specified URL by:
  • <ol>
  • <li>Converting the host name and protocol
  • name to lower-case.</li>
  • <li>Dropping the port number in case it is a default port number
  • for the specified protocol.</li>
  • <li>If the input URL's file path is set to "/", then it is removed.</li>
  • <li>The input URL's ref path is disregarded.</li>
  • <li>The input URL's user info path is disregarded.</li>
  • </ol> *
  • @param url an input URL.
  • @return the normalized URL. */ public static URL normalizeUrl( URL url ) { String protocol = url.getProtocol().toLowerCase(); String host = url.getHost().toLowerCase();
// if a standard port is used, set port to -1 int port = url.getPort(); if ( ( port == WebConst.URL_STANDARD_PORT_HTTP && WebConst.URL_SCHEME_HTTP.equals( protocol ) ) || ( port == WebConst.URL_STANDARD_PORT_HTTPS && WebConst.URL_SCHEME_HTTPS.equals( protocol ) ) ) port = -1; String file = url.getFile(); if ( "/".equals( file ) ) file = CommonConst.EMPTY_STRING; try { return new URL( protocol, host, port, file ); } catch ( MalformedURLException e ) { throw new ShouldNeverHappenException( "Error normalizing URL: " + url, e ); } } Jan
Hide
Jan Moravec added a comment - 10/Oct/07 7:16 AM

The WebConst constants:

/**

  • URL standard http port (80).
    */
    int URL_STANDARD_PORT_HTTP = 80;

/**

  • URL standard https port (443).
    */
    int URL_STANDARD_PORT_HTTPS = 443;

/**

  • URL http scheme.
    */
    String URL_SCHEME_HTTP = "http";

/**

  • URL https scheme.
    */
    String URL_SCHEME_HTTPS = "https";
Show
Jan Moravec added a comment - 10/Oct/07 7:16 AM The WebConst constants: /**
  • URL standard http port (80). */ int URL_STANDARD_PORT_HTTP = 80;
/**
  • URL standard https port (443). */ int URL_STANDARD_PORT_HTTPS = 443;
/**
  • URL http scheme. */ String URL_SCHEME_HTTP = "http";
/**
  • URL https scheme. */ String URL_SCHEME_HTTPS = "https";

People

Vote (0)
Watch (2)

Dates

  • Created:
    03/Oct/07 6:48 AM
    Updated:
    19/Jan/08 2:47 PM