当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseException类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:26,代码来源:CloudStoreSeedNodeProvider.java

示例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());
            }
        }
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:23,代码来源:CloudStoreSeedNodeProvider.java

示例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);
   }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:26,代码来源:GenerateTempURL.java

示例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);
   }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:19,代码来源:GenerateTempURL.java

示例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;
        }
    }
}
 
开发者ID:bouncestorage,项目名称:swiftproxy,代码行数:13,代码来源:ObjectResource.java

示例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;
			
}
 
开发者ID:jasonrig,项目名称:openstack-queue,代码行数:54,代码来源:OSConnection.java

示例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;
}
 
开发者ID:bouncestorage,项目名称:bouncestorage,代码行数:36,代码来源:WriteBackPolicy.java

示例8: toResponse

import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
@Override
public Response toResponse(HttpResponseException exception) {
    return Response.status(exception.getResponse().getStatusCode())
            .build();
}
 
开发者ID:bouncestorage,项目名称:swiftproxy,代码行数:6,代码来源:HttpResponseExceptionMapper.java

示例9: isMappable

import org.jclouds.http.HttpResponseException; //导入依赖的package包/类
@Override
public boolean isMappable(HttpResponseException exception) {
    return exception.getResponse() != null;
}
 
开发者ID:bouncestorage,项目名称:swiftproxy,代码行数:5,代码来源:HttpResponseExceptionMapper.java


注:本文中的org.jclouds.http.HttpResponseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。