Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.thetransactioncompany.cors;
  
  
  import java.net.URI;
  import java.net.IDN;


Validated resource request origin, as defined in The Web Origin Concept (RFC 6454). Supported schemes are http and https.

Author(s):
Vladimir Dzhuvinov
Luis Sala
Jared Ottley
EdraĆ­ Brosa
 
 public class ValidatedOrigin extends Origin {


The origin scheme.
 
 	private String scheme;


The origin host.
 
 	private String host;


The parsed origin port, -1 for default port.
 
 	private int port = -1;


Creates a new validated origin.

Parameters:
origin The origin to validate. Must not be null.
Throws:
OriginException If the value doesn't represent a valid URI and a supported origin.
 
 	public ValidatedOrigin(final Origin origin)
 		throws OriginException {
 	
 		super(origin.toString());
 
 		// Parse URI value
 	
 		URI uri;
 	
 		try {
 			uri = new URI(origin.toString());
 			
 		} catch (URISyntaxException e) {
 		
 			throw new OriginException("Bad origin URI: " + e.getMessage());
 		}
 		
 		 = uri.getScheme();
 		 = uri.getHost();
 		 = uri.getPort();
 		
 		if ( == null)
 			throw new OriginException("Bad origin URI: Missing scheme, such as http or https");
 		
 		// Canonicalise scheme and host
 		
 		// Apply the IDNA toASCII algorithm [RFC3490] to /host/
 	
 		// Finally, convert to lower case
 	}


Returns the scheme.

Returns:
The scheme.
 
 	public String getScheme() {
 
 		return ;
 	}


Returns the host (name or IP address).

Returns:
The host name or IP address.
 
 	public String getHost() {
 	
		return ;
	}


Returns the port number.

Returns:
The port number, -1 for default port.
	public int getPort() {
		return ;
	}


Returns the suffix which is made up of the host name / IP address and port (if a non-default port is specified).

Example:

 http://example.com => example.com
 http://example.com:8080 => example.com:8080
 

Returns:
The suffix.
	public String getSuffix() {
		String s = ;
		if ( != -1)
			s = s + ":" + ;
		return s;
	}
New to GrepCode? Check out our FAQ X