Java Code Examples for com.google.gwt.http.client.Response.getStatusCode()

The following are Jave code examples for showing how to use getStatusCode() 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: sig-seguimiento-vehiculos   File: AbstractGitHubGetListRequest.java   View Source Code Vote up 6 votes
protected RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 2
Project: sig-seguimiento-vehiculos   File: GitHubGetRepositoryListRequest.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 3
Project: sig-seguimiento-vehiculos   File: GitHubGetFileRequest.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 4
Project: sig-seguimiento-vehiculos   File: GitHubUpdateFileExporter.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 5
Project: gwt-jackson-rest   File: RestRequestCallback.java   View Source Code Vote up 6 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if (isSuccessStatusCode(response)) {
        if (null != callback) {
            R result;
            if (null != responseConverter && null != response.getText() && !response.getText().isEmpty()) {
                try {
                    result = responseConverter.read(response.getText());
                } catch (Exception e) {
                    onError(request, e);
                    return;
                }
            } else {
                result = null;
            }
            callback.onSuccess(response, result);
        }
    } else {
        if (null != callback) {
            callback.onError(response);
        } else {
            throw new RestException("An error occured. Status : " + response.getStatusCode());
        }
    }
}
 
Example 6
Project: che   File: AsyncRequestCallback.java   View Source Code Vote up 6 votes
/**
 * @see
 *     com.google.gwt.http.client.RequestCallback#onResponseReceived(com.google.gwt.http.client.Request,
 *     com.google.gwt.http.client.Response)
 */
@Override
public final void onResponseReceived(Request request, Response response) {
  if (loader != null) {
    loader.hide();
  }

  // If there is no connection to the server then status equals 0 ( In Internet Explorer status is
  // 12029 )
  if (response.getStatusCode() == 0 || response.getStatusCode() == 12029) {
    onServerDisconnected();
    return;
  }

  if (response.getStatusCode() == HTTPStatus.UNAUTHORIZED) {
    onUnauthorized(response);
    return;
  }

  if (isSuccessful(response)) {
    handleSuccess(response);
  } else {
    handleFailure(response);
  }
}
 
Example 7
Project: che   File: AsyncRequestCallback.java   View Source Code Vote up 6 votes
protected final boolean isSuccessful(Response response) {
  if (successCodes == null) {
    successCodes = DEFAULT_SUCCESS_CODES;
  }

  if ("Authentication-required".equals(response.getHeader(HTTPHeader.JAXRS_BODY_PROVIDED))) {
    return false;
  }

  for (int code : successCodes) {
    if (response.getStatusCode() == code) {
      return true;
    }
  }
  return false;
}
 
Example 8
Project: geowe-core   File: AbstractGitHubGetListRequest.java   View Source Code Vote up 6 votes
protected RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 9
Project: geowe-core   File: GitHubGetRepositoryListRequest.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 10
Project: geowe-core   File: GitHubGetFileRequest.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 11
Project: geowe-core   File: GitHubUpdateFileExporter.java   View Source Code Vote up 6 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example 12
Project: preferanser   File: ErrorHandlingRestyGwtRequestListener.java   View Source Code Vote up 6 votes
@Override public void afterClientErrorHandled(Method method, Request request, Response response) {
    String errorMessage;
    switch (response.getStatusCode()) {
        case 0:
            return; // Ignore
        case 401: // Unauthorized
            placeManager.revealDefaultPlace();
            errorMessage = "Для просмотра данной страницы необходимо войти в систему.";
            break;
        case 404: // Not found
            errorMessage = "Объект не найден.";
            break;
        default:
            errorMessage = "HTTP response error: " + response.getText();
            Window.alert("Обработка запроса завершилась ошибкой. " +
                "Подробная информация об ошибке доступна в консоли браузера. " +
                "Пожалуйста, обновите текущую страницу или начните с главной.");
    }

    log.severe(errorMessage);
}
 
