protected CloneVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof CloneVAppOptions) { return (CloneVAppOptions) arg; } else if (arg instanceof CloneVAppOptions[]) { CloneVAppOptions[] options = (CloneVAppOptions[]) arg; return (options.length > 0) ? options[0] : null; } } return null; }
protected CaptureVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof CaptureVAppOptions) { return (CaptureVAppOptions) arg; } else if (arg instanceof CaptureVAppOptions[]) { CaptureVAppOptions[] options = (CaptureVAppOptions[]) arg; return (options.length > 0) ? options[0] : null; } } return null; }
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof InstantiateVAppTemplateOptions) { return (InstantiateVAppTemplateOptions) arg; } else if (arg instanceof InstantiateVAppTemplateOptions[]) { InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg; return (options.length > 0) ? options[0] : null; } } return null; }
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof InstantiateVAppTemplateOptions) { return (InstantiateVAppTemplateOptions) arg; } else if (arg instanceof InstantiateVAppTemplateOptions[]) { InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg; return (options.length > 0) ? options[0] : null; } } return null; }
public static String findAvailabilityZoneInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof String) { String zone = (String) arg; if (AvailabilityZone.zones.contains(zone)) return zone; } } return null; }
public static String findRegionInArgsOrNull(GeneratedHttpRequest<?> gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof String) { String regionName = (String) arg; if (isRegion(regionName)) return regionName; } } return null; }
public static String findRegionInArgsOrNull(GeneratedHttpRequest gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof String) { String regionName = (String) arg; // TODO regions may not be amazon regions! // take from a configured value if (isRegion(regionName)) return regionName; } } return null; } }
@VisibleForTesting void appendBucketName(HttpRequest req, StringBuilder toSign) { checkArgument(req instanceof GeneratedHttpRequest<?>, "this should be a generated http request"); GeneratedHttpRequest<?> request = GeneratedHttpRequest.class.cast(req); String bucketName = null; for (int i = 0; i < request.getJavaMethod().getParameterAnnotations().length; i++) { if (Iterables.any(Arrays.asList(request.getJavaMethod().getParameterAnnotations()[i]), new Predicate<Annotation>() { public boolean apply(Annotation input) { return input.annotationType().equals(Bucket.class); } })) { bucketName = (String) request.getArgs()[i]; break; } } if (bucketName != null) toSign.append(servicePath).append(bucketName); }
@SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Map<String, String> postParams) { checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, "this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); String templateName = checkNotNull(postParams.remove("templateName"), "templateName"); String vApp = checkNotNull(postParams.remove("vApp"), "vApp"); CaptureVAppOptions options = findOptionsInArgsOrNull(gRequest); if (options == null) { options = new CaptureVAppOptions(); } try { stringBinder.bindToRequest(request, generateXml(templateName, vApp, options)); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (FactoryConfigurationError e) { throw new RuntimeException(e); } catch (TransformerException e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Map<String, String> postParams) { checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, "this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); String newName = checkNotNull(postParams.remove("newName"), "newName"); String vApp = checkNotNull(postParams.remove("vApp"), "vApp"); CloneVAppOptions options = findOptionsInArgsOrNull(gRequest); if (options == null) { options = new CloneVAppOptions(); } try { stringBinder.bindToRequest(request, generateXml(newName, vApp, options)); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (FactoryConfigurationError e) { throw new RuntimeException(e); } catch (TransformerException e) { throw new RuntimeException(e); } }
public ContainerMetadata apply(HttpResponse from) { ContainerMetadata to = new ContainerMetadata(); to.setName(request.getArgs().get(0).toString()); to.setReadACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ)); to.setBytes(new Long(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_BYTES_USED))); to.setCount(new Long(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_OBJECT_COUNT))); addUserMetadataTo(from, to); return to; }
"this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); String name = checkNotNull(postParams.remove("name"), "name"); String template = checkNotNull(postParams.remove("template"), "template");
"this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); String name = checkNotNull(postParams.remove("name"), "name"); final URI template = URI.create(checkNotNull(postParams.remove("template"), "template"));
public ContainerProperties apply(HttpResponse from) { MutableContainerPropertiesWithMetadata to = new MutableContainerPropertiesWithMetadataImpl(); to.setName(request.getArgs()[0].toString()); addUserMetadataTo(from, to); parseLastModifiedOrThrowException(from, to); addETagTo(from, to); to.setUrl(request.getEndpoint()); return to; }