本文整理汇总了Java中org.jclouds.http.HttpResponseException类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseException类的具体用法?Java HttpResponseException怎么用?Java HttpResponseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseException类属于org.jclouds.http包,在下文中一共展示了HttpResponseException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerAddress
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
private void registerAddress(String cluster, InetSocketAddress address) throws HekateException {
try (BlobStoreContext ctx = createContext()) {
BlobStore store = ctx.getBlobStore();
String file = cluster + '/' + AddressUtils.toFileName(address);
try {
if (!store.blobExists(container, file)) {
Blob blob = store.blobBuilder(file)
.type(StorageType.BLOB)
.payload(new byte[]{1})
.build();
store.putBlob(container, blob);
if (log.isInfoEnabled()) {
log.info("Registered address to the cloud store [container={}, file={}]", container, file);
}
}
} catch (ResourceNotFoundException | HttpResponseException e) {
throw new HekateException("Failed to register the seed node address to the cloud store "
+ "[container=" + container + ", file=" + file + ']', e);
}
}
}
示例2: unregisterAddress
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
private void unregisterAddress(String cluster, InetSocketAddress address) {
try (BlobStoreContext ctx = createContext()) {
BlobStore store = ctx.getBlobStore();
String file = cluster + '/' + AddressUtils.toFileName(address);
try {
if (store.blobExists(container, file)) {
store.removeBlob(container, file);
if (log.isInfoEnabled()) {
log.info("Unregistered address from the cloud store [container={}, file={}]", container, file);
}
}
} catch (ResourceNotFoundException | HttpResponseException e) {
if (log.isWarnEnabled()) {
log.warn("Failed to unregister the seed node address from the cloud store "
+ "[container={}, file={}, cause={}]", container, file, e.toString());
}
}
}
}
示例3: generatePutTempURL
import org.jclouds.http.HttpResponseException; //导入依赖的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.HttpResponseException; //导入依赖的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: serverCopyBlob
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
private String serverCopyBlob(BlobStore blobStore, String container, String objectName, String destContainer,
String destObject, CopyOptions options) {
try {
return blobStore.copyBlob(container, objectName, destContainer, destObject, options);
} catch (RuntimeException e) {
if (e.getCause() instanceof HttpResponseException) {
throw (HttpResponseException) e.getCause();
} else {
throw e;
}
}
}
示例6: createServer
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
/**
* Creates a VM instance. The VM created using this instance is not
* guaranteed to have been created successfully. It is up to the programmer
* to subsequently check that the VM started correctly.
*
* @see #checkServerStatus(Server)
* @param name Server name
* @param imageId image identifier to use for the new VM
* @param flavor machine flavour
* @param availabilityZone availablity zone in which to create the server
* @param securityGroups security groups to apply to the new server
* @param keyPair key pair to inject
* @param retryCount number of times to attempt to create this server if an error is encountered
* @param serverOptions additional server options
* @return a Server object representing the VM being created
*/
public Server createServer(String name, String imageId, Flavor flavor, String availabilityZone, String[] securityGroups, KeyPair keyPair, int retryCount, CreateServerOptions...serverOptions) {
logger.debug("Attempting to create server \""+name+"\" in availability zone \""+availabilityZone+"\"...");
CreateServerOptions[] options = new CreateServerOptions[serverOptions.length + 1];
options[0] = CreateServerOptions.Builder
.availabilityZone(availabilityZone)
.securityGroupNames(securityGroups)
.keyPairName(keyPair.getName());
for (int i = 0; i < serverOptions.length; i++) {
options[i+1] = serverOptions[i];
}
ServerCreated serverCreated = null;
try {
serverCreated = getServerApi().create(name, imageId, flavor.getId(), options);
} catch (HttpResponseException e) {
logger.warn("Nova returned something unexpected while creating the VM!");
logger.warn("Nova said: "+e.getMessage());
if (retryCount > 0) {
logger.warn("Will retry in 5 seconds.");
try {
Thread.sleep(5000); // 5 second sleep
} catch (InterruptedException e1) {
e1.printStackTrace();
}
return createServer(name, imageId, flavor, availabilityZone, securityGroups, keyPair, (retryCount - 1), serverOptions);
} else {
logger.warn("Giving up.");
return null;
}
}
return (serverCreated != null)?getServerApi().get(serverCreated.getId()):null;
}
示例7: maybeConditionalGet
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
private GetOptions maybeConditionalGet(String container, String blobName, GetOptions options) {
if (options.getIfMatch() != null || options.getIfNoneMatch() != null ||
options.getIfModifiedSince() != null || options.getIfUnmodifiedSince() != null) {
BlobMetadata meta = blobMetadata(container, blobName);
HttpResponseException ex = null;
if (options.getIfMatch() != null && !eTagsEqual(options.getIfMatch(), meta.getETag())) {
throw new ClientErrorException(Response.Status.PRECONDITION_FAILED);
}
if (options.getIfNoneMatch() != null && eTagsEqual(options.getIfNoneMatch(), meta.getETag())) {
throw new WebApplicationException(Response.Status.NOT_MODIFIED);
}
if (options.getIfModifiedSince() != null &&
meta.getLastModified().compareTo(options.getIfModifiedSince()) <= 0) {
throw new WebApplicationException(Response.Status.NOT_MODIFIED);
}
if (options.getIfUnmodifiedSince() != null &&
meta.getLastModified().compareTo(options.getIfUnmodifiedSince()) > 0) {
throw new ClientErrorException(Response.Status.PRECONDITION_FAILED);
}
return new GetOptions() {
@Override
public List<String> getRanges() {
return options.getRanges();
}
};
}
return options;
}
示例8: toResponse
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
@Override
public Response toResponse(HttpResponseException exception) {
return Response.status(exception.getResponse().getStatusCode())
.build();
}
示例9: isMappable
import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
@Override
public boolean isMappable(HttpResponseException exception) {
return exception.getResponse() != null;
}