• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java XMLHttpRequest类的典型用法和代码示例

java 10次浏览

本文整理汇总了Java中com.google.gwt.xhr.client.XMLHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java XMLHttpRequest类的具体用法?Java XMLHttpRequest怎么用?Java XMLHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

XMLHttpRequest类属于com.google.gwt.xhr.client包,在下文中一共展示了XMLHttpRequest类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: scriptSync

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Load javascript files synchronously and evalue/execute them directly too.
 * You can also add them at the head of the html-document with
 * Vertx.addLibrariesJs(), which is the same but more 'to the rules'. You
 * need this if you want to use the javascript right after loading it (which
 * is normal in most cases).
 * 
 * @param jss
 *            javascript file(s)
 * @return this
 */
public Fluent scriptSync(String... jss) {
	if (!GWT.isClient()) {
		return this;
	}
	for (String js : jss) {
		XMLHttpRequestSyc xhr = (XMLHttpRequestSyc) XMLHttpRequestSyc.create();
		xhr.setOnReadyStateChange(a -> {
			if (a.getReadyState() == XMLHttpRequest.DONE && a.getStatus() == 200) {
				eval(xhr.getResponseText());
			}
		});
		xhr.open("GET", js, false);
		xhr.send();
	}
	return this;
}
 

开发者ID:nielsbaloe,
项目名称:vertxui,
代码行数:28,
代码来源:Fluent.java

示例2: ajax

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public static <I, O> void ajax(String protocol, String url, I model, ObjectMapper<I> inMapper,
		ObjectMapper<O> outMapper, BiConsumer<Integer, O> handler) {
	XMLHttpRequest xhr = XMLHttpRequest.create();
	xhr.setOnReadyStateChange(a -> {
		if (handler == null || xhr.getReadyState() != 4) {
			return;
		}
		O result = null;
		if (xhr.getStatus() == 200) {
			result = out(xhr.getResponseText(), outMapper);
		}
		handler.accept(xhr.getStatus(), result);
	});
	xhr.open(protocol, url);
	xhr.send(in(model, inMapper));
}
 

开发者ID:nielsbaloe,
项目名称:vertxui,
代码行数:17,
代码来源:Pojofy.java

