public final class PSHTTPConnector extends Object
By default the request is made anonymously. In order to make a request on behalf of a
PageSeeder user, use the using(PSSession)
method - this is required for any page
that needs login access.
For simple PageSeeder connections via GET or POST, this class provides convenience methods which will open and close the connections and capture any error in XML.
For example:
PSHTTPResponseInfo connector = new PSConnector(PSResourceType.SERVICE, "/groups/123/members").using(session).get(xml);
For more complex connections, involving multipart queries or if any of the default properties of the connection need to be changed, this class can be used to create the connection to PageSeeder, for example:
PSHTTPConnector connector = new PSHTTPConnector(PSResourceType.SERVICE, "/groups/123/upload").using(session); PSHTTPConnection connection = connector.connect(Type.MULTIPART); connection.addXMLPart(xml1); connection.addXMLPart(xml2); connection.addXMLPart(xml3); connection.disconnect();
Note: This class was forked from Bastille 0.8.29
Constructor and Description |
---|
PSHTTPConnector(PSHTTPResourceType type,
String resource)
Creates a new connection to the specified resource.
|
Modifier and Type | Method and Description |
---|---|
void |
addParameter(String name,
String value)
Add a parameter to this request.
|
PSHTTPConnection |
connect(PSHTTPConnection.Method type)
Connect to PageSeeder using the specified method.
|
PSHTTPResponseInfo |
delete(org.xml.sax.helpers.DefaultHandler handler)
Connect to PageSeeder and fetch the XML using the DELETE method to be parsed by a handler.
|
PSHTTPResponseInfo |
delete(org.pageseeder.xmlwriter.XMLWriter xml)
Connect to PageSeeder via DELETE and copy the output onto the specified XML writer.
|
PSHTTPResponseInfo |
get()
Connect to PageSeeder via GET and discard the output.
|
PSHTTPResponseInfo |
get(org.xml.sax.helpers.DefaultHandler handler)
Connect to PageSeeder and fetch the XML using the GET method to be parsed by a handler.
|
PSHTTPResponseInfo |
get(OutputStream out)
Connect to PageSeeder and fetch the content using the GET method to be parsed by a handler.
|
PSHTTPResponseInfo |
get(org.pageseeder.xmlwriter.XMLWriter xml)
Connect to PageSeeder via GET and copy the output onto the specified XML writer.
|
PSHTTPResponseInfo |
get(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates)
Connect to PageSeeder via GET and transform the XML output using the specified templates.
|
PSHTTPResponseInfo |
get(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates,
Map<String,String> parameters)
Connect to PageSeeder via GET and transform the XML output using the specified templates.
|
PSSession |
getSession() |
void |
includeErrorContent(boolean include)
Sets whether this resource should include the error content.
|
static PSHTTPConnector |
newService(String service)
Factory method to create a new connector for service.
|
PSHTTPResponseInfo |
patch()
Connect to PageSeeder via PATCH and discard the output.
|
PSHTTPResponseInfo |
patch(org.xml.sax.helpers.DefaultHandler handler)
Connect to PageSeeder and fetch the XML using the PATCH method to be parsed by a handler.
|
PSHTTPResponseInfo |
patch(org.pageseeder.xmlwriter.XMLWriter xml)
Connect to PageSeeder via PATCH and copy the output onto the specified XML writer.
|
PSHTTPResponseInfo |
patch(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates)
Connect to PageSeeder via PATCH and transform the XML output using the specified templates.
|
PSHTTPResponseInfo |
patch(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates,
Map<String,String> parameters)
Connect to PageSeeder via PATCH and transform the XML output using the specified templates.
|
PSHTTPResponseInfo |
post()
Connect to PageSeeder via POST and discard the output.
|
PSHTTPResponseInfo |
post(org.xml.sax.helpers.DefaultHandler handler)
Connect to PageSeeder and fetch the XML using the POST method to be parsed by a handler.
|
PSHTTPResponseInfo |
post(org.pageseeder.xmlwriter.XMLWriter xml)
Connect to PageSeeder via POST and copy the output onto the specified XML writer.
|
PSHTTPResponseInfo |
post(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates)
Connect to PageSeeder via POST and transform the XML output using the specified templates.
|
PSHTTPResponseInfo |
post(org.pageseeder.xmlwriter.XMLWriter xml,
Templates templates,
Map<String,String> parameters)
Connect to PageSeeder via POST and transform the XML output using the specified templates.
|
PSHTTPResponseInfo |
put()
Connect to PageSeeder via PUT and discard the output.
|
PSHTTPResponseInfo |
put(org.xml.sax.helpers.DefaultHandler handler)
Connect to PageSeeder and fetch the XML using the PUT method to be parsed by a handler.
|
PSHTTPResponseInfo |
put(org.pageseeder.xmlwriter.XMLWriter xml)
Connect to PageSeeder via PUT and copy the output onto the specified XML writer.
|
void |
setBody(String body)
Set the body of the request (used for PUT)
|
void |
setName(String name)
Set the name (URL) of the request
|
void |
setUser(PSSession user)
Sets the user for this request.
|
PSHTTPConnector |
using(PSSession session)
Sets the session for this request as a chainable method.
|
PSHTTPConnector |
using(String username,
String password)
Sets the username and password for this request as a chainable method.
|
public PSHTTPConnector(PSHTTPResourceType type, String resource)
type
- The type of resource.resource
- Thepublic static PSHTTPConnector newService(String service)
service
- The service subpath (after the /ps/service)public PSHTTPConnector using(PSSession session)
session
- the user for this request.public PSHTTPConnector using(String username, String password)
username
- the user for this request.password
- the passwordpublic void setUser(PSSession user)
user
- the user for this request.public PSSession getSession()
public void addParameter(String name, String value)
name
- The name of the parametervalue
- The value of the parameterpublic void setBody(String body)
body
- The body of the requestpublic void setName(String name)
name
- The name of the requestpublic void includeErrorContent(boolean include)
include
- true
to include the content of response even when the response code
is greater than 400 (included);
false
to only include the response when the response code is
between 200 and 299.public PSHTTPConnection connect(PSHTTPConnection.Method type) throws IOException
type
- The connection type using the specified methodIOException
- If thrown while trying to open the connection or if the URL for the
underlying resource is malformed.public PSHTTPResponseInfo get() throws APIException
Error messages will be captured.
APIException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo get(OutputStream out) throws APIException
out
- where the output should be copied.APIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo get(org.xml.sax.helpers.DefaultHandler handler) throws APIException
handler
- the handler for the XML returned by PageSeederAPIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo get(org.pageseeder.xmlwriter.XMLWriter xml) throws APIException
xml
- the XML to copy the output from PageSeederAPIException
- Wrap any error while communicating with PageSeeder or writing the XML.public PSHTTPResponseInfo get(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLAPIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo get(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates, Map<String,String> parameters) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLparameters
- Parameters to send to the XSLT transformer (optional)APIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo patch() throws APIException
Error messages will be captured.
APIException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo patch(org.xml.sax.helpers.DefaultHandler handler) throws APIException
handler
- the handler for the XML returned by PageSeederAPIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo patch(org.pageseeder.xmlwriter.XMLWriter xml) throws APIException
xml
- the XML to copy the output from PageSeederAPIException
- Wrap any error while communicating with PageSeeder or writing the XML.public PSHTTPResponseInfo patch(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLAPIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo patch(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates, Map<String,String> parameters) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLparameters
- Parameters to send to the XSLT transformer (optional)APIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo post() throws APIException
Error messages will be captured.
APIException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo post(org.xml.sax.helpers.DefaultHandler handler) throws APIException
handler
- the handler for the XML returned by PageSeederAPIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo post(org.pageseeder.xmlwriter.XMLWriter xml) throws APIException
xml
- the XML to copy the output from PageSeederAPIException
- Wrap any error while communicating with PageSeeder or writing the XML.public PSHTTPResponseInfo post(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLAPIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo post(org.pageseeder.xmlwriter.XMLWriter xml, Templates templates, Map<String,String> parameters) throws APIException
Templates can be specified to transform the XML returned from PageSeeder. In that case, the XML written out is the result of the transformation.
If the templates are omitted, the XML writer received a copy of the output from PageSeeder.
xml
- The result of the transformation or source XML if no templatestemplates
- A set of templates to process the XMLparameters
- Parameters to send to the XSLT transformer (optional)APIException
- Wrap any error while communicating with PageSeeder, writing or transforming the XML.public PSHTTPResponseInfo put() throws APIException
Error messages will be captured.
APIException
- If an error occurs when trying to write the XML.public PSHTTPResponseInfo put(org.xml.sax.helpers.DefaultHandler handler) throws APIException
handler
- the handler for the XML returned by PageSeederAPIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo put(org.pageseeder.xmlwriter.XMLWriter xml) throws APIException
xml
- the XML to copy the output from PageSeederAPIException
- Wrap any error while communicating with PageSeeder or writing the XML.public PSHTTPResponseInfo delete(org.xml.sax.helpers.DefaultHandler handler) throws APIException
handler
- the handler for the XML returned by PageSeederAPIException
- Wrap any error while communicating with PageSeeder or parsing the outputpublic PSHTTPResponseInfo delete(org.pageseeder.xmlwriter.XMLWriter xml) throws APIException
xml
- the XML to copy the output from PageSeederAPIException
- Wrap any error while communicating with PageSeeder or writing the XML.Copyright © 2016 Allette Systems. All rights reserved.