本文整理汇总了Java中org.jclouds.http.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于org.jclouds.http包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldRetryRequest
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public boolean shouldRetryRequest(final HttpCommand command, final HttpResponse response) {
command.incrementFailureCount();
byte[] data = closeClientButKeepContentStream(response);
String message = data != null ? new String(data) : null;
// Do not retry client errors that are not retryable errors
if (response.getStatusCode() != 400 &&
(!message.contains("RESOURCE_BUSY") || !message.contains("UNEXPECTED_ERROR"))) {
return false;
} else if (!command.isReplayable()) {
logger.error("Cannot retry after server error, command is not replayable: %1$s", command);
return false;
} else if (command.getFailureCount() > retryCountLimit) {
logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit,
command);
return false;
} else {
imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString());
return true;
}
}
示例2: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public void apply(String virtualMachineId) {
// try to workaround jcloud issue
// https://issues.apache.org/jira/browse/JCLOUDS-1155
try {
jcloudsDeleteVirtualMachineStrategy.apply(virtualMachineId);
} catch (org.jclouds.http.HttpResponseException e) {
final HttpResponse response = e.getResponse();
if (response.getStatusCode() == 400) {
if (e.getContent().contains("Security Group") && e.getContent()
.contains("in use")) {
//silently error error
return;
}
}
throw e;
}
}
示例3: generatePutTempURL
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
private void generatePutTempURL() throws IOException {
System.out.format("Generate PUT Temp URL%n");
// Create the Payload
String data = "This object will be public for 10 minutes.";
ByteSource source = ByteSource.wrap(data.getBytes());
Payload payload = Payloads.newByteSourcePayload(source);
// Create the Blob
Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);
System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());
// PUT the file using jclouds
HttpResponse response = blobStoreContext.utils().http().invoke(request);
int statusCode = response.getStatusCode();
if (statusCode >= 200 && statusCode < 299) {
System.out.format(" PUT Success (%s)%n", statusCode);
}
else {
throw new HttpResponseException(null, response);
}
}
示例4: generateDeleteTempURL
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
private void generateDeleteTempURL() throws IOException {
System.out.format("Generate DELETE Temp URL%n");
HttpRequest request = blobStoreContext.getSigner(REGION).signRemoveBlob(CONTAINER, FILENAME);
System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());
// DELETE the file using jclouds
HttpResponse response = blobStoreContext.utils().http().invoke(request);
int statusCode = response.getStatusCode();
if (statusCode >= 200 && statusCode < 299) {
System.out.format(" DELETE Success (%s)%n", statusCode);
}
else {
throw new HttpResponseException(null, response);
}
}
示例5: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public MutableBlobProperties apply(HttpResponse response) {
StringWriter writer = new StringWriter();
MutableBlobProperties properties = null;
try {
IOUtils.copy(response.getPayload().getInput(), writer);
String theString = writer.toString();
properties = mapper.readValue(theString, MutableBlobProperties.class);
} catch (IOException e) {
System.out.println(response.getMessage());
e.printStackTrace();
}
return properties;
}
示例6: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public Blob apply(HttpResponse response) {
final StringWriter writer = new StringWriter();
MutableBlobProperties properties = null;
try {
IOUtils.copy(response.getPayload().getInput(), writer);
final String theString = writer.toString();
properties = this.mapper.readValue(theString, MutableBlobProperties.class);
final OrionBlob orionBlob = this.orionBlobProvider.create(properties);
if (properties.getType() == BlobType.FILE_BLOB) {
final HttpResponse payloadRes = this.api.getBlobContents(getOrionUtils().getUserWorkspace(), properties.getContainer(),
properties.getParentPath(), properties.getName());
orionBlob.setPayload(payloadRes.getPayload());
}
return this.orionBlob2Blob.apply(orionBlob);
} catch (final IOException e) {
System.out.println(response.getMessage());
e.printStackTrace();
}
return null;
}
示例7: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@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());
}
}
示例8: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public RawContent apply(final HttpResponse input) {
try (final InputStream inputStream = input.getPayload().openStream()) {
final String value = Strings2.toStringAndClose(inputStream);
return RawContent.create(value, null);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例9: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public RequestStatus apply(final HttpResponse input) {
final int statusCode = input.getStatusCode();
if (statusCode >= 200 && statusCode < 400) {
if (statusCode == 204) {
throw new ResourceNotFoundException("The repository does not exist in this project.");
} else {
return RequestStatus.create(true, null);
}
} else {
throw new RuntimeException(input.getStatusLine());
}
}
示例10: parseMessage
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
private String parseMessage(final HttpCommand command, final HttpResponse response) {
if (response.getPayload() != null) {
try {
return Strings2.toStringAndClose(response.getPayload().openStream());
} catch (IOException e) {
throw Throwables.propagate(e);
}
} else {
return new StringBuffer(command.getCurrentRequest().getRequestLine())
.append(" -> ")
.append(response.getStatusLine())
.toString();
}
}
示例11: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public Boolean apply(HttpResponse response) {
if (String.valueOf(response.getStatusCode()).startsWith("2")) {
return true;
}
return false;
}
示例12: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public PageSet<? extends StorageMetadata> apply(HttpResponse res) {
final List<OrionStorageMetadata> storageDataList = Lists.transform(this.folderListParser.apply(res),
this.childMetadataToStorageMetadata);
return new OrionPageSet(storageDataList);
}
示例13: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public Boolean apply(HttpResponse response) {
if ((response.getStatusCode() == 200) || (response.getStatusCode() == 201)) {
return true;
} else {
return false;
}
}
示例14: apply
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
@Override
public Boolean apply(HttpResponse res) {
if (res.getStatusLine().startsWith("4")) {
return false;
} else if (res.getStatusLine().startsWith("2")) {
JsonObject responseObject = (JsonObject) (new JsonParser()).parse(res.getMessage());
if (responseObject.get("Directory").getAsBoolean()) {
return true;
}
}
return false;
}
示例15: OrionResponseException
import org.jclouds.http.HttpResponse; //导入依赖的package包/类
/**
* @param command
* @param response
*/
public OrionResponseException(HttpCommand command, HttpResponse response, OrionError error) {
super(command, response);
orionError = error;
}