|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.extensions.webscripts.connector.AbstractClient org.springframework.extensions.webscripts.connector.RemoteClient
public class RemoteClient
Remote client for for accessing data from remote URLs.
Can be used as a Script root object for simple HTTP requests.
Generally remote URLs will be "data" webscripts (i.e. returning XML/JSON) called from web-tier script objects and will be housed within an Alfresco Repository server.
Supports HTTP methods of GET, DELETE, PUT and POST of body content data.
A 'Response' is returned containing the response data stream as a String and the Status object representing the status code and error information if any. Methods supplying an InputStream will force a POST and methods supplying an OutputStream will stream the result directly to it and not generate a response in the 'Response' object.
Field Summary | |
---|---|
static int |
SC_MOVED_PERMANENTLY
|
static int |
SC_MOVED_TEMPORARILY
|
static int |
SC_REMOTE_CONN_NOHOST
|
static int |
SC_REMOTE_CONN_TIMEOUT
|
static int |
SC_SEE_OTHER
|
static int |
SC_TEMPORARY_REDIRECT
|
Fields inherited from class org.springframework.extensions.webscripts.connector.AbstractClient |
---|
endpoint |
Constructor Summary | |
---|---|
RemoteClient(String endpoint)
Construction |
|
RemoteClient(String endpoint,
String defaultEncoding)
Construction |
Method Summary | |
---|---|
Response |
call(String uri)
Call a remote WebScript uri. |
Response |
call(String uri,
boolean buildResponseString,
InputStream in)
Call a remote WebScript uri. |
Response |
call(String uri,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Call a remote WebScript uri. |
Response |
call(String uri,
InputStream in)
Call a remote WebScript uri. |
Response |
call(String uri,
InputStream in,
OutputStream out)
Call a remote WebScript uri. |
Response |
call(String uri,
OutputStream out)
Call a remote WebScript uri. |
Response |
call(String uri,
String body)
Call a remote WebScript uri, passing the supplied body as a POST request (unless the request method is set to override as say PUT). |
Map<String,String> |
getCookies()
Gets the current set of cookies for state transfer. |
String |
getTicket()
Returns the authentication ticket |
String |
getTicketName()
|
protected URL |
processResponse(URL url,
org.apache.commons.httpclient.HttpMethod method)
Pre-processes the response, propagating cookies and deciding whether a redirect is required |
void |
setCookies(Map<String,String> cookies)
Provides a set of cookies for state transfer. |
void |
setRequestContentType(String contentType)
|
void |
setRequestMethod(HttpMethod method)
|
void |
setRequestProperties(Map<String,String> requestProperties)
Allows for additional request properties to be set onto this object These request properties are applied to the connection when the connection is called. |
void |
setTicket(String ticket)
Sets the authentication ticket to use. |
void |
setTicketName(String ticketName)
Sets the authentication ticket name to use. |
void |
setUsernamePassword(String user,
String pass)
Basic HTTP auth. |
Methods inherited from class org.springframework.extensions.webscripts.connector.AbstractClient |
---|
getEndpoint, getURL |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SC_REMOTE_CONN_TIMEOUT
public static final int SC_REMOTE_CONN_NOHOST
public static final int SC_MOVED_TEMPORARILY
public static final int SC_MOVED_PERMANENTLY
public static final int SC_SEE_OTHER
public static final int SC_TEMPORARY_REDIRECT
Constructor Detail |
---|
public RemoteClient(String endpoint)
endpoint
- HTTP API endpoint of remote Alfresco server webapp
For example http://servername:8080/alfrescopublic RemoteClient(String endpoint, String defaultEncoding)
endpoint
- HTTP API endpoint of remote Alfresco server webapp
For example http://servername:8080/alfrescodefaultEncoding
- Encoding to use when converting responses that do not specify oneMethod Detail |
---|
public void setTicket(String ticket)
ticket
- public String getTicket()
public void setTicketName(String ticketName)
ticket
- public String getTicketName()
public void setUsernamePassword(String user, String pass)
user
- pass
- public void setRequestContentType(String contentType)
requestContentType
- the POST request "Content-Type" header value to set
NOTE: this value is reset to the default of GET after a call() is made.public void setRequestMethod(HttpMethod method)
requestMethod
- the request Method to set i.e. one of GET/POST/PUT/DELETE etc.
if not set, GET will be assumed unless an InputStream is supplied during call()
in which case POST will be used unless the request method overrides it with PUT.
NOTE: this value is reset to the default of GET after a call() is made.public void setRequestProperties(Map<String,String> requestProperties)
requestProperties
- public void setCookies(Map<String,String> cookies)
cookies
- the cookiespublic Map<String,String> getCookies()
public Response call(String uri)
uri
- WebScript URI - for example /test/myscript?arg=value
Response
public Response call(String uri, String body)
uri
- Uri to call on the endpointbody
- Body of the POST request.
Response
public Response call(String uri, InputStream in)
uri
- WebScript URI - for example /test/myscript?arg=valuein
- The optional InputStream to the call - if supplied a POST will be performed
Response
public Response call(String uri, boolean buildResponseString, InputStream in)
uri
- WebScript URI - for example /test/myscript?arg=valuebuildResponseString
- True to build a String result automatically based on the response
encoding, false to instead return the InputStream in the Response.in
- The optional InputStream to the call - if supplied a POST will be performed
Response
public Response call(String uri, OutputStream out)
uri
- WebScript URI - for example /test/myscript?arg=valueout
- OutputStream to stream successful response to - will be closed automatically.
A response data string will not therefore be available in the Response object.
If remote call fails the OutputStream will not be modified or closed.
Response
public Response call(String uri, InputStream in, OutputStream out)
uri
- WebScript URI - for example /test/myscript?arg=valuein
- The optional InputStream to the call - if supplied a POST will be performedout
- OutputStream to stream response to - will be closed automatically.
A response data string will not therefore be available in the Response object.
If remote call returns a status code then any available error response will be
streamed into the output.
If remote call fails completely the OutputStream will not be modified or closed.
Response
public Response call(String uri, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
uri
- WebScript URI - for example /test/myscript?arg=valuereq
- HttpServletRequest the request to retrieve input and headers etc. fromres
- HttpServletResponse the response to stream response to - will be closed automatically.
A response data string will not therefore be available in the Response object.
The HTTP method to be used should be set via the setter otherwise GET will be assumed
and the InputStream will not be retrieve from the request.
If remote call returns a status code then any available error response will be
streamed into the response object.
If remote call fails completely the OutputStream will not be modified or closed.
Response
protected URL processResponse(URL url, org.apache.commons.httpclient.HttpMethod method) throws MalformedURLException
method
- the executed method
MalformedURLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |