private void urlCheck(final String url, final LinkListener listener) { HttpRequest request = new HttpRequest(HttpMethods.GET); request.setUrl(url); request.setTimeOut(TIMEOUT_MS); Gdx.net.sendHttpRequest(request, new HttpResponseListener() { @Override public void handleHttpResponse(HttpResponse httpResponse) { if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) { listener.ok(url); } else { listener.ko(url); } } @Override public void failed(Throwable t) { listener.ko(url); } @Override public void cancelled() { listener.ko(url); } }); }
public HttpClientResponse (HttpURLConnection connection) throws IOException { this.connection = connection; try { this.status = new HttpStatus(connection.getResponseCode()); } catch (IOException e) { this.status = new HttpStatus(-1); } }
@Override public void handleHttpResponse(HttpResponse httpResponse) { HttpStatus status = httpResponse.getStatus(); if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) { String result = httpResponse.getResultAsString(); Gdx.app.debug("Score response", "ScoresList recieved !"); Gdx.app.debug("Score response", result); @SuppressWarnings("unchecked") LinkedList<JsonValue> list = json.fromJson(LinkedList.class, result); if (list != null) { for (JsonValue jsonValue : list) { remoteScores.add(json.readValue(RemoteScore.class, jsonValue)); } Gdx.app.debug("Remote list size", ""+remoteScores.size()); } else { Gdx.app.debug("Score response", "No data to process !"); } Gdx.app.debug("Score response", "Process data"); processor.processList(remoteScores); } else { Gdx.app.debug("Score response", "http error, code : "+status.getStatusCode()); showDialog(); } }
private String[][] getTAPData(String url, boolean hip, final String format, final GaiaDataListener listener) { HttpRequest request = new HttpRequest(HttpMethods.GET); request.setUrl(url); request.setTimeOut(5000); Gdx.net.sendHttpRequest(request, new HttpResponseListener() { @Override public void handleHttpResponse(HttpResponse httpResponse) { if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) { // Ok listener.ok(isToArray(httpResponse.getResultAsStream(), format), hip); } else { // Ko with code listener.ko(httpResponse.getStatus().toString()); } } @Override public void failed(Throwable t) { // Failed listener.ko(); } @Override public void cancelled() { // Cancelled listener.ko(); } }); return null; }
public HttpStatus getStatus () { return status; }
@Test void parseJsonExpiredResult() throws IOException { final InputStream resultStream = TestUtils.getResourceRequestStream("testsResources/SearchGc_ExpiredResult.txt"); final CB_List<AbstractCache> cacheList = new CB_List<>(); final CB_List<LogEntry> logList = new CB_List<>(); final CB_List<ImageEntry> imageList = new CB_List<>(); final SearchGC searchGC = new SearchGC(apiKey, "GC1T33T") { protected void writeLogToDB(final LogEntry logEntry) { logList.add(logEntry); } protected void writeImagEntryToDB(final ImageEntry imageEntry) { imageList.add(imageEntry); } protected void writeCacheToDB(final AbstractCache cache) { cacheList.add(cache); } }; final AtomicBoolean WAIT = new AtomicBoolean(true); Net.HttpResponse response = new Net.HttpResponse() { @Override public byte[] getResult() { return new byte[0]; } @Override public String getResultAsString() { return null; } @Override public InputStream getResultAsStream() { return resultStream; } @Override public HttpStatus getStatus() { return null; } @Override public String getHeader(String name) { return null; } @Override public Map<String, List<String>> getHeaders() { return null; } }; searchGC.handleHttpResponse(response, new GenericCallBack<ApiResultState>() { @Override public void callBack(ApiResultState value) { assertTrue(value == ApiResultState.EXPIRED_API_KEY, "ApiResult must be 'Key Expired'"); WAIT.set(false); } }); while (WAIT.get()) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Test void parseResult() { final GetYourUserProfile getYourUserProfile = new GetYourUserProfile(apiKey); Net.HttpResponse response = new Net.HttpResponse() { @Override public byte[] getResult() { return new byte[0]; } @Override public String getResultAsString() { return API_RESULT_JSON; } @Override public InputStream getResultAsStream() { return null; } @Override public HttpStatus getStatus() { return null; } @Override public String getHeader(String name) { return null; } @Override public Map<String, List<String>> getHeaders() { return null; } }; getYourUserProfile.handleHttpResponse(response, new GenericCallBack<ApiResultState>() { @Override public void callBack(ApiResultState value) { assertThat("Type should be 3", getYourUserProfile.getMembershipType() == ApiResultState.MEMBERSHIP_TYPE_PREMIUM); assertEquals(getYourUserProfile.getMemberName(), "LONGRI", "name should be LONGRI"); } }); }
public void sendDenied() { responseListener.apiError(new HttpStatus(400), "Bad Request"); }
/** Returns the {@link HttpStatus} containing the statusCode of the HTTP response. */ HttpStatus getStatus ();
public HttpClientResponse (Response response) { this.response = response; this.status = new HttpStatus(response.getStatusCode()); }
@Override public HttpStatus getStatus () { return status; }
private void startLoading(final TextureTile tile) { // Early exit if cache hit byte[] bytes = cache.get(tile.getURL()); if(bytes != null && loadTile(tile, bytes)) { addToTiledMap(tile); return; } // Request tile from back end final Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET); httpRequest.setUrl(tile.getURL()); Net.HttpResponseListener listener = new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode() != HttpStatus.SC_OK) { logger.error("Invalid response from server, HTTP status: " + httpResponse.getStatus().getStatusCode()); return; } final byte[] content = httpResponse.getResult(); Gdx.app.postRunnable( new Runnable() { @Override public void run() { if(loadTile(tile, content)) { addToTiledMap(tile); } } } ); } @Override public void failed(Throwable t) { logger.error("Could not load from server", t); } @Override public void cancelled() { logger.error("Request was cancelled"); } }; Gdx.net.sendHttpRequest(httpRequest, listener); }
public HttpClientResponse(int status, Int8Array response, XMLHttpRequest request) { this.response = response; this.status = new HttpStatus(status); this.request = request; }
public void apiError(HttpStatus response, String data);