Example 13
Project: droopy   File: Main.java   View Source Code Vote up 6 votes
public final void onResponseReceived(final Request request, final Response response) {
  final String text = response.getText();
  if (text.isEmpty()) {
    final int code = response.getStatusCode();
    final String errmsg;
    if (code == 0) {  // Happens when a cross-domain request fails to connect.
      errmsg = ("Failed to connect to " + server + ", check that the server"
                + " is up and that you can connect to it.");
    } else {
      errmsg = ("Empty response from server: code=" + code
                + " status=" + response.getStatusText());
    }
    onError(request, new RuntimeException(errmsg));
  } else {
    JSONValue value;
    try {
      value = JSONParser.parseStrict(text);
    } catch (JSONException e) {
      onError(request, e);
      return;
    }
    onSuccess(value);
  }
}
 
Example 14
Project: sig-seguimiento-vehiculos   File: GitHubCreateFileExporter.java   View Source Code Vote up 5 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();
				message = response.getStatusText();
				defaultCodeError = response.getStatusCode();

			} catch (Throwable t) {
				message = t.getMessage();
			}

			messageDialogBuilder.createError(
					UIMessages.INSTANCE.warning() + " " + defaultCodeError,
					message).show();

			return false;
		}
	};
}
 
Example 15
Project: optashift-employee-rostering   File: FailureShownRestCallback.java   View Source Code Vote up 5 votes
@Override
public void onError(Response response) {
    String message = "Error calling REST method with status (" + response.getStatusCode() + ": " + response.getStatusText() + ") and text (" +
        response.getText() + ").";
    ErrorPopup.show(message);
    throw new IllegalStateException(message);
}
 
Example 16
Project: cuba   File: CubaXhrConnection.java   View Source Code Vote up 5 votes
@Override
protected XhrResponseHandler createResponseHandler() {
    return new XhrResponseHandler() {
        protected int serverTimeOnClient;

        @Override
        public void onResponseReceived(Request request, Response response) {
            int statusCode = response.getStatusCode();
            if (statusCode == 200) {
                serverTimeOnClient = (int) Util.round(Profiler.getRelativeTimeMillis() - requestStartTime, 0);
            }
            super.onResponseReceived(request, response);
        }

        @Override
        protected void beforeHandlingMessage(ValueMap json) {
            super.beforeHandlingMessage(json);
            ScreenClientProfiler profiler = ScreenClientProfiler.getInstance();
            String profilerMarker = ScreenClientProfiler.getProfilerMarkerFromJson(json);
            if (profilerMarker != null) {
                int serverTimeOnServer = ScreenClientProfiler.getServerTimeFromJson(json);
                if (serverTimeOnServer > 0) {
                    profiler.registerServerTime(profilerMarker, serverTimeOnServer);
                    profiler.registerNetworkTime(profilerMarker, serverTimeOnClient - serverTimeOnServer);
                } else {
                    profiler.registerServerTime(profilerMarker, serverTimeOnClient);
                }
                profiler.registerEventTs(profilerMarker, ScreenClientProfiler.getEventTsFromJson(json));
            }
        }
    };
}
 
Example 17
Project: che   File: AsyncRequestCallback.java   View Source Code Vote up 5 votes
private void handleSuccess(Response response) {
  try {
    if (unmarshaller != null) {
      // It's needed for handling a situation when response DTO object is NULL
      if (response.getStatusCode() != Response.SC_NO_CONTENT) {
        unmarshaller.unmarshal(response);
      }
      payload = unmarshaller.getPayload();
    }

    onSuccess(payload);
  } catch (Exception e) {
    onFailure(e);
  }
}
 
Example 18
Project: geowe-core   File: GitHubCreateFileExporter.java   View Source Code Vote up 5 votes
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();
				message = response.getStatusText();
				defaultCodeError = response.getStatusCode();

			} catch (Throwable t) {
				message = t.getMessage();
			}

			messageDialogBuilder.createError(
					UIMessages.INSTANCE.warning() + " " + defaultCodeError,
					message).show();

			return false;
		}
	};
}
 
