Scripting Server

HttpRequest - Reference Documentation

Class implementing the request passed to a scripting servlet.

Instances of this class wrap the HttpServletRequest from the Servlet API and allow scripts easy access to properties of an incoming HTTP connection.

Instances of this class can not be created directly, but are passed as argument to the handleRequest() method.

Form fields and uploaded files can be accessed using the parameters property. It contains all form field names and the associated value. Uploaded files are stored as ByteString values.

Index of Methods

Properties

Type Name Description
String method The HTTP request method (GET, POST, PUT, DELETE, etc)
String contextPath The context path under which the servlet is installed. "" for root.
String servletPath The path that called this servlet
String pathInfo The additional path elements after the servlets URL or null
String queryString The query part of an URL after the '?' or null
String contentType The MIME type of the body of the request or null
String contentLength The length of content in the request
Number localPort The local port that received this request
Object parameters Associative array with form fields
HttpServletRequest nativeRequest The native request

getSession()

Prototype

HttpSession getSession()

Description

Obtain - and possibly create - a session object for this connection

Return

HttpSession The session object associated with this request

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


function testSession(req, res) {
	GPSystem.trace("TestSession");
	var session = req.getSession();
	GPSystem.trace("Session id " + session.id);
	GPSystem.trace("Session is new: " + session.isNew);
	GPSystem.trace("Native object " + session.nativeSession);
}

getEntityAsString()

Prototype

String getEntityAsString()

Description

Read the entity from an HTTP request and return it as String.

Return

String The content of the request's entity as string

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


function testEntityString(req, res) {
	GPSystem.trace("TestEntityString");
	var s = req.getEntityAsString();
	GPSystem.trace("Entity (length=" + s.length + "): " + s)
	res.print(s);
}

getEntityAsXML()

Prototype

XML getEntityAsXML()

Description

Read the entity from an HTTP request and parse as XML structure.

Return

XML The content of the request's entity as XML object

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


function testEntityXML(req, res) {
	GPSystem.trace("TestEntityXML");
	var xml = req.getEntityAsXML();
	GPSystem.trace("Entity: " + xml.toString());
	res.print(xml);
}

getEntityAsInputStream()

Prototype

java.io.InputStream getEntityAsInputStream()

Description

Obtain the input stream to read the entity from the HTTP request.

This method is a special function to provide for backward compatibility with the GPXML class. It may be removed in future releases.

Return

java.io.InputStream The input stream to read the entity

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


function testEntityInputStream(req, res) {
	GPSystem.trace("TestEntityInputStream");
	var is = req.getEntityAsInputStream();

	var parser = new GPXML();
	var r = parser.parse(is);

	GPSystem.trace("Entity: " + r.p.elementValue);
	res.println(r.p.elementValue);
}

getHeaderField()

Prototype

String[] getHeaderField(String fieldName)

Description

Returns a list of values for given header field.

If the field does already exists, then undefined is returned

Arguments

Type Name Description
String fieldName The HTTP header field name

Return

String[] The list of values for this header field

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


function testHeader(req, res) {
	GPSystem.trace("TestHeader");

	var headers = req.getHeaderFieldList();
	GPSystem.trace(headers);
	for (var i = 0; i < headers.length; i++) {
		print(headers[i] + " : " + req.getHeaderField(headers[i]));
	}

	var fieldList = req.getHeaderField("x-test");
	if (fieldList) {
		var str = fieldList[0];
		GPSystem.trace(str);
		res.addHeaderField("y-test", str);
	}
}

getHeaderFieldList()

Prototype

String[] getHeaderFieldList()

Description

Returns a list of header fields contained in the response.

Return

String[] The list of header fields

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


// See getHeaderField for an example