org.idoox.transport.client
Class Endpoint

java.lang.Object
  extended byorg.idoox.transport.client.Endpoint
All Implemented Interfaces:
URI

public class Endpoint
extends java.lang.Object
implements URI

This class is a client URI implementation. Simple client examples of the transport usage with Endpoint class:


    // HTTP GET
    Endpoint endpoint = new Endpoint("http://www.idoox.com/");
    ClientConnection connection = endpoint.newConnection(TransportMethod.GET);

    InputMessage in = connection.getInputMessage();
    byte[] buffer = new byte[2000];
    int length;
    while((length = in.read(buffer, 0, buffer.length)) >= 0) {
        System.out.print(new String(buffer, 0, length));
    }
    in.close();


    // HTTP POST
    Endpoint endpoint = new Endpoint("http://my.post.site/");
    ClientConnection connection = endpoint.newConnection(TransportMethod.POST);

    OutputMessage out = connection.getOutputMessage();
    out.setContentType("text/plain");
    out.write("Where do you want to go today?".getBytes("UTF-8"));
    out.close();

    InputMessage in = connection.getInputMessage();
    if(in.getStatusCode() != Message.SC_OK) {
        throw new IOException("ERROR: " + in.getStatusCode());
    }
    in.read(...);
    in.close();
 

Component:
Core

Constructor Summary
Endpoint(java.lang.String endpoint)
          Creates new endpoint from the string
Endpoint(java.lang.String scheme, java.lang.String userinfo, java.lang.String host, int port, java.lang.String context_path, java.lang.String location)
          Creates new endpoint from the specified scheme, userinfo, host, port, context path, and location.
Endpoint(java.lang.String scheme, java.lang.String userinfo, java.lang.String host, int port, java.lang.String context_path, java.lang.String path, java.lang.String fragment, java.util.Map paramMap)
          Creates new endpoint from the specified scheme, userinfo, host, port, context path, path, parameters map and fragment.
Endpoint(java.lang.String scheme, java.lang.String userinfo, java.lang.String host, int port, java.lang.String context_path, java.lang.String path, java.lang.String fragment, java.lang.String query)
          Creates new endpoint from the specified scheme, userinfo, host, port, context path, path, query and fragment.
Endpoint(URI uri)
          Creates new endpoint from the URI.
Endpoint(URI context, java.lang.String location)
          Creates new endpoint from some context and a new location.
 
Method Summary
 boolean equals(java.lang.Object other)
           
 java.lang.String getContextPath()
          Gets context path.
 java.lang.String getFragment()
          Gets fragment.
 java.lang.String getHost()
          Gets host.
 java.lang.String getLocation()
          Gets location.
 java.lang.String getParameter(java.lang.String name)
          Gets parameter.
 java.util.Set getParameterNames()
          Gets parameter names.
 java.lang.String[] getParameters(java.lang.String name)
          Gets parameters.
 java.lang.String getPath()
          Gets path.
 int getPort()
          Gets port.
 java.lang.String getQuery()
          Gets query.
 java.lang.String getScheme()
          Gets scheme.
 java.lang.String getUserinfo()
          Gets user info.
 boolean hasHandler()
          Returns true if this URI has handler on the TransportRepository.
 int hashCode()
           
 ClientConnection newConnection(TransportMethod method)
          Creates new connection without properties.
 ClientConnection newConnection(TransportMethod method, java.util.Map properties)
          Creates new connection.
 URI normalize()
          Returns normalized URI (or this if it is already in normalized form).
 void setContextPath(java.lang.String context_path)
          Sets context path.
 void setFragment(java.lang.String fragment)
          Sets fragment.
 void setHost(java.lang.String host)
          Sets host.
 void setLocation(java.lang.String location)
          Sets location.
 void setParameter(java.lang.String name, java.lang.String value)
          Sets parameter.
 void setParameters(java.lang.String name, java.lang.String[] values)
          Sets parameters.
 void setPath(java.lang.String path)
          Sets path.
 void setPort(int port)
          Sets port.
 void setQuery(java.lang.String query)
          Sets query string.
 void setScheme(java.lang.String scheme)
          Sets scheme.
 void setUserinfo(java.lang.String userinfo)
          Sets user info.
 java.lang.String toExternalForm()
          Constructs a string representation of this endpoint.
 java.lang.String toString()
          Constructs a string representation of this endpoint.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Endpoint

public Endpoint(java.lang.String endpoint)
         throws java.net.MalformedURLException
Creates new endpoint from the string

Parameters:
endpoint - endpoint string
Throws:
java.net.MalformedURLException - if an URL is malformed

Endpoint

public Endpoint(java.lang.String scheme,
                java.lang.String userinfo,
                java.lang.String host,
                int port,
                java.lang.String context_path,
                java.lang.String location)
Creates new endpoint from the specified scheme, userinfo, host, port, context path, and location.

Parameters:
scheme - the scheme
userinfo - the user info
host - the host
port - the port
context_path - the context path
location - the location

Endpoint

public Endpoint(java.lang.String scheme,
                java.lang.String userinfo,
                java.lang.String host,
                int port,
                java.lang.String context_path,
                java.lang.String path,
                java.lang.String fragment,
                java.lang.String query)
Creates new endpoint from the specified scheme, userinfo, host, port, context path, path, query and fragment.

Parameters:
scheme - the scheme
userinfo - the user info
host - the host
port - the port
context_path - the context path
path - the path
query - the query string
fragment - the fragment

Endpoint