Example 19
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 20
Project: opennmszh   File: Application.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updateTimelineChart(ChartUtils.convertJSONToDataTable(response.getText()));
    }

}
 
Example 21
Project: opennmszh   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(response.getText()));
    }else {
        //updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(DefaultNodeService.SNMP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get SnmpInterfaces");
    }
}
 
Example 22
Project: opennmszh   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(response.getText()));
    } else {
        //updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(DefaultNodeService.IP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get IpInterfaces");
    }
}
 
Example 23
Project: FallenGalaxy   File: Action.java   View Source Code Vote up 5 votes
public void onResponseReceived(Request request, Response response) {
	if (callback != null) {
		if (response.getStatusCode() == 200) {
			if (!uri.toLowerCase().contains("polling")) {
				int lag = (int) (System.currentTimeMillis() - startTime);
				totalLag += lag;
				lastLag = lag;
				requestsCount++;
			}
			
			AnswerData answerData = AnswerData.wrap(response.getText());
			
			String type = answerData.getType();
			
			if (type.equals(AnswerData.TYPE_SUCCESS)) {
				callback.onSuccess(answerData);
			} else if (type.equals(AnswerData.TYPE_ERROR)) {
				callback.onFailure(answerData.getStringData());
			} else if (type.equals(AnswerData.TYPE_CONFIRM_PASSWORD) ||
					type.equals(AnswerData.TYPE_WRONG_PASSWORD)) {
				FaultManager.showConfirmPasswordDialog(uri, params, callback,
						type.equals(AnswerData.TYPE_WRONG_PASSWORD));
			} else if (type.equals(AnswerData.TYPE_DISCONNECTED)) {
				disconnected = true;
				FaultManager.showDisconnectedDialog();
			}
			cleanUp();
		} else {
			retry(String.valueOf(response.getStatusCode()));
		}
	} else {
		if (response.getStatusCode() != 200) {
			retry(String.valueOf(response.getStatusCode()));
		}
		cleanUp();
	}
}
 
Example 24
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 25
Project: OpenNMS   File: Application.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updateTimelineChart(ChartUtils.convertJSONToDataTable(response.getText()));
    }

}
 
Example 26
Project: OpenNMS   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(response.getText()));
    }else {
        //updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(DefaultNodeService.SNMP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get SnmpInterfaces");
    }
}
 
Example 27
Project: OpenNMS   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(response.getText()));
    } else {
        //updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(DefaultNodeService.IP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get IpInterfaces");
    }
}
 
Example 28
Project: OpenNMS   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(response.getText()));
    }else {
        //updatePhysicalInterfaceList(NodeRestResponseMapper.createSnmpInterfaceData(DefaultNodeService.SNMP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get SnmpInterfaces");
    }
}
 
Example 29
Project: OpenNMS   File: PageableNodeList.java   View Source Code Vote up 5 votes
@Override
public void onResponseReceived(Request request, Response response) {
    if(response.getStatusCode() == 200) {
        updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(response.getText()));
    } else {
        //updateIpInterfaceList(NodeRestResponseMapper.createIpInterfaceData(DefaultNodeService.IP_INTERFACES_TEST_RESPONSE));
        showErrorDialogBox("Error attempting to get IpInterfaces");
    }
}
 
Example 30
Project: gwt-jackson-rest   File: RestRequestCallback.java   View Source Code Vote up 4 votes
private boolean isSuccessStatusCode(Response response) {
    int statusCode = response.getStatusCode();
    return (statusCode >= 200 && statusCode < 300) || statusCode == 304;
}
 
Example 31
Project: libgdxcn   File: GwtNet.java   View Source Code Vote up 4 votes
public HttpClientResponse (Response response) {
	this.response = response;
	this.status = new HttpStatus(response.getStatusCode());
}
 
Example 32
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);
}