public final class PSHTTPConnection extends Object
Note: This class was initially forked from Bastille 0.8.29
Modifier and Type | Class and Description |
---|---|
static class |
PSHTTPConnection.Method
Not strictly HTTP method as multipart request use a separate method.
|
Modifier and Type | Method and Description |
---|---|
void |
addParameterPart(String name,
String value)
Add a parameter as part of a multipart request.
|
void |
addPart(File part)
Add a part to the request from a file (write the contents directly to the stream).
|
void |
addPart(InputStream in,
String filename)
Add a part to the request from input stream (write the contents directly to the stream).
|
void |
addXMLPart(String part)
Add a part to the request (write the contents directly to the stream).
|
void |
addXMLPart(String part,
Map<String,String> headers)
Add a part to the request (write the contents directly to the stream).
|
void |
closeOutput()
Closes the output stream when writing to the connection.
|
protected static PSHTTPConnection |
connect(PSHTTPResource resource,
PSHTTPConnection.Method type,
PSCredentials credentials)
Create a PageSeeder connection for the specified URL and method.
|
HttpURLConnection |
connection()
Returns the underlying HTTP connection.
|
String |
getContentType()
Returns the content type of the underlying HTTP connection.
|
int |
getResponseCode()
Returns the response code of the underlying HTTP connection.
|
String |
getResponseMessage()
Returns the response message of the underlying HTTP connection.
|
PSSession |
getSession()
The session may have been updated after the connection was made.
|
PSHTTPConnection.Method |
method()
Returns the type of connection.
|
void |
process(PSHTTPResponseInfo response,
org.xml.sax.helpers.DefaultHandler handler)
Process the specified PageSeeder connection.
|
void |
process(PSHTTPResponseInfo response,
OutputStream out)
Process the specified PageSeeder connection.
|
void |
process(PSHTTPResponseInfo response,
org.pageseeder.xmlwriter.XMLWriter xml)
Process the specified PageSeeder connection.
|
PSHTTPResponseInfo |
process(PSHTTPResponseInfo response,
org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates)
Process the specified PageSeeder connection.
|
PSHTTPResponseInfo |
process(PSHTTPResponseInfo response,
org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates,
Map<String,String> parameters)
Process the specified PageSeeder connection.
|
PSHTTPResource |
resource()
Returns the PageSeeder resource corresponding to the URL.
|
public void addXMLPart(String part) throws IOException
part
- The encoding to specify in the Part's headerIOException
- Should any error occur while writing the part on the outputpublic void addXMLPart(String part, Map<String,String> headers) throws IOException
part
- The encoding to specify in the Part's headerheaders
- A list of headers added to this XML Part ('content-type' header is ignored)IOException
- Should any error occur while writingpublic void addPart(File part) throws IOException
part
- File for partIOException
- Should any error occur while writingpublic void addPart(InputStream in, String filename) throws IOException
in
- Input stream for part contentfilename
- The filename for the partIOException
- Should any error occur while writingpublic void addParameterPart(String name, String value) throws IOException
name
- the name of the parametervalue
- the value of the parameterIOException
- Should any error occur while writingpublic void closeOutput() throws IOException
This method does nothing if the output stream hasn't been created.
IOException
- If thrown by the close method.public int getResponseCode() throws IOException
IOException
- If thrown by the underlying HTTP connection.HttpURLConnection.getResponseCode()
public String getResponseMessage() throws IOException
IOException
- If thrown by the underlying HTTP connection.HttpURLConnection.getResponseMessage()
public String getContentType() throws IOException
IOException
- If thrown by the underlying HTTP connection.URLConnection.getContentType()
public HttpURLConnection connection()
This method can be useful to perform additional operations on the connection which are not provided by this class.
public PSHTTPResource resource()
public PSHTTPConnection.Method method()
public PSSession getSession()
public void process(PSHTTPResponseInfo response, OutputStream out) throws IOException
response
- the response infoout
- where the output should be copied.IOException
- If an error occurs when trying to write the XML.public void process(PSHTTPResponseInfo response, org.xml.sax.helpers.DefaultHandler handler) throws IOException
If the handler is not specified, the xml writer receives a copy of the PageSeeder XML.
response
- the response infohandler
- the handler for the XML (can be used to rewrite the XML)IOException
- If an error occurs when trying to write the XML.public void process(PSHTTPResponseInfo response, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
The xml writer receives a copy of the PageSeeder XML.
response
- The response object.xml
- The XML to copy from PageSeederIOException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo process(PSHTTPResponseInfo response, org.pageseeder.xmlwriter.XMLWriter xml, Templates templates) throws IOException
Templates can be specified to transform the XML.
response
- The PageSeeder response metadata to updatexml
- The XML to copy from PageSeedertemplates
- A set of templates to process the XML (optional)IOException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo process(PSHTTPResponseInfo response, org.pageseeder.xmlwriter.XMLWriter xml, Templates templates, Map<String,String> parameters) throws IOException
Templates can be specified to transform the XML.
response
- The PageSeeder response metadata to updatexml
- The XML to copy from PageSeedertemplates
- A set of templates to process the XML (optional)parameters
- Parameters to send to the XSLT transformer (optional)IOException
- If an error occurs when trying to write the XML.protected static PSHTTPConnection connect(PSHTTPResource resource, PSHTTPConnection.Method type, PSCredentials credentials) throws IOException
The connection is configured to:
resource
- The resource to connect to.type
- The type of connection.credentials
- The user login to use (optional).IOException
- Should an exception be returns while opening the connectionCopyright © 2016 Allette Systems. All rights reserved.