SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

URLConnection - Reference Documentation

Class implementing an URL connection to a resource. This class can be used to put, get, post or delete local and remote resources (CRUD operations).

Index of Methods

Properties

TypeNameDescription
NumberresponseCodeThe HTTP response code
StringresponseMessageThe HTTP response message
StringcontentEncodingThe encoding format for the content
StringcontentLengthThe length of the content
StringcontentTypeThe content type
DatedateThe date form the header field
DateexpirationThe expiration from the header field
DatelastModifiedThe date of last modification from the header field

Constructor

Prototype

URLConnection(String url)

Description

Create a connection object to access a resource identified by the URL.

Arguments

TypeNameDescription
StringurlURL of the resource to access

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var cwd = GPSystem.mapFilename("urltest.dat", GPSystem.CWD);

var urlConnection = new URLConnection("file:" + cwd);

get()

Prototype

String get()

Description

Read from the resource the full content as string.

Return

StringThe content of the resource as string

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var page = urlConnection.get();
assert(page.equals("Hello World\n"));

post()

Prototype

String post(String str)

Description

Write the text to the resource and receive response.

Arguments

TypeNameDescription
StringstrThe content to write

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var url = "http://localhost:8081/scriptingservlet/";
var urlConnection = new URLConnection(url + "admin?restart");

var page = urlConnection.get();
print("GET:\n" + page);
print(urlConnection.responseCode + " - " + urlConnection.responseMessage);
print("ContentEncoding : " + urlConnection.contentEncoding);
print("ContentLength : " + urlConnection.contentLength);
print("ContentType : " + urlConnection.contentType);
print("Date : " + urlConnection.date);
print("Expiration : " + urlConnection.expiration);
print("Last Modified : " + urlConnection.lastModified);

assert(urlConnection.responseCode == 200);


var urlConnection = new URLConnection(url + "admin");

var script = "GPSystem.trace(\"Hello World\");\n";

var result = urlConnection.post(script);
print("POST:\n" + result);

var result = urlConnection.post(script);
print("POST:\n" + result);


var urlConnection = new URLConnection(url + "admin");

var page = urlConnection.get();
print("GET:\n" + page);


put()

Prototype

String put(String str)

Description

Write the text to the resource and receive response.

Arguments

TypeNameDescription
StringstrThe content to write

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var url = "http://localhost:8081/scriptingservlet/";
var urlConnection = new URLConnection(url + "admin?restart");

var page = urlConnection.get();
print("GET:\n" + page);


var urlConnection = new URLConnection(url + "admin");

var script = "GPSystem.trace(\"Hello World\");\n";

var result = urlConnection.put(script);
print("PUT:\n" + result);

var result = urlConnection.put(script);
print("PUT:\n" + result);


var urlConnection = new URLConnection(url + "admin");

var page = urlConnection.get();
print("GET:\n" + page);


deleteResource()

Prototype

void deleteResource()

Description

Delete the resource.

The delete operation only works for connections using HTTP.

The method is not named "delete" because delete is a reserved name in the Rhino JavaScript implementation.

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var url = "http://localhost:8081/scriptingservlet/";

var urlConnection = new URLConnection(url + "admin");

urlConnection.deleteResource();