示例3: jsLogout

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public JavaScriptObject jsLogout(final JavaScriptObject onSuccess, final JavaScriptObject onFailure) throws Exception {
	return Utils.publishCancellable(requestLogout(new CallbackAdapter<XMLHttpRequest, XMLHttpRequest>() {

		@Override
		protected void doWork(XMLHttpRequest aResult) throws Exception {
			Utils.invokeJsFunction(onSuccess);
		}

		@Override
		public void onFailure(XMLHttpRequest reason) {
			try {
				Utils.executeScriptEventVoid(onFailure, onFailure, Utils.toJs(reason.getStatusText()));
			} catch (Exception ex) {
				Logger.getLogger(AppClient.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
	}));
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:19,
代码来源:AppClient.java

示例4: requestLogout

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public Cancellable requestLogout(final Callback<XMLHttpRequest, XMLHttpRequest> aCallback) throws Exception {
	String query = param(PlatypusHttpRequestParams.TYPE, String.valueOf(Requests.rqLogout));
	return startApiRequest(null, query, null, RequestBuilder.GET, null, new CallbackAdapter<XMLHttpRequest, XMLHttpRequest>() {

		@Override
		protected void doWork(XMLHttpRequest aResult) throws Exception {
			principal = null;
			aCallback.onSuccess(aResult);
		}

		@Override
		public void onFailure(XMLHttpRequest reason) {
			aCallback.onFailure(reason);
		}

	});
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:18,
代码来源:AppClient.java

示例5: syncRequest

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public XMLHttpRequest2 syncRequest(String aUrl, ResponseType aResponseType, String aBody, RequestBuilder.Method aMethod) throws Exception {
	final XMLHttpRequest2 req = XMLHttpRequest.create().<XMLHttpRequest2> cast();
	aUrl = Loader.URL_QUERY_PROCESSOR.process(aUrl);
	req.open(aMethod.toString(), aUrl, false);
	interceptRequest(req);
	/*
	 * Since W3C standard about sync XmlHttpRequest and response type. if
	 * (aResponseType != null && aResponseType != ResponseType.Default)
	 * req.setResponseType(aResponseType);
	 */
	req.setRequestHeader("Pragma", "no-cache");
	if (aBody != null)
		req.send(aBody);
	else
		req.send();
	if (req.getStatus() == Response.SC_OK)
		return req;
	else
		throw new Exception(req.getStatus() + " " + req.getStatusText());
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:21,
代码来源:AppClient.java

示例6: loadText

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public void loadText (String url, final AssetLoaderListener<String> listener) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange (XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				if (xhr.getStatus() != 200) {
					listener.onFailure();
				} else {
					listener.onSuccess(xhr.getResponseText());
				}
			}
		}
	});
	setOnProgress(request, listener);
	request.open("GET", url);
	request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	request.send();
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:20,
代码来源:AssetDownloader.java

示例7: loadBinary

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public void loadBinary (final String url, final AssetLoaderListener<Blob> listener) {
	XMLHttpRequest request = XMLHttpRequest.create();		
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange (XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				if (xhr.getStatus() != 200) {
					listener.onFailure();
				} else {
					Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
					listener.onSuccess(new Blob(data));
				}
			}
		}
	});
	setOnProgress(request, listener);
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.send();
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:21,
代码来源:AssetDownloader.java

示例8: createResponse

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
Response createResponse(XMLHttpRequest xmlHttpRequest) {
    return new ResponseImpl(xmlHttpRequest) {

        @Override
        public int getStatusCode() {
          /*
           * http://code.google.com/p/google-web-toolkit/issues/detail?id=5031
           *
           * The XMLHTTPRequest object in IE will return a status code of 1223 and drop some
           * response headers if the server returns a HTTP/204.
           *
           * This issue is fixed in IE10.
           */
            int statusCode = super.getStatusCode();
            return (statusCode == 1223) ? SC_NO_CONTENT : statusCode;
        }
    };
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:20,
代码来源:Request.java

示例9: cancel

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Cancels a pending request. If the request has already been canceled or if
 * it has timed out no action is taken.
 */
public void cancel() {
/*
 * There is a strange race condition that occurs on Mozilla when you cancel
 * a request while the response is coming in. It appears that in some cases
 * the onreadystatechange handler is still called after the handler function
 * has been deleted and during the call to XmlHttpRequest.abort(). So we
 * null the xmlHttpRequest here and that will prevent the
 * fireOnResponseReceived method from calling the callback function.
 * 
 * Setting the onreadystatechange handler to null gives us the correct
 * behavior in Mozilla but crashes IE. That is why we have chosen to fixed
 * this in Java by nulling out our reference to the XmlHttpRequest object.
 */
    if (xmlHttpRequest != null) {
        XMLHttpRequest xmlHttp = xmlHttpRequest;
        xmlHttpRequest = null;

        xmlHttp.clearOnReadyStateChange();
        xmlHttp.abort();

        cancelTimer();
    }
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:28,
代码来源:Request.java

示例10: isPending

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Returns true if this request is waiting for a response.
 *
 * @return true if this request is waiting for a response
 */
public boolean isPending() {
    if (xmlHttpRequest == null) {
        return false;
    }

    int readyState = xmlHttpRequest.getReadyState();

/*
 * Because we are doing asynchronous requests it is possible that we can
 * call XmlHttpRequest.send and still have the XmlHttpRequest.getReadyState
 * method return the state as XmlHttpRequest.OPEN. That is why we include
 * open although it is nottechnically true since open implies that the
 * request has not been sent.
 */
    switch (readyState) {
        case XMLHttpRequest.OPENED:
        case XMLHttpRequest.HEADERS_RECEIVED:
        case XMLHttpRequest.LOADING:
            return true;
    }

    return false;
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:29,
代码来源:Request.java

示例11: fireOnResponseReceived

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public void fireOnResponseReceived(RequestCallback callback) {
    if (xmlHttpRequest == null) {
        // the request has timed out at this point
        return;
    }

    cancelTimer();

/*
 * We cannot use cancel here because it would clear the contents of the
 * JavaScript XmlHttpRequest object so we manually null out our reference to
 * the JavaScriptObject
 */
    final XMLHttpRequest xhr = xmlHttpRequest;
    xmlHttpRequest = null;

    String errorMsg = getBrowserSpecificFailure(xhr);
    if (errorMsg != null) {
        Throwable exception = new RuntimeException(errorMsg);
        callback.onError(this, exception);
    } else {
        Response response = createResponse(xhr);
        callback.onResponseReceived(this, response);
    }
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:26,
代码来源:Request.java

示例12: exists

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public Promise<Boolean> exists()
{
    return new Promise<>((resolve, reject) ->
    {
        XMLHttpRequest request = XMLHttpRequest.create();

        request.open("HEAD", getAbsolutePath());

        request.setOnReadyStateChange(xhr ->
        {
            if (request.getStatus() == 404)
                resolve.invoke(false);

            else if (request.getReadyState() == XMLHttpRequest.DONE && request.getStatus() == 200)
                resolve.invoke(true);
        });

        request.send();
    });
}
 

开发者ID:sriharshachilakapati,
项目名称:SilenceEngine,
代码行数:22,
代码来源:GwtFilePath.java

示例13: readBinaryFile

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void readBinaryFile(FilePath file, UniCallback<DirectBuffer> onComplete, UniCallback<Throwable> onError)
{
    // Create a XMLHttpRequest to load the file into a direct buffer
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("GET", file.getAbsolutePath());

    // Set to read as ArrayBuffer and attach a handler
    request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer);
    request.setOnReadyStateChange(xhr ->
    {
        if (request.getReadyState() == XMLHttpRequest.DONE)
        {
            if (request.getStatus() == 200)
                // Invoke the onComplete handler
                onComplete.invoke(new GwtDirectBuffer(request.getResponseArrayBuffer()));
            else
                onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText()));
        }
    });

    // Send the request
    request.send();
}
 

开发者ID:sriharshachilakapati,
项目名称:SilenceEngine,
代码行数:25,
代码来源:GwtFileReader.java

示例14: readTextFile

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void readTextFile(FilePath file, UniCallback<String> onComplete, UniCallback<Throwable> onError)
{
    // Create a XMLHttpRequest to load the file into a direct buffer
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("GET", file.getAbsolutePath());

    // Set to read as default mode and attach a handler
    request.setResponseType(XMLHttpRequest.ResponseType.Default);
    request.setOnReadyStateChange(xhr ->
    {
        if (request.getReadyState() == XMLHttpRequest.DONE)
        {
            if (request.getStatus() == 200)
                // Invoke the onComplete handler
                onComplete.invoke(request.getResponseText());
            else
                onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText()));
        }
    });

    // Send the request
    request.send();
}
 

