本文整理汇总了Java中org.eclipse.jetty.client.api.ContentResponse.getContentAsString方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResponse.getContentAsString方法的具体用法?Java ContentResponse.getContentAsString怎么用?Java ContentResponse.getContentAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.api.ContentResponse
的用法示例。
在下文中一共展示了ContentResponse.getContentAsString方法的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: callSynchronous
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
public String callSynchronous(JsonArray params, OrangeContext orangeContext)
throws RpcCallException {
HttpClientWrapper clientWrapper = loadBalancer.getHttpClientWrapper();
HttpRequestWrapper balancedPost = clientWrapper.createHttpPost(this);
//set custom headers
if (orangeContext != null) {
orangeContext.getProperties().forEach(balancedPost::setHeader);
}
balancedPost.setHeader("Content-type", TYPE_JSON);
//TODO: fix: Temporary workaround below until go services are more http compliant
balancedPost.setHeader("Connection", "close");
JsonRpcRequest jsonRequest = new JsonRpcRequest(null, methodName, params);
String json = jsonRequest.toString();
balancedPost.setContentProvider(new StringContentProvider(json));
logger.debug("Sending request of size {}", json.length());
ContentResponse rpcResponse = clientWrapper.execute(balancedPost,
new JsonRpcCallExceptionDecoder(), orangeContext);
String rawResponse = rpcResponse.getContentAsString();
logger.debug("Json response from the service: {}", rawResponse);
return JsonRpcResponse.fromString(rawResponse).getResult().getAsString();
}
示例3: verifyQRCode
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
private String verifyQRCode() throws InterruptedException, ExecutionException, TimeoutException {
LOGGER.debug("等待扫描二维码");
// 阻塞直到确认二维码认证成功
while (true) {
sleep(1);
ContentResponse response = get(ApiURL.VERIFY_QR_CODE, hash33(qrsig));
String result = response.getContentAsString();
if (result.contains("成功")) {
for (String content : result.split("','")) {
if (content.startsWith("http")) {
LOGGER.info("正在登录,请稍后");
return content;
}
}
} else if (result.contains("已失效")) {
LOGGER.info("二维码已失效");
return null;
}
}
}
示例4: executeRequest
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
Request httpRequest = this.httpClient.newRequest(url).method(method);
addHttpHeaders(httpRequest, headers);
if (body != null) {
httpRequest.content(new StringContentProvider(body));
}
ContentResponse response;
try {
response = httpRequest.send();
}
catch (Exception ex) {
throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
}
HttpStatus status = HttpStatus.valueOf(response.getStatus());
HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
return (response.getContent() != null ?
new ResponseEntity<String>(response.getContentAsString(), responseHeaders, status) :
new ResponseEntity<String>(responseHeaders, status));
}
示例5: 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();
}
示例6: sendMessageToHyVarRec
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
protected String sendMessageToHyVarRec(String message, URI uri) throws UnresolvedAddressException, ExecutionException, InterruptedException, TimeoutException {
HttpClient hyvarrecClient = new HttpClient();
try {
hyvarrecClient.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
URI hyvarrecUri = uri;
Request hyvarrecRequest = hyvarrecClient.POST(hyvarrecUri);
hyvarrecRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
hyvarrecRequest.content(new StringContentProvider(message), "application/json");
ContentResponse hyvarrecResponse;
String hyvarrecAnswerString = "";
hyvarrecResponse = hyvarrecRequest.send();
hyvarrecAnswerString = hyvarrecResponse.getContentAsString();
// Only for Debug
System.err.println("HyVarRec Answer: "+hyvarrecAnswerString);
return hyvarrecAnswerString;
}
示例7: systemCallStillReturnsEvenWhenRunnersAreUnavailable
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Test
public void systemCallStillReturnsEvenWhenRunnersAreUnavailable() throws Exception {
ContentResponse systemResponse = httpClient.get("/api/v1/system");
JSONObject all = new JSONObject(systemResponse.getContentAsString());
assertThat(all.getBoolean("appRunnerStarted"), equalTo(false));
JSONArray runners = all.getJSONArray("runners");
MatcherAssert.assertThat(runners.length(), equalTo(2));
for (Object runnerO : runners) {
JSONObject runner = (JSONObject) runnerO;
if (runner.getJSONObject("system").getBoolean("appRunnerStarted")) {
assertThat(runner.has("error"), is(false));
} else {
assertThat(runner.has("error"), is(true));
}
}
}
示例8: theRestAPILives
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Test
public void theRestAPILives() throws Exception {
JSONObject all = getAllApps();
System.out.println("all = " + all.toString(4));
assertThat(all.getInt("appCount"), is(1));
JSONAssert.assertEquals("{apps:[" +
"{ name: \"maven\", url: \"" + appRunnerUrl + "/maven/\" }" +
"]}", all, JSONCompareMode.LENIENT);
assertThat(restClient.deploy("invalid-app-name"),
is(equalTo(404, is("No app found with name 'invalid-app-name'. Valid names: maven"))));
ContentResponse resp = client.GET(appRunnerUrl + "/api/v1/apps/maven");
assertThat(resp.getStatus(), is(200));
JSONObject single = new JSONObject(resp.getContentAsString());
JSONAssert.assertEquals(all.getJSONArray("apps").getJSONObject(0), single, JSONCompareMode.STRICT_ORDER);
assertThat(single.has("lastBuild"), is(true));
assertThat(single.has("lastSuccessfulBuild"), is(true));
}
示例9: 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;
}
示例10: sendRequest
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
protected String sendRequest(String path, String data, HttpMethod method) throws Exception {
String url = getServiceUrl(path);
Request request = httpClient.newRequest(url).method(method).
header(HttpHeader.CONTENT_TYPE, "application/json");
if (data != null) {
request.content(new StringContentProvider(data));
}
ContentResponse response = request.send();
return response.getContentAsString();
}
示例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: appsAddedToAnInstanceBeforeItJoinsTheClusterAreAvailable
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Test
public void appsAddedToAnInstanceBeforeItJoinsTheClusterAreAvailable() throws Exception {
AppRepo app1 = AppRepo.create("maven");
RestClient direct = RestClient.create(latestAppRunnerWithoutNode.httpUrl().toString());
direct.createApp(app1.gitUrl(), "app1");
direct.deploy(app1.name);
httpClient.registerRunner(latestAppRunnerWithoutNode.id(), latestAppRunnerWithoutNode.httpUrl(), 1);
ContentResponse contentResponse = httpClient.get("/api/v1/apps/app1");
assertThat(contentResponse.getStatus(), is(200));
JSONObject json = new JSONObject(contentResponse.getContentAsString());
JSONAssert.assertEquals("{ 'name': 'app1', 'url': '" + httpClient.routerUrl + "/app1/' }", json, JSONCompareMode.LENIENT);
httpClient.stop(app1.name);
}
示例14: appsReturnsPartialListWhenAnAppRunnerIsAvailableAndHasErrorMessages
import org.eclipse.jetty.client.api.ContentResponse; //导入方法依赖的package包/类
@Test
public void appsReturnsPartialListWhenAnAppRunnerIsAvailableAndHasErrorMessages() throws Exception {
// querying for all the apps returns a combined list
ContentResponse appsResponse = httpClient.get("/api/v1/apps");
JSONObject actual = new JSONObject(appsResponse.getContentAsString());
JSONAssert.assertEquals("{ " +
"'appCount': 1," +
"'apps': [ { 'name': 'app1', 'url': '" + httpClient.targetURI().resolve("/app1/") + "' } ]" +
"}", actual, JSONCompareMode.STRICT_ORDER);
assertThat(actual.getJSONArray("errors").length(), is(1));
}
示例15: 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;
}