org.opentox.toxotis.client.https
Class PostHttpsClient

java.lang.Object
  extended by org.opentox.toxotis.client.AbstractClient
      extended by org.opentox.toxotis.client.https.AbstractHttpsClient
          extended by org.opentox.toxotis.client.https.PostHttpsClient
All Implemented Interfaces:
Closeable, IClient, IPostClient

public class PostHttpsClient
extends AbstractHttpsClient
implements IPostClient

Author:
Pantelis Sopasakis, Charalampos Chomenides

Field Summary
 
Fields inherited from class org.opentox.toxotis.client.AbstractClient
bufferSize
 
Fields inherited from interface org.opentox.toxotis.client.IPostClient
METHOD
 
Fields inherited from interface org.opentox.toxotis.client.IClient
httpProtocol, httpSecureProtocol, URL_ENCODING
 
Constructor Summary
PostHttpsClient()
           
PostHttpsClient(VRI vri)
           
 
Method Summary
 IPostClient addPostParameter(String paramName, String paramValue)
          Add a parameter which will be posted to the target URI.
 String getContentType()
           
 ReentrantReadWriteLock.WriteLock getPostLock()
           
protected  HttpURLConnection initializeConnection(URI uri)
          Initialize a connection to the target URI
 void post()
          According to the the configuration of the PostHttpClient, permorms a remote POST request to the server identified by the URI provided in the contructor.
 PostHttpsClient setContentType(Media media)
          Specify the Content-type header value that is the MIME of the POSTed entity.
 PostHttpsClient setContentType(String contentType)
          Specify the Content-type header value that is the MIME of the POSTed entity.
 PostHttpsClient setPostable(File objectToPost)
          Set a file whose contents are to be posted to the remote server specified in the constructor of this class.
 IPostClient setPostable(InputStream model)
           
 PostHttpsClient setPostable(IStAXWritable staxWritable)
          Set a StAX-writeable component to be posted to the remote location
 PostHttpsClient setPostable(com.hp.hpl.jena.ontology.OntModel model)
          Set an ontological data model which is to be posted to the remote location as application/rdf+xml.
 PostHttpsClient setPostable(String string, boolean binary)
          Provide a POSTable object as a string.
 
Methods inherited from class org.opentox.toxotis.client.AbstractClient
addHeaderParameter, authorize, close, connect, getConnection, getConnectionInputStream, getConnectionLock, getHeaderValues, getMediaType, getReadLock, getRemoteStream, getResponseCode, getResponseContentType, getResponseHeader, getResponseOntModel, getResponseOntModel, getResponseText, getResponseUriList, getUri, setConnection, setMediaType, setMediaType, setUri, setUri
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opentox.toxotis.client.IClient
addHeaderParameter, authorize, close, getConnectionLock, getMediaType, getReadLock, getRemoteStream, getResponseCode, getResponseContentType, getResponseHeader, getResponseOntModel, getResponseOntModel, getResponseText, getResponseUriList, getUri, setMediaType, setMediaType, setUri, setUri
 

Constructor Detail

PostHttpsClient

public PostHttpsClient()

PostHttpsClient

public PostHttpsClient(VRI vri)
Method Detail

setPostable

public PostHttpsClient setPostable(String string,
                                   boolean binary)
Description copied from interface: IPostClient
Provide a POSTable object as a string. Keep in mind that the this string will not be URL-Encoded or by any means modified prior to the POST operation. It is also up to the user to specify a proper Content-type.

Specified by:
setPostable in interface IPostClient
Parameters:
string - String representation of an entity to be posted to a remote server.
binary - Specifies whether the data should be posted in binary format, i.e. as a sequence of bytes or as a character sequence.
Returns:
This post client with an updated value of the postable object.
See Also:
Collection of Media Types

setPostable

public PostHttpsClient setPostable(com.hp.hpl.jena.ontology.OntModel model)
Set an ontological data model which is to be posted to the remote location as application/rdf+xml. Invokations of this method set automatically the content-type to application/rdf+xml though it can be overriden afterwards.

