|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.ptc.windchill.ws.HttpUtils
public class HttpUtils
Utility class that can be used to upload or download content from the Windchill Web Services API.
// get an instance of ContentHandle from the GetDownloadHandles Windchill Web Services method.
ContentHandle handle = ...
HttpUtils utils = new HttpUtils();
String username, password;
username = password = null;
for (;;) {
try {
if ( username != null ) utils.setUsername ( username );
if ( password != null ) utils.setPassword ( password );
InputStream is = utils.download ( handle );
// read the data from is
break;
} catch ( IOException ioe ) {
if ( utils.getRc() != HttpUtils.HTTP_UNAUTHORIZED )
throw ioe;
else {
// prompt the user for credentials, set the username/password variables and try again.
// the getHost()/getRealm() methods can be used to build a cache to avoid subsequent unauthenticated requests.
}
}
}
// get an instance of ContentHandle from the GetUploadHandles Windchill Web Services method.
ContentHandle handle = ...
File f = ...
HttpUtils utils = new HttpUtils();
String username, password;
username = password = null;
for (;;) {
try {
if ( username != null ) utils.setUsername ( username );
if ( password != null ) utils.setPassword ( password );
utils.upload ( handle, f ).close();
// ignore response from server as long as HTTP_OK
break;
} catch ( IOException ioe ) {
if ( utils.getRc() != HttpUtils.HTTP_UNAUTHORIZED )
throw ioe;
else {
// prompt the user for credentials, set the username/password variables and try again.
// the getHost()/getRealm() methods can be used to build a cache to avoid subsequent unauthenticated requests.
}
}
}
| Constructor Summary | |
|---|---|
HttpUtils()
Creates an HttpUtils object. |
|
HttpUtils(String username,
String password)
Creates an HttpUtils object. |
|
| Method Summary | |
|---|---|
InputStream |
download(ContentHandle handle)
Downloads data from a ContentHandle. |
int |
getContentLength()
Gets the content length of data the server responded with. |
String |
getHost()
Gets the host that upload or download was last performed to. |
String |
getPassword()
Gets the password that will be sent with requests. |
int |
getRc()
Gets the response code issued by the web server in response to a request. |
String |
getRealm()
Gets the realm. |
String |
getUsername()
Gets the username that will be sent with requests. |
void |
setPassword(String password)
Sets the password that will be sent with requests. |
void |
setUsername(String username)
Sets the username that will be sent with requests. |
InputStream |
upload(ContentHandle handle,
DataSource data)
Uploads data from a DataSource to a ContentHandle. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HttpUtils()
setUsername(String)/setPassword(String) methods are called.
setUsername(String),
setPassword(String)
public HttpUtils(String username,
String password)
username - The username.password - The password.| Method Detail |
|---|
public void setUsername(String username)
username - The username.setPassword(String)public String getUsername()
public void setPassword(String password)
password - The password.setUsername(String)public String getPassword()
public int getRc()
IllegalStateException - If the call is not following a call to upload or download where the server was contacted.HTTP_OK,
HTTP_UNAUTHORIZED,
HTTP_INTERNAL_ERROR,
HttpURLConnectionpublic int getContentLength()
IllegalStateException - If call is not subsequent to a call to download.public String getHost()
IllegalStateException - If call is not following upload or download.getRealm()
public String getRealm()
throws IOException
getRc() == HTTP_UNAUTHORIZED).
Only Basic authentication is supported. Can only be called following a call to upload or download
and following an unauthorized server response.
IllegalStateException - If call is not following upload or download.
IOException - If the response is unexpected or there is an issue with the WWW-Authenticate header.getRc(),
getHost()
public InputStream download(ContentHandle handle)
throws IOException
handle - The ContentHandle.
IOException - If an error occurs.getRc()
public InputStream upload(ContentHandle handle,
DataSource data)
throws IOException
handle - The ContentHandle.data - The DataSource object.
IOException - If an error occurs.getRc()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||