Response method in java
Java SE Messaging API Reference for Oracle Internet of Things Cloud Service Client Software Library. Release 21.1.1.0.0-3 E70331-25
Interface Response
public interface Response
A Response instance is used to retrieve the result of a request on a Resource . Requests on these resources are asynchronous, so, before accessing the result code or data, it is necessary to check that the request is terminated by calling isDone() . Example of use:
Response resp = resource.get(. ); while (!resp.isDone()) < Thread.sleep(xxx); resp.poll(); >byte[] data = resp.getBody(); .
Method Summary
Method Detail
getStatusCode
getRequestId
java.lang.String getRequestId()
getPath
getBody
byte[] getBody() throws java.lang.IllegalStateException
getHeaders
java.util.Map getHeaders() throws java.lang.IllegalStateException
isDone
Call isDone to determine if the response is complete. Resource requests to the cloud service can be asynchronous. Before obtaining the body isDone must be called and return true before calling getBody , getBodyString or getHeaders . If isDone() returns false the application must call poll() to try to update the response.
poll
void poll() throws java.io.IOException, java.security.GeneralSecurityException
This method is used to look for an available response. It should typically be called when isDone() has returned false .
Java SE Messaging API Reference for Oracle Internet of Things Cloud Service Client Software Library. Release 21.1.1.0.0-3 E70331-25
Copyright © 2015, 2017, Oracle. All rights reserved.
Response method in java
An HTTP response. An HttpResponse is not created directly, but rather returned as a result of sending an HttpRequest . An HttpResponse is made available when the response status code and headers have been received, and typically after the response body has also been completely received. Whether or not the HttpResponse is made available before the response body has been completely received depends on the BodyHandler provided when sending the HttpRequest . This class provides methods for accessing the response status code, headers, the response body, and the HttpRequest corresponding to this response. The following is an example of retrieving a response as a String:
HttpResponse response = client .send(request, BodyHandlers.ofString());
The class BodyHandlers provides implementations of many common response handlers. Alternatively, a custom BodyHandler implementation can be used.
Nested Class Summary
Implementations of BodyHandler that implement various useful handlers, such as handling the response body as a String, or streaming the response body to a file.
Implementations of BodySubscriber that implement various useful subscribers, such as converting the response body bytes into a String, or streaming the bytes to a file.
Initial response information supplied to a BodyHandler when a response is initially received and before the body is processed.
Method Summary
Method Detail
statusCode
request
Returns the HttpRequest corresponding to this response. The returned HttpRequest may not be the initiating request provided when sending. For example, if the initiating request was redirected, then the request returned by this method will have the redirected URI, which will be different from the initiating request URI.
previousResponse
OptionalHttpResponseT>> previousResponse()
Returns an Optional containing the previous intermediate response if one was received. An intermediate response is one that is received as a result of redirection or authentication. If no previous response was received then an empty Optional is returned.
headers
body
Returns the body. Depending on the type of T , the returned body may represent the body after it was read (such as byte[] , or String , or Path ) or it may represent an object with which the body is read, such as an InputStream . If this HttpResponse was returned from an invocation of previousResponse() then this method returns null
sslSession
Returns an Optional containing the SSLSession in effect for this response. Returns an empty Optional if this is not a HTTPS response.
uri
Returns the URI that the response was received from. This may be different from the request URI if redirection occurred.
version
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.