You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/07/24 20:47:16 UTC
svn commit: r425182 - in /incubator/xap/trunk/src/xap/requestservice:
HttpRequest.js RequestService.js
Author: mturyn
Date: Mon Jul 24 13:47:16 2006
New Revision: 425182
URL: http://svn.apache.org/viewvc?rev=425182&view=rev
Log:
Introduces HttpRequest, an helper class for the XMLHttpRequest objects wrappered in HttpRequest and used now in RequestService.
Added:
incubator/xap/trunk/src/xap/requestservice/HttpRequest.js (with props)
Modified:
incubator/xap/trunk/src/xap/requestservice/RequestService.js
Added: incubator/xap/trunk/src/xap/requestservice/HttpRequest.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/requestservice/HttpRequest.js?rev=425182&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/requestservice/HttpRequest.js (added)
+++ incubator/xap/trunk/src/xap/requestservice/HttpRequest.js Mon Jul 24 13:47:16 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+Xap.provide('xap.requestservice.HttpRequest');
+Xap.require('xap.util.HttpUtils');
+
+
+
+xap.requestservice.HttpRequest = function(url, method) {
+ this._url = url;
+ this._method = method || 'GET'; /* default is GET */
+ this._headers = {};
+ this._content = null;
+}
+
+xap.requestservice.HttpRequest.prototype.setRequestHeader = function(name, value) {
+ this._headers[name] = value;
+}
+
+xap.requestservice.HttpRequest.prototype.getHeader = function(name) {
+ return this._headers[name] || '';
+}
+
+xap.requestservice.HttpRequest.prototype.getHeaderNames = function() {
+ var headerNames = Array();
+ for (var i in this._headers) {
+ headerNames[headerNames.length] = i;
+ }
+ return headerNames;
+}
+
+xap.requestservice.HttpRequest.prototype.setContent = function(content) {
+ this._content = content;
+}
+
+xap.requestservice.HttpRequest.prototype.getContent = function() {
+ return this._content;
+}
+
+xap.requestservice.HttpRequest.prototype.setRequestMethod = function(method) {
+ this._method = method;
+}
+
+xap.requestservice.HttpRequest.prototype.getRequestMethod = function() {
+ return this._method;
+}
+
+xap.requestservice.HttpRequest.prototype.setUri = function(uri) {
+ this._url = uri;
+}
+
+xap.requestservice.HttpRequest.prototype.getUri = function() {
+ return this._url;
+}
\ No newline at end of file
Propchange: incubator/xap/trunk/src/xap/requestservice/HttpRequest.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/xap/trunk/src/xap/requestservice/RequestService.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/requestservice/RequestService.js?rev=425182&r1=425181&r2=425182&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/requestservice/RequestService.js (original)
+++ incubator/xap/trunk/src/xap/requestservice/RequestService.js Mon Jul 24 13:47:16 2006
@@ -15,24 +15,25 @@
*
*/
-//Let Dojo know what to expect from this file:
-Xap.provide('xap.requestservice.RequestService');
-Xap.require("xap.xml.sax.SaxContentHandler") ;
-Xap.require("xap.xml.sax.SaxParser") ;
-
- /**
- * xap.requestservice.RequestService provides methods for sending and receiving
+/**
+ * RequestService provides methods for sending and receiving
* HTTP messages, and other request based functions.
*/
+
+
+Xap.provide("xap.requestservice.RequestService");
+Xap.require("xap.xml.sax.SaxContentHandler") ;
+Xap.require("xap.xml.sax.SaxParser") ;
+
+
//-----------------------------------------------------------------------
// Constructors.
//-----------------------------------------------------------------------
xap.requestservice.RequestService = function( clientSession ) {
- this._clientSession = clientSession;
+ this._clientSession = clientSession;
}
-
/**
* The response content is assumed to be in XML format and is processed
* automatically by the client.
@@ -42,21 +43,21 @@
*
* @param url, the url will be relative to the application context path always.
* @return The retrieved content (String)
- * @throws xap.requestservice.RequestServiceException, a wrapper exception of either a failed
+ * @throws RequestServiceException, a wrapper exception of either a failed
* network call or a failed response processing. Check the
* <code>getCausalThrowable()</code> and <code>printStackTrace()</code>
* method to find out details.
* <P>
- * The process cause could be <code>xap.xml.sax.ParserException</code> etc.
- * <P><code>xap.xml.sax.ParserException</code>: when the data contains a
+ * The process cause could be <code>ParserException</code> etc.
+ * <P><code>ParserException</code>: when the data contains a
* malformed XML; however, any XML up to the point of malformed data will be
* processed and executed. Also note that a well-formed but non-relevant XML,
* will be ignored during the processing and will not trigger an exception.
*/
-xap.requestservice.RequestService.prototype.retrieveAndProcess = function( url ) {
- var content = this.retrieve( url );
- this._processXmlString( content.responseText );
- return content;
+xap.requestservice.RequestService.prototype.retrieveAndProcess = function(url) {
+ var content = this.retrieve(url);
+ this._processXmlString(content.responseText);
+ return content;
}
/**
@@ -72,12 +73,17 @@
* is finished or an error occurs.
*
*/
-xap.requestservice.RequestService.prototype.retrieveAndProcessAsynchronously = function( url, listener ) {
- var callback = function( response ) {
- this._processXmlString( request.responseText );
- listener.requestCompleted( url, request.responseText );
- };
- xap.util.HttpUtils.get( url, callback );
+xap.requestservice.RequestService.prototype.retrieveAndProcessAsynchronously = function(url, listener) {
+ var self = this;
+ var callback = function(response) {
+ if (response.status == xap.util.HttpUtils.OK) {
+ self._processXmlString(response.responseText);
+ listener.requestCompleted(url, response.responseText);
+ } else {
+ listener.requestFailed(url, response.statusText);
+ }
+ };
+ xap.util.HttpUtils.get(url, callback);
}
/**
@@ -88,11 +94,11 @@
* a full url.
*
* @return The content of the response (String)
- * @throws xap.requestservice.RequestServiceException, a wrapper exception. Check the
+ * @throws RequestServiceException, a wrapper exception. Check the
* <code>getCause()</code> method to find out details.
*/
-xap.requestservice.RequestService.prototype.retrieve = function( url ) {
- return xap.util.HttpUtils.get( url );
+xap.requestservice.RequestService.prototype.retrieve = function(url) {
+ return xap.util.HttpUtils.get(url);
}
@@ -102,19 +108,25 @@
* @param url, if there is no leading slash, it's relative to current context path; if
* there is a leading slash, it's relative to server; or it needs to be a full url.
*
- * @param listener The xap.requestservice.NetServiceListener to asynchronously call back when the retrieve
+ * @param listener The NetServiceListener to asynchronously call back when the retrieve
* is finished or an error occurs.
*/
-xap.requestservice.RequestService.prototype.retrieveAsynchronously = function( url, listener ) {
- var callback = function(response){ listener.requestCompleted(url, response.responseText)};
- xap.util.HttpUtils.get( url, callback );
+xap.requestservice.RequestService.prototype.retrieveAsynchronously = function(url, listener) {
+ var callback = function( response ) {
+ if (response.status == xap.util.HttpUtils.OK) {
+ listener.requestCompleted(url, response.responseText);
+ } else {
+ listener.requestFailed(url, response.statusText);
+ }
+ };
+ xap.util.HttpUtils.get(url, callback);
}
/**
- * Parses the xml string into a xap.xml.dom.Document and then walks the resulting xap.xml.dom.Document
- * dispatching elements to appropriate xap.xml.NamespaceHandlers.
+ * Parses the xml string into a Document and then walks the resulting Document
+ * dispatching elements to appropriate NamespaceHandlers.
*/
xap.requestservice.RequestService.prototype._processXmlString = function( xmlString ) {
- var parser = new xap.xml.sax.SaxParser( new xap.xml.sax.SaxContentHandler() );
- this._clientSession.processDocument( parser.parse( xmlString ) );
-}
+ var parser = new xap.xml.sax.SaxParser( new xap.xml.sax.SaxContentHandler() );
+ this._clientSession.processDocument( parser.parse( xmlString ) );
+}
\ No newline at end of file