Java Code Examples for com.google.gwt.http.client.Response.SC_OK

The following are Jave code examples for showing how to use SC_OK of the com.google.gwt.http.client.Response class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: platypus-js   File: AppClient.java   View Source Code Vote up 6 votes
public XMLHttpRequest2 syncRequest(String aUrl, ResponseType aResponseType) throws Exception {
	final XMLHttpRequest2 req = syncRequest(aUrl, aResponseType, null, RequestBuilder.GET);
	if (req.getStatus() == Response.SC_OK)
		return req;
	else
		throw new Exception(req.getStatus() + " " + req.getStatusText());
}
 
Example 2
Project: platypus-js   File: AppClient.java   View Source Code Vote up 6 votes
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());
}
 
Example 3
Project: platypus-js   File: AppClient.java   View Source Code Vote up 5 votes
public XMLHttpRequest2 syncApiRequest(String aUrlPrefix, final String aUrlQuery, ResponseType aResponseType) throws Exception {
	String url = apiUrl + (aUrlPrefix != null ? aUrlPrefix : "") + "?" + aUrlQuery;
	final XMLHttpRequest2 req = syncRequest(url, aResponseType, null, RequestBuilder.GET);
	if (req.getStatus() == Response.SC_OK)
		return req;
	else
		throw new Exception(req.getStatus() + " " + req.getStatusText());
}
 
Example 4
Project: gwt-webpoller   File: AbstractHttpRequestFactory.java   View Source Code Vote up 5 votes
/**
 * Return error associated with response.
 *
 * @param response the response.
 * @return the error if any, null otherwise.
 */
@Nullable
protected Throwable getError( @Nonnull final Response response )
{
  final int statusCode = response.getStatusCode();
  if ( Response.SC_OK == statusCode )
  {
    return null;
  }
  else
  {
    return new Exception( "Bad status code: " + statusCode );
  }
}
 
Example 5
Project: sigmah   File: ImportationPresenter.java   View Source Code Vote up 5 votes
private void onSubmit(String result) {
	switch (ServletConstants.getErrorCode(result)) {
		case Response.SC_OK:
			if (view.getAutomatedField().getValue()) {
				doAutomatedImport(result);
			} else {
				loadImportResults(result);
			}
			break;

		default:
			N10N.error(I18N.CONSTANTS.createFormIncomplete(), I18N.MESSAGES.importFormIncompleteDetails(""));
			break;
	}
}
 
Example 6
Project: gwt-comet   File: HTTPRequestCometTransport.java   View Source Code Vote up 5 votes
private void onReceiving(int statusCode, String responseText, boolean connected) {
	if (statusCode != Response.SC_OK) {
		if (!connected) {
			super.disconnect();
			listener.onError(new StatusCodeException(statusCode, responseText), connected);
		}
	}
	else {
		int index = responseText.lastIndexOf(SEPARATOR);
		if (index > read) {
			List<Serializable> messages = new ArrayList<Serializable>();
			
			SplitResult data = separator.split(responseText.substring(read, index), index);
			int length = data.length();
			for (int i = 0; i < length; i++) {
				if (disconnecting) {
					return;
				}
				
				String message = data.get(i);
				if (!message.isEmpty()) {
					parse(message, messages);
				}
			}
			read = index + 1;
			if (!messages.isEmpty()) {
				listener.onMessage(messages);
			}
		}
		
		if (!connected) {
			super.disconnected();
		}
	}
}
 
Example 7
Project: touchkit   File: OfflineModeEntrypoint.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if (response != null && response.getStatusCode() == Response.SC_OK) {
        dispatch(SERVER_AVAILABLE);
    } else {
        dispatch(RESPONSE_TIMEOUT);
    }
}
 
Example 8
Project: swarm   File: GwtRequestDispatcher.java   View Source Code Vote up 4 votes
@Override
public void onResponseReceived(Request nativeRequest, Response nativeResponse)
{
	TransactionRequest request = this.getDispatchedRequest(nativeRequest);
	m_reusedResponse.clear();
	int statusCode = nativeResponse.getStatusCode();
	
	if( statusCode != Response.SC_OK )
	{
		String statusText = nativeResponse.getStatusText();
		m_reusedResponse.setError(E_ResponseError.HTTP_ERROR);
		
		this.onError(nativeRequest, request, m_reusedResponse);
		
		return;
	}
	
	I_JsonObject responseJson = m_jsonFactory.createJsonObject(nativeResponse.getText());
	m_reusedResponse.readJson(m_jsonFactory, responseJson);
	
	if( !(request instanceof TransactionRequestBatch) )
	{
		m_callbacks.onResponseReceived(request, m_reusedResponse);
	}
	else
	{
		if( m_reusedResponse.getError() != E_ResponseError.NO_ERROR )
		{
			this.onError(nativeRequest, request, m_reusedResponse);
			
			return;
		}

		TransactionRequestBatch batch = (TransactionRequestBatch) request;

		I_JsonArray responseList = m_jsonFactory.getHelper().getJsonArray(responseJson, E_JsonKey.responseList);
		
		m_callbacks.onResponseReceived(batch, responseList);
	}
	
	this.m_nativeRequestMap.remove(nativeRequest);
}
 
Example 9
Project: sigmah   File: ServletConstants.java   View Source Code Vote up 3 votes
/**
 * Parse the error message and return the embeded error code as an integer. If the message does not denote an error,
 * 200 is returned.
 * 
 * @param message
 *          Message returned by a servlet.
 * @return The error code if available, 200 otherwise.
 */
public static int getErrorCode(String message) {
	if (!isErrorResponse(message)) {
		return Response.SC_OK;
	} else {
		return Integer.parseInt(message.substring(1));
	}
}