public Endpoint(java.lang.String scheme,
                java.lang.String userinfo,
                java.lang.String host,
                int port,
                java.lang.String context_path,
                java.lang.String path,
                java.lang.String fragment,
                java.util.Map paramMap)
Creates new endpoint from the specified scheme, userinfo, host, port, context path, path, parameters map and fragment.

Parameters:
scheme - the scheme
userinfo - the user info
host - the host
port - the port
context_path - the context path
path - the path
paramMap - the parameters map where keys - parameter names, values - parameter values (ArrayList of String)
fragment - the fragment

Endpoint

public Endpoint(URI uri)
Creates new endpoint from the URI.

Parameters:
uri - the URI

Endpoint

public Endpoint(URI context,
                java.lang.String location)
         throws java.net.MalformedURLException
Creates new endpoint from some context and a new location. If the location is an absolute location it changes the location in context with this one. If the location is a relative location it changes a relative part of context location with this one.

Parameters:
context - the context
location - the location
Throws:
java.net.MalformedURLException - if an URL is malformed
Method Detail

getScheme

public java.lang.String getScheme()
Gets scheme.

Specified by:
getScheme in interface URI
Returns:
the scheme or null

setScheme

public void setScheme(java.lang.String scheme)
Sets scheme.

Parameters:
scheme - the scheme

getUserinfo

public java.lang.String getUserinfo()
Gets user info.

Specified by:
getUserinfo in interface URI
Returns:
the user info or null

setUserinfo

public void setUserinfo(java.lang.String userinfo)
Sets user info.

Parameters:
userinfo - the user info

getHost

public java.lang.String getHost()
Gets host.

Specified by:
getHost in interface URI
Returns:
the host or null

setHost

public void setHost(java.lang.String host)
Sets host.

Parameters:
host - the host

getPort

public int getPort()
Gets port.

Specified by:
getPort in interface URI
Returns:
the port or -1

setPort

public void setPort(int port)
Sets port.

Parameters:
port - the port

getContextPath

public java.lang.String getContextPath()
Gets context path.

Specified by:
getContextPath in interface URI
Returns:
the context path or null

setContextPath

public void setContextPath(java.lang.String context_path)
Sets context path.

Parameters:
context_path - the context path

getLocation

public java.lang.String getLocation()
Gets location.

Specified by:
getLocation in interface URI
Returns:
the location or null

setLocation

public void setLocation(java.lang.String location)
Sets location.

Parameters:
location - the location

getPath

public java.lang.String getPath()
Gets path.

Specified by:
getPath in interface URI
Returns:
the path or null

setPath

public void setPath(java.lang.String path)
Sets path.

Parameters:
path - the path

getQuery

public java.lang.String getQuery()
Gets query.

Specified by:
getQuery in interface URI
Returns:
the query string or null

setQuery

public void setQuery(java.lang.String query)
Sets query string.

Parameters:
query - the query string

getParameterNames

public java.util.Set getParameterNames()
Gets parameter names.

Specified by:
getParameterNames in interface URI
Returns:
set of parameter names

getParameter

public java.lang.String getParameter(java.lang.String name)
Gets parameter.

Specified by:
getParameter in interface URI
Parameters:
name - the parameter name
Returns:
the parameter value or null

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
Sets parameter.

Parameters:
name - the parameter name
value - the parameter value

getParameters

public java.lang.String[] getParameters(java.lang.String name)
Gets parameters.

Specified by:
getParameters in interface URI
Parameters:
name - the parameter name
Returns:
the array of parameter values or null

setParameters

public void setParameters(java.lang.String name,
                          java.lang.String[] values)
Sets parameters.

Parameters:
name - the parameter name
values - the array of parameter values

getFragment

public java.lang.String getFragment()
Gets fragment.

Specified by:
getFragment in interface URI
Returns:
the fragment or null

setFragment

public void setFragment(java.lang.String fragment)
Sets fragment.

Parameters:
fragment - the fragment

toExternalForm

public java.lang.String toExternalForm()
Constructs a string representation of this endpoint.

Specified by:
toExternalForm in interface URI
Returns:
a string representation of this object

toString

public java.lang.String toString()
Constructs a string representation of this endpoint.

Returns:
a string representation of this object

hasHandler

public boolean hasHandler()
Returns true if this URI has handler on the TransportRepository.

Returns:
true or false

newConnection

public ClientConnection newConnection(TransportMethod method)
                               throws java.net.MalformedURLException,
                                      java.io.IOException
Creates new connection without properties.

Parameters:
method - the method for connection initialization
Returns:
new connection
Throws:
java.io.IOException - if an I/O error occurs
java.net.MalformedURLException - if an URL is malformed
See Also:
newConnection(TransportMethod, Map)

newConnection

public ClientConnection newConnection(TransportMethod method,
                                      java.util.Map properties)
                               throws java.net.MalformedURLException,
                                      java.io.IOException
Creates new connection. It does:
1. gets a transport repository implementation from WSO2 SOA Enablement Server Context
2. gets a transport from the repository with a name getScheme() and checks if this one is CLIENT type
3. creates new client connection on the transport and inits it for given transport method

Parameters:
method - the method for connection initialization
properties - properties for the transport
Returns:
new connection
Throws:
java.io.IOException - if an I/O error occurs
java.net.MalformedURLException - if an URL is malformed

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object other)

normalize

public URI normalize()
Returns normalized URI (or this if it is already in normalized form). Normalized URI is uri with normalized path. Normalized path does not contain any empty or "." segments or ".." segments preceded by other segment than "..".

Returns:
URI with normalized path
Since:
4.7