开发者ID:sriharshachilakapati,
项目名称:SilenceEngine,
代码行数:25,
代码来源:GwtFileReader.java

示例15: loadShader

点赞 3

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * The GWT shader load is async
 *
 * @param file
 */
public void loadShader(String file, OnTextResourceLoaded listener) {
	XMLHttpRequest request = XMLHttpRequest.create();

	request.setOnReadyStateChange(new ReadyStateChangeHandler() {

		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				// ASYNC
				listener.onResourceLoaded(xhr.getResponseText());
			}
		}
	});

	request.open("GET", GWT.getHostPageBaseURL() + shaderPath + file);
	request.send();
}
 

开发者ID:mobialia,
项目名称:jmini3d,
代码行数:23,
代码来源:ResourceLoader.java

示例16: onModuleLoad

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void onModuleLoad()
{
    // Test media support in browser
    GWT.log("MP3: " + AudioDecoder.isSupported(AudioDecoder.FileFormat.MP3));
    GWT.log("WAV: " + AudioDecoder.isSupported(AudioDecoder.FileFormat.WAV));
    GWT.log("OGG: " + AudioDecoder.isSupported(AudioDecoder.FileFormat.OGG));
    GWT.log("WEBM: " + AudioDecoder.isSupported(AudioDecoder.FileFormat.WEBM));

    String url = Resources.INSTANCE.music().getSafeUri().asString();

    // Create an XMLHttpRequest to load the file from URL
    XMLHttpRequest request = XMLHttpRequest.create();
    request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer);

    request.open("GET", url);

    // Attach a state change listener to check for the loading of the file
    request.setOnReadyStateChange((r) ->
    {
        if (request.getReadyState() == XMLHttpRequest.DONE)
        {
            try
            {
                ArrayBuffer data = request.getResponseArrayBuffer();

                createWebAudioAPIExample(data);
                createOpenALExample(data);
            }
            catch (AudioContextException e)
            {
                e.printStackTrace();
            }
        }
    });

    // Send the request so browser starts loading the file
    request.send();
}
 