Specified by:
setPostable in interface IPostClient
Parameters:
model - Ontological Model to be posted
Returns:
The PostHttpClient with the updated Ontological Model.

initializeConnection

protected HttpURLConnection initializeConnection(URI uri)
                                          throws ServiceInvocationException
Initialize a connection to the target URI

Specified by:
initializeConnection in class AbstractClient
Parameters:
uri - The location to which the HTTP connection should be made.
Returns:
An instance of HttpURLConnection that is used to perform the remote HTTP request.
Throws:
ServiceInvocationException

getContentType

public String getContentType()
Specified by:
getContentType in interface IPostClient

setContentType

public PostHttpsClient setContentType(String contentType)
Description copied from interface: IPostClient
Specify the Content-type header value that is the MIME of the POSTed entity. Alternatively users can invoke IClient.addHeaderParameter(java.lang.String, java.lang.String) using the Header RequestHeaders.CONTENT_TYPE.

Specified by:
setContentType in interface IPostClient
Parameters:
contentType - The MIME type corresponding to the Content-type value for the underlying request as a String.
Returns:
The current updated modifiable POST client.

post

public void post()
          throws ServiceInvocationException
Description copied from interface: IPostClient
According to the the configuration of the PostHttpClient, permorms a remote POST request to the server identified by the URI provided in the contructor. First, the protected method initializeConnection(URI) is invoked and then a DataOutputStream opens to tranfer the data to the server.

Specified by:
post in interface IPostClient
Throws:
ServiceInvocationException

setContentType

public PostHttpsClient setContentType(Media media)
Description copied from interface: IPostClient
Specify the Content-type header value that is the MIME of the POSTed entity. Alternatively users can invoke IClient.addHeaderParameter(java.lang.String, java.lang.String) using the Header RequestHeaders.CONTENT_TYPE.

Specified by:
setContentType in interface IPostClient
Parameters:
media - The MIME type corresponding to the Content-type value for the underlying request as an instance of Media.
Returns:
The current updated modifiable POST client.

setPostable

public PostHttpsClient setPostable(IStAXWritable staxWritable)
Set a StAX-writeable component to be posted to the remote location

Specified by:
setPostable in interface IPostClient
Parameters:
staxWritable - A StAX component that implements the interface IStAXWritable that will be posted to the remote server via the method write(OutputStream) that writes the component to an outputstream pointing to the remote stream
Returns:
The PostHttpClient with the updated writeable component.

setPostable

public PostHttpsClient setPostable(File objectToPost)
Set a file whose contents are to be posted to the remote server specified in the constructor of this class. If the file is not found under the specified path, an IllegalArgumentException is thrown. Because the type of the file is in general unknown and it is not considered to be a good practise to deduce the file type from the file extension, it is up to the user to specify the content type of the posted object using the method setContentType. Since it is not possible to POST entities of different content types to an HTTP server, any invokation to this method will override any previous invokation of setPostable(OntModel) and setPostable(String).

Specified by:
setPostable in interface IPostClient
Parameters:
objectToPost - File whose contents are to be posted.
Returns:
This post client
Throws:
IllegalArgumentException - In case the provided file does not exist

addPostParameter

public IPostClient addPostParameter(String paramName,
                                    String paramValue)
                             throws NullPointerException
Add a parameter which will be posted to the target URI. Once the parameter is submitted to the PostClient, it is stored as URL-encoded using the UTF-8 encoding.

Specified by:
addPostParameter in interface IPostClient
Parameters:
paramName - Parameter name
paramValue - Parameter value
Returns:
This object
Throws:
NullPointerException - If paramName is null.

getPostLock

public ReentrantReadWriteLock.WriteLock getPostLock()
Specified by:
getPostLock in interface IPostClient

setPostable

public IPostClient setPostable(InputStream model)
Specified by:
setPostable in interface IPostClient


Copyright © 2011-2012 OpenTox. All Rights Reserved.