当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponse类代码示例

本文整理汇总了Java中io.vertx.ext.web.client.HttpResponse的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponse类属于io.vertx.ext.web.client包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postToDestination

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private void postToDestination(final PostRetry payload) {
	this.initWebClient();
	final HttpRequest<Buffer> request = this.initWebPostRequest(this.getConsumerConfig().getUrl());
	request.sendBuffer(payload.body, result -> {
		// Retry if it didn't work
		if (result.failed()) {
			this.logger.error(result.cause());
			this.processError(payload);
		} else {
			final HttpResponse<Buffer> response = result.result();
			// Check for return code
			if ((response.statusCode() >= 200) && (response.statusCode() < 300)) {
				// We are good
				this.logger.info("Successful post:" + payload.body.toString());
			} else {
				this.processError(payload);
			}
		}
	});
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:21,代码来源:RestConsumer.java

示例2: step2ResultHandshake

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private void step2ResultHandshake(final HttpResponse<Buffer> postReturn) {
	// Don't proceed in a shutdown scenario
	if (this.shuttingDown || this.shutdownCompleted) {
		this.shutdownCompleted = true;
		return;
	}

	// Handle cookies
	this.captureCookies(postReturn.cookies());

	// Handle the body
	final JsonObject handshakeResult = postReturn.bodyAsJsonArray().getJsonObject(0);
	// Check if it worked
	if (handshakeResult.getBoolean("successful", false)) {
		final String clientIdCandidate = handshakeResult.getString("clientId");
		if (clientIdCandidate == null) {
			this.logger.error("Handshake didn't provide clientId");
		} else {
			this.clientId = clientIdCandidate;
			this.step3ActionAdvice(handshakeResult);
		}
	} else {
		this.logger.error("Handshake was unsuccessful");
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:26,代码来源:CometD.java

示例3: step3ResultAdvice

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private void step3ResultAdvice(final HttpResponse<Buffer> postReturn) {
	if (this.shuttingDown || this.shutdownCompleted) {
		this.shutdownCompleted = true;
		return;
	}

	// Handle cookies
	this.captureCookies(postReturn.cookies());
	// Handle body
	final JsonObject advice = postReturn.bodyAsJsonArray().getJsonObject(0);
	if (advice.getBoolean("successful", false)) {
		// TODO Extract the advice, especially timeout
		this.step4ActionSubscribe();
	} else {
		this.logger.error("Advice negotiation failed (Step 3)");
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:18,代码来源:CometD.java

示例4: resultOfAuthentication

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private void resultOfAuthentication(final AsyncResult<HttpResponse<Buffer>> postReturn,
		final Future<AuthInfo> futureAuthinfo) {
	if (postReturn.succeeded()) {
		// Get session info
		final Buffer body = postReturn.result().body();
		final AuthInfo a = this.extractAuthInfoFromBody(body);
		if (a != null) {
			this.setCachedAuthInfo(a);
			futureAuthinfo.complete(a);
		} else {
			futureAuthinfo.fail("Authentication phase failed, please check log");
		}
	} else {
		futureAuthinfo.fail(postReturn.cause());
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:17,代码来源:SoapApi.java

示例5: testImplicitMode

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
public void testImplicitMode() {
    vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    HttpRequest<Buffer> request = client.postAbs("http://admin:[email protected]:8080/oauth/authorize?response_type=token&scope=read%20write&client_id=myClientId&redirect_uri=http://example.com");
    request.putHeader("Authorization", getHeader());
    request.send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            //String location = response.getHeader("Location");
            String body = response.bodyAsString();
            System.out.println("Implicit Mode Get Token" + body + " status code" + response.statusCode() + " Location=");
        } else {
            System.out.println("Something went wrong " + ar.cause().getMessage());
        }
    });
}
 
开发者ID:openmg,项目名称:metagraph-auth,代码行数:17,代码来源:VertxWebTest.java

示例6: retrieveServices

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private Future<JsonArray> retrieveServices(String token) {
  Future<JsonArray> future = Future.future();
  String path = "/api/v1/namespaces/" + namespace + "/services";
  client.get(path)
    .putHeader("Authorization", "Bearer " + token)
    .send(resp -> {
      if (resp.failed()) {
        future.fail(resp.cause());
      } else if (resp.result().statusCode() != 200) {
        future.fail("Unable to retrieve services from namespace " + namespace + ", status code: "
          + resp.result().statusCode() + ", content: " + resp.result().bodyAsString());
      } else {
        HttpResponse<Buffer> response = resp.result();
        JsonArray items = response.bodyAsJsonObject().getJsonArray("items");
        if (items == null) {
          future.fail("Unable to retrieve services from namespace " + namespace + " - no items");
        } else {
          future.complete(items);
          watch(client, token, response.bodyAsJsonObject().getJsonObject("metadata").getString("resourceVersion"));
        }
      }
    });
  return future;
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:25,代码来源:KubernetesServiceImporter.java

示例7: read

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
/**
 * Reads a secret from `path`.
 *
 * @param path            the path
 * @param responseHandler the callback invoked with the result
 */
public void read(String path, Handler<AsyncResult<Secret>> responseHandler) {
  Objects.requireNonNull(responseHandler);

  client.get("/v1/" + Objects.requireNonNull(path))
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "No token to access the vault"))
    .send(response -> {
      if (response.failed()) {
        responseHandler.handle(VaultException.toFailure("Unable to access the Vault", response.cause()));
        return;
      }

      HttpResponse<Buffer> result = response.result();
      if (result.statusCode() != 200) {
        responseHandler.handle(VaultException.toFailure(result.statusMessage(), result.statusCode(),
          result.bodyAsString()));
      } else {
        Secret secret = result.bodyAsJson(Secret.class);
        responseHandler.handle(Future.succeededFuture(secret));
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-config,代码行数:28,代码来源:SlimVaultClient.java

示例8: write

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
/**
 * Write a secret to `path`.
 *
 * @param path          the path
 * @param resultHandler the callback invoked with the result
 */
public void write(String path, JsonObject secrets, Handler<AsyncResult<Secret>> resultHandler) {
  Objects.requireNonNull(resultHandler);
  client.post("/v1/" + Objects.requireNonNull(path))
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
    .sendJsonObject(Objects.requireNonNull(secrets, "The secret must be set"),
      ar -> {
        if (ar.failed()) {
          resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
          return;
        }

        HttpResponse<Buffer> response = ar.result();
        if (response.statusCode() == 200 || response.statusCode() == 204) {
          resultHandler.handle(Future.succeededFuture(response.bodyAsJson(Secret.class)));
        } else {
          resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
            response.bodyAsString()));
        }
      });
}
 
开发者ID:vert-x3,项目名称:vertx-config,代码行数:27,代码来源:SlimVaultClient.java

示例9: delete

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
/**
 * Deletes a secret from `path`.
 *
 * @param path          the path
 * @param resultHandler the callback invoked with the result
 */
public void delete(String path, Handler<AsyncResult<Void>> resultHandler) {
  Objects.requireNonNull(resultHandler);
  client.delete("/v1/" + Objects.requireNonNull(path))
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
    .send(ar -> {
      if (ar.failed()) {
        resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
        return;
      }

      HttpResponse<Buffer> response = ar.result();
      if (response.statusCode() != 204) {
        resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
          response.bodyAsString()));
      } else {
        resultHandler.handle(Future.succeededFuture());
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-config,代码行数:26,代码来源:SlimVaultClient.java

示例10: renewSelf

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
/**
 * Renews the current token.
 *
 * @param leaseDurationInSecond the extension in second
 * @param resultHandler         the callback invoked with the result
 */
public void renewSelf(long leaseDurationInSecond, Handler<AsyncResult<Auth>> resultHandler) {
  JsonObject payload = null;
  if (leaseDurationInSecond > 0) {
    payload = new JsonObject().put("increment", leaseDurationInSecond);
  }
  HttpRequest<Buffer> request = client.post("/v1/auth/token/renew-self")
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must not be null"));

  Handler<AsyncResult<HttpResponse<Buffer>>> handler = ar -> {
    if (ar.failed()) {
      resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
      return;
    }
    manageAuthResult(resultHandler, ar.result());
  };

  if (payload != null) {
    request.sendJsonObject(payload, handler);
  } else {
    request.send(handler);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-config,代码行数:29,代码来源:SlimVaultClient.java

示例11: lookupSelf

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
/**
 * Looks up for the current token metadata.
 *
 * @param resultHandler the callback invoked with the result
 */
public void lookupSelf(Handler<AsyncResult<Lookup>> resultHandler) {
  client.get("/v1/auth/token/lookup-self")
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must not be null"))
    .send(ar -> {
      if (ar.failed()) {
        resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
        return;
      }
      HttpResponse<Buffer> response = ar.result();
      if (response.statusCode() != 200) {
        resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
          response.bodyAsString()));
      } else {
        JsonObject object = response.bodyAsJsonObject();
        Lookup lookup = object.getJsonObject("data").mapTo(Lookup.class);
        resultHandler.handle(Future.succeededFuture(lookup));
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-config,代码行数:25,代码来源:SlimVaultClient.java

示例12: getValueForCompany

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
private Future<Double> getValueForCompany(WebClient client, String company, int numberOfShares) {
  // Create the future object that will  get the value once the value have been retrieved
  Future<Double> future = Future.future();

  //----
  client.get("/?name=" + encode(company))
      .as(BodyCodec.jsonObject())
      .send(ar -> {
    if (ar.succeeded()) {
      HttpResponse<JsonObject> response = ar.result();
      if (response.statusCode() == 200) {
        double v = numberOfShares * response.body().getDouble("bid");
        future.complete(v);
      } else {
        future.complete(0.0);
      }
    } else {
      future.fail(ar.cause());
    }
  });
  // ---

  return future;
}
 
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:25,代码来源:PortfolioServiceImpl.java

示例13: receiveResponseAsJsonObject

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
public void receiveResponseAsJsonObject(WebClient client) {
  client
    .get(8080, "myserver.mycompany.com", "/some-uri")
    .as(BodyCodec.jsonObject())
    .send(ar -> {
      if (ar.succeeded()) {
        HttpResponse<JsonObject> response = ar.result();

        JsonObject body = response.body();

        System.out.println("Received response with status code" + response.statusCode() + " with body " + body);
      } else {
        System.out.println("Something went wrong " + ar.cause().getMessage());
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:17,代码来源:WebClientExamples.java

示例14: receiveResponseAsJsonPOJO

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
public void receiveResponseAsJsonPOJO(WebClient client) {
  client
    .get(8080, "myserver.mycompany.com", "/some-uri")
    .as(BodyCodec.json(User.class))
    .send(ar -> {
      if (ar.succeeded()) {
        HttpResponse<User> response = ar.result();

        User user = response.body();

        System.out.println("Received response with status code" + response.statusCode() + " with body " +
          user.getFirstName() + " " + user.getLastName());
      } else {
        System.out.println("Something went wrong " + ar.cause().getMessage());
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:WebClientExamples.java

示例15: receiveResponseAsBufferDecodeAsJsonObject

import io.vertx.ext.web.client.HttpResponse; //导入依赖的package包/类
public void receiveResponseAsBufferDecodeAsJsonObject(WebClient client) {
  client
    .get(8080, "myserver.mycompany.com", "/some-uri")
    .send(ar -> {
      if (ar.succeeded()) {

        HttpResponse<Buffer> response = ar.result();

        // Decode the body as a json object
        JsonObject body = response.bodyAsJsonObject();

        System.out.println("Received response with status code" + response.statusCode() + " with body " + body);
      } else {
        System.out.println("Something went wrong " + ar.cause().getMessage());
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:WebClientExamples.java


注:本文中的io.vertx.ext.web.client.HttpResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。