开发者ID:sriharshachilakapati,
项目名称:GWT-AL,
代码行数:40,
代码来源:Main.java

示例17: clicked

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private void clicked(Event e) {
	button.setAttribute("disabled", "");
	thinking.getStyle().setProperty("display", "");

	XMLHttpRequest xhr = XMLHttpRequest.create();
	xhr.setOnReadyStateChange(a -> {
		if (xhr.getReadyState() == 4 && xhr.getStatus() == 200) {
			responsed(xhr.getResponseText());
		}
	});
	xhr.open("POST", url);
	xhr.send();
}
 

开发者ID:nielsbaloe,
项目名称:vertxui,
代码行数:14,
代码来源:Client.java

示例18: getText

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public RFuture<String> getText(final String path) {
  final String fullPath = pathPrefix + path;
  /*
   * Except for IE, all browsers support on-domain and cross-domain XHR via
   * {@code XMLHTTPRequest}. IE, on the other hand, not only requires the use
   * of a non-standard {@code XDomainRequest} for cross-domain requests, but
   * doesn't allow on-domain requests to be issued via {@code XMLHTTPRequest},
   * even when {@code Access-Control-Allow-Origin} includes the current
   * document origin. Since we here don't always know if the current request
   * will be cross domain, we try XHR, and then fall back to XDR if the we're
   * running on IE.
   */
  try {
    return doXhr(fullPath, XMLHttpRequest.ResponseType.Default).
      map(new Function<XMLHttpRequest,String>() {
        public String apply (XMLHttpRequest xhr) {
          return xhr.getResponseText();
        }
      });
  } catch (JavaScriptException e) {
    if (Window.Navigator.getUserAgent().indexOf("MSIE") != -1) {
      return doXdr(fullPath).map(new Function<XDomainRequest,String>() {
        public String apply (XDomainRequest xdr) {
          return xdr.getResponseText();
        }
      });
    } else {
      throw e;
    }
  }
}
 

开发者ID:playn,
项目名称:playn,
代码行数:33,
代码来源:HtmlAssets.java

示例19: getBytes

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public RFuture<ByteBuffer> getBytes(final String path) {
  if (!TypedArrays.isSupported()) return RFuture.failure(
    new UnsupportedOperationException("TypedArrays not supported by this browser."));
  return doXhr(pathPrefix + path, XMLHttpRequest.ResponseType.ArrayBuffer).
    map(new Function<XMLHttpRequest,ByteBuffer>() {
      public ByteBuffer apply (XMLHttpRequest xhr) {
        return TypedArrayHelper.wrap(xhr.getResponseArrayBuffer());
      }
    });
}
 

开发者ID:playn,
项目名称:playn,
代码行数:12,
代码来源:HtmlAssets.java

示例20: downloadFile

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private void downloadFile(final String url) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				downloadsInProgress--;
				if (xhr.getStatus() == 200) {
					FileItem entry = getCachedFile(url);
					entry.data = TypedArrays.createUint8Array(xhr.getResponseArrayBuffer());
					entry.dataSize = entry.data.byteLength();
					filesMemoryUsage += entry.dataSize;
					checkFilesMemory();
					context.startProcessing();
					fireReady(url);
					continueDownload();
				} else {
					GWT.log("Error downloading " + url);
					GWT.log("response status: " + xhr.getStatus() + " " + xhr.getStatusText());
					context.setStatus(ProcessingContext.STATUS_ERROR);
					fileCache.get(url).downloadStarted = false;
				}
			}
		}
	});
	request.send();
	fileCache.get(url).downloadStarted = true;
	downloadsInProgress++;
}
 

开发者ID:mateusz-matela,
项目名称:djvu-html5,
代码行数:32,
代码来源:PageDecoder.java

