Java 类com.badlogic.gdx.net.HttpStatus 实例源码

项目:gaiasky    文件:DesktopNetworkChecker.java   
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);
        }
    });

}
项目:JavityEngine    文件:JavityNetJavaImpl.java   
public HttpClientResponse (HttpURLConnection connection) throws IOException {
    this.connection = connection;
    try {
        this.status = new HttpStatus(connection.getResponseCode());
    } catch (IOException e) {
        this.status = new HttpStatus(-1);
    }
}
项目:RottenCave    文件:ListListener.java   
@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();
    }
}
项目:gaiasky    文件:GaiaCatalogWindow.java   
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;
}
项目:JavityEngine    文件:JavityNetJavaImpl.java   
public HttpStatus getStatus () {
    return status;
}
项目:cachebox3.0    文件:SearchGCTest.java   
@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();
        }
    }

}
项目:cachebox3.0    文件:GetYourUserProfileTest.java   
@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");
        }
    });
}
项目:gdx-twitter    文件:DesktopTwitterAPI.java   
public void sendDenied() {
    responseListener.apiError(new HttpStatus(400), "Bad Request");
}
项目:libgdxcn    文件:Net.java   
/** Returns the {@link HttpStatus} containing the statusCode of the HTTP response. */
HttpStatus getStatus ();
项目:libgdxcn    文件:GwtNet.java   
public HttpClientResponse (Response response) {
    this.response = response;
    this.status = new HttpStatus(response.getStatusCode());
}
项目:libgdxcn    文件:GwtNet.java   
@Override
public HttpStatus getStatus () {
    return status;
}
项目:libgdx-maps    文件:MapManager.java   
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);
    }
项目:TinyVoxel    文件:GwtNet.java   
public HttpClientResponse(int status, Int8Array response, XMLHttpRequest request) {
    this.response = response;
    this.status = new HttpStatus(status);
          this.request = request;
}
项目:TinyVoxel    文件:GwtNet.java   
@Override
public HttpStatus getStatus () {
    return status;
}
项目:gdx-twitter    文件:TwitterResponseListener.java   
public void apiError(HttpStatus response, String data);