本文整理了Java中io.micronaut.http.HttpResponse.getStatus()
方法的一些代码示例,展示了HttpResponse.getStatus()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getStatus()
方法的具体详情如下:
包路径:io.micronaut.http.HttpResponse
类名称:HttpResponse
方法名:getStatus
暂无
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* @return The HTTP status
*/
default HttpStatus status() {
return getStatus();
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* @return The response status code
*/
default int code() {
return getStatus().getCode();
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* @return The {@link io.micronaut.http.HttpStatus} returned
*/
public HttpStatus getStatus() {
return getResponse().getStatus();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpStatus getStatus() {
return getDelegate().getStatus();
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* @return The HTTP status reason phrase
*/
default String reason() {
return getStatus().getReason();
}
代码示例来源:origin: micronaut-projects/micronaut-core
private Class<?> getErrorType(HttpResponse<?> response) {
Optional<MediaType> contentType = response.getContentType();
Class<?> errorType = null;
if (contentType.isPresent() && response.getStatus().getCode() > 399) {
MediaType mediaType = contentType.get();
errorType = errorDecoder.getErrorType(mediaType);
}
return errorType;
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Perform an HTTP request for the given request object emitting the full HTTP response from returned
* {@link org.reactivestreams.Publisher} and converting the response body to the specified type.
*
* @param request The {@link HttpRequest} to execute
* @param bodyType The body type
* @param errorType The error type
* @param <I> The request body type
* @param <O> The response body type
* @param <E> The error type
* @return A result of the given type or null the URI returns a 404
* @throws HttpClientResponseException if an error status is returned
*/
@SuppressWarnings("unchecked")
default <I, O, E> O retrieve(HttpRequest<I> request, Argument<O> bodyType, Argument<E> errorType) {
HttpResponse<O> response = exchange(request, bodyType, errorType);
if (HttpStatus.class.isAssignableFrom(bodyType.getType())) {
return (O) response.getStatus();
} else {
return response
.getBody()
.orElseThrow(() -> new HttpClientResponseException(
"Empty body",
response
));
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Perform an HTTP request for the given request object emitting the full HTTP response from returned
* {@link Publisher} and converting the response body to the specified type.
*
* @param request The {@link HttpRequest} to execute
* @param bodyType The body type
* @param errorType The error type
* @param <I> The request body type
* @param <O> The response body type
* @param <E> The error type
* @return A {@link Publisher} that emits a result of the given type
*/
default <I, O, E> Publisher<O> retrieve(HttpRequest<I> request, Argument<O> bodyType, Argument<E> errorType) {
return Publishers.map(exchange(request, bodyType, errorType), response -> {
if (bodyType.getType() == HttpStatus.class) {
return (O) response.getStatus();
} else {
Optional<O> body = response.getBody();
return body
.orElseThrow(() -> new HttpClientResponseException(
"Empty body",
response
));
}
});
}
代码示例来源:origin: micronaut-projects/micronaut-core
}).map(response -> Collections.singletonMap(originalURI, response.getStatus()));
}).subscribe(uriToStatusMap -> {
Map.Entry<URI, HttpStatus> entry = uriToStatusMap.entrySet().iterator().next();
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testGetPojoList() {
ApplicationContext applicationContext = ApplicationContext.run();
EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();
HttpClient client = applicationContext.createBean(HttpClient.class, server.getURL());
Flowable<HttpResponse<List>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/get/pojoList"), Argument.of(List.class, HttpGetSpec.Book.class)
));
HttpResponse<List> response = flowable.blockingFirst();
assertEquals(response.getStatus(), HttpStatus.OK);
Optional<List> body = response.getBody();
assertTrue(body.isPresent());
List<HttpGetSpec.Book> list = body.get();
assertEquals(list.size(), 1);
assertTrue(list.get(0) instanceof HttpGetSpec.Book);
client.stop();
applicationContext.stop();
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testSimpleGet() {
ApplicationContext applicationContext = ApplicationContext.run();
EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();
HttpClient client = new DefaultHttpClient(server.getURL());
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/get/simple"), String.class
));
HttpResponse<String> response = flowable.blockingFirst();
Assert.assertEquals(response.getStatus(), HttpStatus.OK);
Optional<String> body = response.getBody(String.class);
assertTrue(body.isPresent());
assertEquals(body.get(), "success");
client.stop();
applicationContext.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostWithURITemplate() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::posturitemplate[]
Flowable<HttpResponse<Book>> call = client.exchange(
POST("/amazon/book/{title}", new Book("The Stand")),
Book.class
);
// end::posturitemplate[]
HttpResponse<Book> response = call.blockingFirst();
Optional<Book> message = response.getBody(Book.class); // <2>
// check the status
assertEquals(
HttpStatus.CREATED,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"The Stand",
message.get().getTitle()
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testRetrieveWithPOJOResponse() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::pojoresponse[]
Flowable<HttpResponse<Message>> call = client.exchange(
GET("/greet/John"), Message.class // <1>
);
HttpResponse<Message> response = call.blockingFirst();
Optional<Message> message = response.getBody(Message.class); // <2>
// check the status
assertEquals(
HttpStatus.OK,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"Hello John",
message.get().getText()
);
// end::pojoresponse[]
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
response.getStatus() // <3>
);
代码示例来源:origin: micronaut-projects/micronaut-core
@Test
public void testPostRequestWithString() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());
// tag::poststring[]
Flowable<HttpResponse<String>> call = client.exchange(
POST("/hello", "Hello John") // <1>
.contentType(MediaType.TEXT_PLAIN_TYPE)
.accept(MediaType.TEXT_PLAIN_TYPE), // <2>
String.class // <3>
);
// end::poststring[]
HttpResponse<String> response = call.blockingFirst();
Optional<String> message = response.getBody(String.class); // <2>
// check the status
assertEquals(
HttpStatus.CREATED,
response.getStatus() // <3>
);
// check the body
assertTrue(message.isPresent());
assertEquals(
"Hello John",
message.get()
);
embeddedServer.stop();
client.stop();
}
代码示例来源:origin: micronaut-projects/micronaut-core
response.getStatus() // <3>
);
代码示例来源:origin: io.micronaut/http-client
/**
* @return The {@link io.micronaut.http.HttpStatus} returned
*/
public HttpStatus getStatus() {
return getResponse().getStatus();
}
代码示例来源:origin: io.micronaut/micronaut-http
/**
* @return The response status code
*/
default int code() {
return getStatus().getCode();
}
代码示例来源:origin: io.micronaut/micronaut-http-client
/**
* @return The {@link io.micronaut.http.HttpStatus} returned
*/
public HttpStatus getStatus() {
return getResponse().getStatus();
}
代码示例来源:origin: io.micronaut/http-client
private Class<?> getErrorType(HttpResponse<?> response) {
Optional<MediaType> contentType = response.getContentType();
Class<?> errorType = null;
if (contentType.isPresent() && response.getStatus().getCode() > 399) {
MediaType mediaType = contentType.get();
errorType = errorDecoder.getErrorType(mediaType);
}
return errorType;
}
}
内容来源于网络,如有侵权,请联系作者删除!