示例21: startApiRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public Cancellable startApiRequest(String aUrlPrefix, final String aUrlQuery, String aBody, RequestBuilder.Method aMethod, String aContentType, Callback<XMLHttpRequest, XMLHttpRequest> aCallback)
        throws Exception {
	String url = apiUrl + (aUrlPrefix != null ? aUrlPrefix : "") + (aUrlQuery != null ? "?" + aUrlQuery : "");
	final XMLHttpRequest req = XMLHttpRequest.create();
	req.open(aMethod.toString(), url);
	if (aContentType != null && !aContentType.isEmpty()) {
		req.setRequestHeader("Content-Type", aContentType);
	}
	interceptRequest(req);
	req.setRequestHeader("Pragma", "no-cache");
	return startRequest(req, aBody, aCallback);
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:13,
代码来源:AppClient.java

示例22: startRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public Cancellable startRequest(SafeUri aUri, ResponseType aResponseType, Callback<XMLHttpRequest, XMLHttpRequest> aCallback) throws Exception {
	final XMLHttpRequest req = XMLHttpRequest.create();
	req.open(RequestBuilder.GET.toString(), aUri.asString());
	interceptRequest(req);
	if (aResponseType != null && aResponseType != ResponseType.Default)
		req.setResponseType(aResponseType);
	req.setRequestHeader("Pragma", "no-cache");
	return startRequest(req, null, aCallback);
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:10,
代码来源:AppClient.java

示例23: isJsonResponse

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private boolean isJsonResponse(XMLHttpRequest aResponse) {
	String responseType = aResponse.getResponseHeader("content-type");
	if (responseType != null) {
		responseType = responseType.toLowerCase();
		return responseType.contains("application/json") || responseType.contains("application/javascript") || responseType.contains("text/json") || responseType.contains("text/javascript");
	} else {
		return false;
	}
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:10,
代码来源:AppClient.java

示例24: isReportResponse

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private boolean isReportResponse(XMLHttpRequest aResponse) {
	String responseType = aResponse.getResponseHeader("content-type");
	if (responseType != null) {
		responseType = responseType.toLowerCase();
		return responseType.contains(REPORT_LOCATION_CONTENT_TYPE);
	} else {
		return false;
	}
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:10,
代码来源:AppClient.java

示例25: Request

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
/**
 * Constructs an instance of the Request object.
 *
 * @param xmlHttpRequest JavaScript XmlHttpRequest object instance
 * @param timeoutMillis number of milliseconds to wait for a response
 * @param callback callback interface to use for notification
 *
 * @throws IllegalArgumentException if timeoutMillis &lt; 0
 * @throws NullPointerException if xmlHttpRequest, or callback are null
 */
public Request(XMLHttpRequest xmlHttpRequest, int timeoutMillis,
        final RequestCallback callback) {
    if (xmlHttpRequest == null) {
        throw new NullPointerException();
    }

    if (callback == null) {
        throw new NullPointerException();
    }

    if (timeoutMillis < 0) {
        throw new IllegalArgumentException();
    }

    this.timeoutMillis = timeoutMillis;

    this.xmlHttpRequest = xmlHttpRequest;

    if (timeoutMillis > 0) {
        // create and schedule a cancel command
        timerId = createTimeout(this, callback, timeoutMillis);
    } else {
        // no Timer required
        timerId = 0;
    }
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:37,
代码来源:Request.java

示例26: setHeaders

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private void setHeaders(XMLHttpRequest xmlHttpRequest)
        throws RequestException {
    if (headers != null && headers.size() > 0) {
        for (Map.Entry<String, String> header : headers.entrySet()) {
            try {
                xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
            } catch (JavaScriptException e) {
                throw new RequestException(e.getMessage());
            }
        }
    } else {
        xmlHttpRequest.setRequestHeader("Content-Type",
                "text/plain; charset=utf-8");
    }
}
 

开发者ID:growbit,
项目名称:turbogwt-http,
代码行数:16,
代码来源:RequestBuilder.java

示例27: addTGACanvas

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
private void addTGACanvas(String url) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if(xhr.getReadyState() == XMLHttpRequest.DONE) {
				if(xhr.getStatus() >= 400) {
					// error
					System.out.println("Error");
				}
				else {
					try {
						ArrayBuffer arrayBuffer = xhr.getResponseArrayBuffer();
						Uint8ArrayNative u8array = Uint8ArrayNative.create(arrayBuffer);
						byte [] buffer = new byte[u8array.length()];
						for(int i=0; i<buffer.length; i++) {
							buffer[i] = (byte)u8array.get(i);
						}
						int pixels [] = TGAReader.read(buffer, TGAReader.ABGR);
						int width = TGAReader.getWidth(buffer);
						int height = TGAReader.getHeight(buffer);
						
						Canvas canvas = createImageCanvas(pixels, width, height);
						panel.add(canvas);
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	});
	request.send();
}
 

开发者ID:npedotnet,
项目名称:TGAReader,
代码行数:37,
代码来源:ImageCanvasTest.java

示例28: cancelHttpRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void cancelHttpRequest (HttpRequest httpRequest) {
	HttpResponseListener httpResponseListener = listeners.get(httpRequest);
	XMLHttpRequest request = requests.get(httpRequest);

	if (httpResponseListener != null && request != null) {
		request.abort();
		httpResponseListener.cancelled();
		requests.remove(httpRequest);
		listeners.remove(httpRequest);
	}
}
 

开发者ID:neuroradiology,
项目名称:TinyVoxel,
代码行数:13,
代码来源:GwtNet.java

示例29: sizeInBytes

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public Promise<Long> sizeInBytes()
{
    return new Promise<>((resolve, reject) ->
    {
        XMLHttpRequest request = XMLHttpRequest.create();

        request.open("HEAD", getAbsolutePath());

        request.setOnReadyStateChange(xhr ->
        {
            if (request.getStatus() == 404)
                resolve.invoke(-1L);

            else if (request.getReadyState() == XMLHttpRequest.DONE && request.getStatus() == 200)
                try
                {
                    resolve.invoke(Long.parseLong(request.getResponseHeader("Content-Length")));
                }
                catch (Exception e)
                {
                    resolve.invoke(0L);
                }
        });

        request.send();
    });
}
 

开发者ID:sriharshachilakapati,
项目名称:SilenceEngine,
代码行数:29,
代码来源:GwtFilePath.java

示例30: sendRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public void sendRequest(MapTile tile, final UrlTileDataSource dataSource) {

		String url = mTileSource.getTileUrl(tile);

		mHttpRequest = XMLHttpRequest.create();
		mHttpRequest.open("GET", url);
		mHttpRequest.setResponseType(ResponseType.ArrayBuffer);

		mResponseHandler = new ReadyStateChangeHandler() {

			@Override
			public void onReadyStateChange(XMLHttpRequest xhr) {
				int state = xhr.getReadyState();
				//log.debug(mCurrentUrl + "response " + status + "/" + state);

				if (state == XMLHttpRequest.DONE) {
					if (xhr.getStatus() == 200) {
						Uint8Array buf = Uint8ArrayNative.create(xhr.getResponseArrayBuffer());
						dataSource.process(new Buffer(buf));
					} else {
						dataSource.process(null);
					}
					mHttpRequest = null;
				}
			}
		};

		mHttpRequest.setOnReadyStateChange(mResponseHandler);
		mHttpRequest.send();
	}
 

开发者ID:opensciencemap,
项目名称:vtm,
代码行数:31,
代码来源:LwHttp.java

示例31: connect

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void connect(int connectionCount) {
	super.connect(connectionCount);
	read = 0;
	
	xmlHttpRequest = XMLHttpRequest.create();
	try {
		xmlHttpRequest.open("GET", getUrl(connectionCount));
		xmlHttpRequest.setRequestHeader("Accept", "application/comet");
		xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
			@Override
			public void onReadyStateChange(XMLHttpRequest request) {
				if (!disconnecting) {
					switch (request.getReadyState()) {
					case XMLHttpRequest.LOADING:
						onReceiving(request.getStatus(), request.getResponseText());
						break;
					case XMLHttpRequest.DONE:
						onLoaded(request.getStatus(), request.getResponseText());
						break;
					}
				}
			}
		});
		xmlHttpRequest.send();
	}
	catch (JavaScriptException e) {
		xmlHttpRequest = null;
		listener.onError(new RequestException(e.getMessage()), false);
	}
}
 

开发者ID:rzschech,
项目名称:gwt-comet,
代码行数:32,
代码来源:HTTPRequestCometTransport.java

示例32: report

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
void report(double timestamp, String streamName, Level level, Object[] objects, Throwable t) {
  // TODO(danilatos): Use a JsoView to construct and then serialize, rather
  // than string builder, unless it's too slow (might even be faster).

  StringBuilder sb = new StringBuilder();
  sb.append("{\"strongName\" : ");
  sb.append(escape(GWT.getPermutationStrongName()));

  sb.append(",\"timestamp\" : ");
  sb.append("" + (long) timestamp);

  sb.append(",\"stream\" : ");
  sb.append(escape(streamName));

  sb.append(",\"level\" : ");
  sb.append(escape(level.name()));

  // Stacktrace info of the first exception found, if any
  if (t != null) {
    sb.append(",\"exception\" : ");
    buildExceptionJson(sb, t);
  }

  sb.append(",\"objects\" : [");
  boolean needsComma = false;
  for (Object o : objects) {
    if (needsComma) {
      sb.append(",");
    } else {
      needsComma = true;
    }
    sb.append(escape(o != null ? o.toString() : "(null)"));
  }

  sb.append("]}");
  String jsonData = sb.toString();

  XMLHttpRequest xhr = XMLHttpRequest.create();
  xhr.open("POST", errorReportUrl + "?firstReport=" + firstReport);
  firstReport = false;
  xhr.send(jsonData);
}
 

开发者ID:ArloJamesBarnes,
项目名称:walkaround,
代码行数:43,
代码来源:ErrorReportingLogHandler.java

示例33: submitForm

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public Cancellable submitForm(String aAction, RequestBuilder.Method aMethod, String aContentType, Map<String, String> aFormData, final Callback<XMLHttpRequest, XMLHttpRequest> aCallback) {
	final XMLHttpRequest req = XMLHttpRequest.create().cast();
	String urlPath = aAction != null ? aAction : "";
	List<String> parameters = new ArrayList<String>();
	for (String paramName : aFormData.keySet()) {
		parameters.add(param(paramName, aFormData.get(paramName)));
	}
               String paramsData = params(parameters.toArray(new String[] {}));
               if(aMethod != RequestBuilder.POST){
                   urlPath += "?" + paramsData;
               }
	req.open(aMethod.toString(), urlPath);
               req.setRequestHeader("Content-Type", aContentType);
	req.setOnReadyStateChange(new ReadyStateChangeHandler() {
                       @Override
		public void onReadyStateChange(final XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				xhr.clearOnReadyStateChange();
				if (aCallback != null) {
                                               try {
                                                       if (xhr.getStatus() == Response.SC_OK) {
                                                               aCallback.onSuccess(xhr);
                                                       } else {
                                                               aCallback.onFailure(xhr);
                                                       }
                                               } catch (Exception ex) {
                                                       Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
                                               }
				}
			}
		}
	});
               if(aMethod == RequestBuilder.POST){
                   req.send(paramsData);
               } else{
                   req.send();
               }
	return new Cancellable() {
		@Override
		public void cancel() {
			req.abort();
		}
	};
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:45,
代码来源:AppClient.java

示例34: interceptRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
protected void interceptRequest(XMLHttpRequest req) {
	// No-op here. Some implementation is in the tests.
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:AppClient.java

示例35: create

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public static native ProgressEvent create(double aLoaded, double aTotal, XMLHttpRequest xhr)/*-{
	return {loaded : aLoaded, total: aTotal, lengthComputable : true, request: xhr};
}-*/;
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:ProgressEvent.java

示例36: getRequest

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
public native final XMLHttpRequest getRequest()/*-{
	return this.request;
}-*/;
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:ProgressEvent.java

示例37: onLoadStart

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void onLoadStart(XMLHttpRequest xhr) {
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:ProgressHandlerAdapter.java

示例38: onAbort

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void onAbort(XMLHttpRequest xhr) {
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:ProgressHandlerAdapter.java

示例39: onError

点赞 2

import com.google.gwt.xhr.client.XMLHttpRequest; //导入依赖的package包/类
@Override
public void onError(XMLHttpRequest xhr) {
}
 

开发者ID:marat-gainullin,
项目名称:platypus-js,
代码行数:4,
代码来源:ProgressHandlerAdapter.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)