本文整理汇总了Java中org.eclipse.jetty.client.api.ContentResponse.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResponse.getStatus方法的具体用法?Java ContentResponse.getStatus怎么用?Java ContentResponse.getStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.api.ContentResponse
的用法示例。
在下文中一共展示了ContentResponse.getStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseSendirResponse
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private void parseSendirResponse(final ContentResponse response) {
final String responseContent = response.getContentAsString();
if ((responseContent == null) || responseContent.isEmpty()) {
throw new CommunicationException("Empty response received!");
}
if (responseContent.startsWith(SENDIR_SUCCESS)) {
return;
}
if (responseContent.startsWith(SENDIR_BUSY)) {
throw new DeviceBusyException("Device is busy!");
}
if ((response.getStatus() != HttpStatus.OK_200) || responseContent.startsWith(SENDIR_ERROR)) {
throw new CommunicationException(String.format("Failed to send IR code: %s", responseContent));
}
}
示例2: getResponseJson
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private static JsonElement getResponseJson(ContentResponse response) {
if (response.getStatus() != 200) {
throw new ResponseException(response.getStatus());
}
JsonElement json = GsonUtil.jsonParser.parse(response.getContentAsString());
Integer retCode = json.getAsJsonObject().get("retcode").getAsInt();
if (retCode == null || retCode != 0) {
if (retCode != null && retCode == 103) {
LOGGER.error("请求失败,Api返回码[103]。你需要进入http://w.qq.com,检查是否能正常接收消息。如果可以的话点击[设置]->[退出登录]后查看是否恢复正常");
throw new ApiException(
"请求失败,Api返回码[103]。你需要进入http://w.qq.com,检查是否能正常接收消息。如果可以的话点击[设置]->[退出登录]后查看是否恢复正常");
} else {
throw new ApiException(retCode);
}
}
return json;
}
示例3: rawRequest
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
protected String rawRequest(String url, Map<String, String> params) throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
Request req = httpClient.newRequest(new String(url.getBytes("UTF-8"), "UTF-8"))
.header(HttpHeader.CONTENT_ENCODING, "UTF-8")
.method(HttpMethod.GET)
.header(HttpHeader.ACCEPT_ENCODING, "UTF-8");
req = req.param("app_token", APIKeys.getAPPKey());
if (params != null) {
for (String key : params.keySet()) {
req = req.param(key, params.get(key));
}
}
Main.log.info("GET {}, {}, {}", req, req.getQuery(), req.getParams());
ContentResponse resp = req.send();
if (resp.getStatus() != HttpStatus.OK_200) {
throw new HttpRequestException(
"Request ended with non-OK status: "
+ HttpStatus.getMessage(resp.getStatus()),
resp.getRequest()
);
}
return resp.getContentAsString();
}
示例4: doExecuteRequest
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Override
protected RemoteInvocationResult doExecuteRequest(
HttpInvokerClientConfiguration config, ByteArrayOutputStream baos)
throws Exception {
if (this.connectTimeout >= 0) {
httpClient.setConnectTimeout(this.connectTimeout);
}
if (this.readTimeout >= 0) {
httpClient.setIdleTimeout(this.readTimeout);
}
ContentResponse response = httpClient.newRequest(config.getServiceUrl())
.method(HttpMethod.POST)
.content(new BytesContentProvider(baos.toByteArray()))
.send();
if (response.getStatus() >= 300) {
throw new IOException(
"Did not receive successful HTTP response: status code = " + response.getStatus() +
", status message = [" + response.getReason() + "]");
}
return readRemoteInvocationResult(new ByteArrayInputStream(response.getContent()), config.getCodebaseUrl());
}
示例5: getMetaData
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
String getMetaData(String path) {
final String baseUri = "http://169.254.169.254/latest";
ContentResponse response = null;
try {
response = httpClient.GET(baseUri + path);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error("CloudStore: unable to fetch requested uri '" + path + "': "
+ e.getMessage());
return null;
}
if (response.getStatus() != 200) {
LOGGER.error("CloudStore: unable to fetch requested uri '" + path +
"' status: " + response.getStatus());
return null;
}
String data = response.getContentAsString();
if (data == null || data.isEmpty()) {
LOGGER.error("CloudStore: received empty response from uri '" + path +
"' status: " + response.getStatus());
return null;
}
return data;
}
示例6: updateHealthStatus
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
public void updateHealthStatus(HealthCheck.Status status) throws Exception {
logger.trace("Updating health of {}", serviceProps.getServiceName());
ContentResponse httpResponse = httpClient.newRequest(getHealthCheckUri(status)).send();
if (httpResponse.getStatus() != 200) {
logger.warn("Received {} trying to update health", httpResponse.getStatus());
}
}
示例7: sendRegistration
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private boolean sendRegistration(JsonObject request) {
try {
ContentResponse httpResponse = httpClient.newRequest(getRegistrationUri()).
content(new StringContentProvider(request.toString())).
method(HttpMethod.PUT).header(HttpHeader.CONTENT_TYPE, "application/json").send();
if (httpResponse.getStatus() == 200) {
return true;
}
} catch (Exception ex) {
logger.warn("Caught exception sending registration {}", request.toString(), ex);
}
return false;
}
示例8: postWithRetry
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private ContentResponse postWithRetry(ApiURL url, JsonObject r)
throws InterruptedException, ExecutionException, TimeoutException {
int times = 0;
ContentResponse response;
do {
response = post(url, r);
times++;
} while (times < RETRY_TIMES && response.getStatus() != 200);
return response;
}
示例9: checkSendMsgResult
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private static void checkSendMsgResult(ContentResponse response) {
if (response.getStatus() != 200) {
LOGGER.error(String.format("发送失败,Http返回码[%d]", response.getStatus()));
throw new ResponseException(response.getStatus());
}
JsonElement json = GsonUtil.jsonParser.parse(response.getContentAsString());
Integer apiReturnCode = json.getAsJsonObject().get("retcode").getAsInt();
if (apiReturnCode != null && apiReturnCode == 0) {
LOGGER.debug("发送成功!");
} else {
LOGGER.error(String.format("发送失败,Api返回码[%d]", apiReturnCode));
throw new ApiException(apiReturnCode);
}
}
示例10: submit
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(SSLContext.getDefault());
HttpClient httpClient = new HttpClient(sslContextFactory);
// Configure HttpClient here
httpClient.start();
ResponseEntity<String> responseEntity = null;
for (int i=0;i< requestOptions.getCount();i++) {
final Request request = httpClient
.newRequest(requestOptions.getUrl());
for(Map.Entry<String,String> e : requestOptions.getHeaderMap().entrySet()) {
request.header(e.getKey(), e.getValue());
}
System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
final ContentResponse response = request.send();
int responseCode = response.getStatus();
System.out.println("Response Code : " + responseCode);
String responseContent = IOUtils.toString(response.getContent(), "utf-8");
//print result
System.out.println(responseContent);
responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
}
httpClient.stop();
return responseEntity;
}
示例11: loadRunner
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Override
public JSONObject loadRunner(HttpServletRequest clientRequest, Runner runner) throws Exception {
URI uri = runner.url.resolve("/api/v1/apps");
Request request = httpClient.newRequest(uri)
.timeout(10, TimeUnit.SECONDS)
.method(HttpMethod.GET);
forwardedHeadersAdder.addHeaders(clientRequest, request);
ContentResponse resp;
try {
resp = request.send();
} catch (TimeoutException e) {
throw new TimeoutException("Timed out calling " + uri);
}
if (resp.getStatus() != 200) {
throw new RuntimeException("Unable to load apps from " + uri + " - message was " + resp.getContentAsString());
}
JSONObject info = new JSONObject(resp.getContentAsString());
List<String> addedNames = new ArrayList<>();
for (Object app : info.getJSONArray("apps")) {
String name = ((JSONObject) app).getString("name");
addedNames.add(name);
proxyMap.add(name, uri.resolve("/" + name));
}
for (Map.Entry<String, URI> entry : proxyMap.getAll().entrySet()) {
if (entry.getValue().getAuthority().equals(runner.url.getAuthority())
&& !addedNames.contains(entry.getKey())) {
log.info("Detected a missing app, so will remove it from the proxy map: " + entry.getKey() + " at " + entry.getValue());
proxyMap.remove(entry.getKey());
}
}
return info;
}
示例12: registerRunner
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private static void registerRunner(RestClientThatThrows client, AppRunnerInstance runner, int maxInstances) throws Exception {
log.info("Registering " + runner.httpUrl() + " with the router");
ContentResponse contentResponse = client.registerRunner(runner.id(), runner.httpUrl(), maxInstances);
if (contentResponse.getStatus() != 201) {
throw new RuntimeException("Could not register " + runner.httpUrl() + ": " + contentResponse.getStatus() + " - " + contentResponse.getContentAsString());
}
}
示例13: verify
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private ContentResponse verify(ContentResponse resp) {
int status = resp.getStatus();
if (status <= 99 || status >= 400) {
throw new RuntimeException("Error returned: " + status + " with response: " + resp.getContentAsString());
}
return resp;
}
示例14: start
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
public void start() {
List<AuthBackupReqMessage> backupReqMessages = server.getBackupReqMessages();
final Runnable requester = new Runnable() {
private int failureCount = 0;
private boolean isTrustedAuthAlive = false;
public void run() {
try {
for (AuthBackupReqMessage backupReqMessage: backupReqMessages) {
ContentResponse contentResponse = server.sendBackupReqMessage(backupReqMessage);
logger.info("Response code: " + contentResponse.getStatus());
if (contentResponse.getStatus() == HttpServletResponse.SC_OK) {
logger.info("The request was successfully handled by the trusted Auth, removing the request");
backupReqMessages.remove(backupReqMessage);
}
}
} catch (TimeoutException | ExecutionException | InterruptedException e) {
logger.error("Exception occurred during backup() {}", e.getMessage());
//throw new RuntimeException();
}
finally {
if (!backupReqMessages.isEmpty()) {
scheduler.schedule(this, backupRequestingPeriod, TimeUnit.SECONDS);
}
}
}
};
if (backupRequestingPeriod <= 0) {
logger.info("Not scheduling backup requester since the period is not set.");
return;
}
logger.info("scheduling a task of sending backup requests every " + backupRequestingPeriod + "second(s).");
final ScheduledFuture<?> beeperHandle =
scheduler.schedule(requester, backupRequestingPeriod, TimeUnit.SECONDS);
}
示例15: generateX509Certificate
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Override
public String generateX509Certificate(String csr, String keyUsage, int expiryTime) {
// Key Usage value used in Go - https://golang.org/src/crypto/x509/x509.go?s=18153:18173#L558
// we're only interested in ExtKeyUsageClientAuth - with value of 2
final String extKeyUsage = ZTSConsts.ZTS_CERT_USAGE_CLIENT.equals(keyUsage) ? "2" : null;
ContentResponse response = null;
for (int i = 0; i < requestRetryCount; i++) {
if ((response = processX509CertRequest(csr, extKeyUsage, expiryTime, i + 1)) != null) {
break;
}
}
if (response == null) {
return null;
}
if (response.getStatus() != HttpStatus.CREATED_201) {
LOGGER.error("unable to fetch requested uri '" + x509CertUri +
"' status: " + response.getStatus());
return null;
}
String data = response.getContentAsString();
if (data == null || data.isEmpty()) {
LOGGER.error("received empty response from uri '" + x509CertUri +
"' status: " + response.getStatus());
return null;
}
X509CertSignObject pemCert = null;
try {
pemCert = JSON.fromString(data, X509CertSignObject.class);
} catch (Exception ex) {
LOGGER.error("unable to decode object from '" + x509CertUri +
"' error: " + ex.getMessage());
}
return (pemCert != null) ? pemCert.getPem() : null;
}