本文整理了Java中org.jclouds.http.HttpResponse
类的一些代码示例,展示了HttpResponse
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse
类的具体详情如下:
包路径:org.jclouds.http.HttpResponse
类名称:HttpResponse
[英]Represents a response produced from HttpCommandExecutorService
[中]表示从HttpCommandExecutorService生成的响应
代码示例来源:origin: org.apache.jclouds.labs/azurecompute-arm
public URI apply(final HttpResponse from) {
if (from.getStatusCode() == 202 && from.getHeaders().containsKey("Location")){
String uri = from.getFirstHeaderOrNull("Location");
return URI.create(uri);
} else if (from.getStatusCode() == 200 || from.getStatusCode() == 204){
return null;
}
throw new IllegalStateException("did not receive expected response code and header in: " + from);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
public Blob apply(HttpResponse from) {
checkNotNull(from, "request");
MutableBlobMetadata metadata = metadataParser.apply(from);
Blob blob = blobFactory.create(metadata);
blob.getAllHeaders().putAll(from.getHeaders());
blob.setPayload(from.getPayload());
return blob;
}
代码示例来源:origin: jclouds/legacy-jclouds
public HttpResponseException(HttpCommand command, HttpResponse response, String content, Throwable cause) {
this(String.format("command: %1$s failed with response: %2$s; content: [%3$s]", command.getCurrentRequest()
.getRequestLine(), response.getStatusLine(), content), command, response, content, cause);
}
代码示例来源:origin: stackoverflow.com
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import java.io.IOException;
import java.io.InputStream;
public class Network {
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
public void getRequest(String reqUrl) throws IOException {
GenericUrl url = new GenericUrl(reqUrl);
HttpRequest request = HTTP_TRANSPORT.createRequestFactory().buildGetRequest(url);
HttpResponse response = request.execute();
System.out.println(response.getStatusCode());
InputStream is = response.getContent();
int ch;
while ((ch = is.read()) != -1) {
System.out.print((char) ch);
}
response.disconnect();
}
}
代码示例来源:origin: cdancy/jenkins-rest
@Override
public RequestStatus apply(final HttpResponse input) {
final int statusCode = input.getStatusCode();
if (statusCode >= 200 && statusCode < 400) {
return RequestStatus.create(true, null);
} else {
throw new RuntimeException(input.getStatusLine());
}
}
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception {
HttpRequest delete = HttpRequest.builder().method("DELETE").endpoint(
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups/160"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build();
NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete,
deleteResponse);
assertTrue(apiWhenServersExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
.delete("160"));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testApply() {
HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
.payload(getClass().getResourceAsStream("/orglist.xml"))
.addHeader("x-vcloud-authorization", "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/").build();
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
TerremarkVCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public HttpResponse apply(HttpRequest input) {
// on first request, throw an SSL close_notify exception
if (counter.getAndIncrement() == 0)
throw propagate(new SSLException("Received close_notify during handshake"));
// on other requests, just validate and return 200
assertEquals(renderRequest(input), renderRequest(HttpRequest.builder().method("HEAD").endpoint(
URI.create("http://mock/objects/rabbit")).build()));
return HttpResponse.builder().statusCode(200).build();
}
});
代码示例来源:origin: jclouds/legacy-jclouds
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testUpdateQuotasFailsNotFound() throws Exception {
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-class-sets/jcloudstestquotas");
QuotaClassApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
HttpRequest.builder().endpoint(endpoint).method("PUT")
.addHeader("X-Auth-Token", authToken)
.payload(payloadFromResourceWithContentType("/quota_class.json", MediaType.APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(404).build()).getQuotaClassExtensionForZone("az-1.region-a.geo-1").get();
api.update("jcloudstestquotas", getTestQuotas());
}
代码示例来源:origin: jclouds/legacy-jclouds
/**
* parses the http response headers to provide the CDN URI string.
*/
public URI apply(final HttpResponse from) {
String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI),
CloudFilesHeaders.CDN_URI);
return URI.create(cdnUri);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testResponsePathPortLocationOk() {
ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x();
HttpResponse response = createMock(HttpResponse.class);
Payload payload = createMock(Payload.class);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://new:8080/fd").build();
function.setContext(request);
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(CONTENT_TYPE)).andReturn("text/plain");
expect(response.getFirstHeaderOrNull(LOCATION)).andReturn("path");
expect(response.getPayload()).andReturn(payload).atLeastOnce();
payload.release();
replay(payload);
replay(response);
assertEquals(function.apply(response), URI.create("http://new:8080/path"));
verify(response);
verify(payload);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testGetSecurityGroupWhenResponseIs404() throws Exception {
HttpRequest getSecurityGroup = HttpRequest.builder().method("GET").endpoint(
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups/0")).headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
authToken).build()).build();
HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(404).build();
NovaApi apiWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
getSecurityGroupResponse);
assertNull(apiWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
.get("0"));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testListClustersEmptyOn404() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
GlobalHostClient client = requestSendsResponse(request, response);
assertEquals(client.listClusters(), ImmutableSet.of());
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(invocationCount = 5, timeOut = 5000)
public void testGetStringViaRequest() throws IOException {
HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET")
.endpoint(format("http://localhost:%d/objects/", testPort)).build());
assertEquals(Strings2.toString(getStringResponse.getPayload()).trim(), XML);
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testMaximumRetriesExceeded() throws InterruptedException, ExecutionException {
beginToFailOnRequestNumber = 0;
endFailuresOnRequestNumber = 6;
requestCount = 0;
try {
submitGetRequest();
fail("Request should not succeed within " + endFailuresOnRequestNumber + " requests");
} catch (HttpResponseException e) {
assertEquals(e.getResponse().getStatusCode(), 500);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testDeleteContainerMetadataWhenResponseIs404ReturnsFalse() {
HttpRequest deleteContainerMetadataRequest = HttpRequest.builder()
.method("POST")
.endpoint(swiftEndpointWithHostReplaced + "/foo")
.addHeader(SwiftHeaders.CONTAINER_DELETE_METADATA_PREFIX + "bar", "")
.addHeader("X-Auth-Token", authToken).build();
HttpResponse deleteContainerMetadataResponse = HttpResponse.builder().statusCode(404).build();
SwiftClient clientDeleteContainerMetadata = requestsSendResponses(authRequest,
authResponse, deleteContainerMetadataRequest, deleteContainerMetadataResponse);
assertFalse(clientDeleteContainerMetadata.deleteContainerMetadata("foo", ImmutableList.<String> of("bar")));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(groups = { "integration", "live" })
public void deleteObjectNoContainer() {
try {
view.getBlobStore().removeBlob("donb", "test");
} catch (HttpResponseException e) {
assertEquals(e.getResponse().getStatusCode(), 404);
} catch (ContainerNotFoundException e) {
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void test400MakesIllegalStateExceptionOnQuotaExceededOnNoFixedIps() {
fn.handleError(command, noFixedIps);
assertEquals(command.getException().getClass(), IllegalStateException.class);
assertEquals(command.getException().getMessage(), noFixedIps.getPayload().getRawContent());
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testCheckTokenIsValidFailNotValid() {
TokenApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
HttpRequest.builder().method("HEAD")
.endpoint(endpoint + "/v2.0/tokens/sometokenorother")
.addHeader("X-Auth-Token", authToken).build(),
HttpResponse.builder().statusCode(404).build()).getTokenApi().get();
assertFalse(api.isValid("sometokenorother"));
}
代码示例来源:origin: jclouds/legacy-jclouds
/**
* clones or proxies can mess up the error message.
*/
@Test
public void testNoExceptionParsingTextPlain() {
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).payload("foo bar").build();
response.getPayload().getContentMetadata().setContentType(TEXT_PLAIN);
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
}
内容来源于网络,如有侵权,请联系作者删除!