/** * Initializes an instance of GeneratedServices. * * @param client the instance of the service client containing this operation class. */ public GeneratedServices(GeneratedStorageClient client) { this.service = RestProxy.create(ServicesService.class, client); this.client = client; }
/** * Create a proxy implementation of the provided Swagger interface. * @param swaggerInterface The Swagger interface to provide a proxy implementation for. * @param <A> The type of the Swagger interface. * @return A proxy implementation of the provided Swagger interface. */ @SuppressWarnings("unchecked") public static <A> A create(Class<A> swaggerInterface) { return create(swaggerInterface, createDefaultPipeline(), createDefaultSerializer()); }
protected Single<HttpResponse> ensureExpectedStatus(HttpResponse httpResponse, int[] additionalAllowedStatusCodes) { return restProxy.ensureExpectedStatus(httpResponse, methodParser, additionalAllowedStatusCodes); }
/** * Create a proxy implementation of the provided Swagger interface. * @param swaggerInterface The Swagger interface to provide a proxy implementation for. * @param httpPipeline The RequestPolicy and HttpClient pipline that will be used to send Http * requests. * @param <A> The type of the Swagger interface. * @return A proxy implementation of the provided Swagger interface. */ @SuppressWarnings("unchecked") public static <A> A create(Class<A> swaggerInterface, HttpPipeline httpPipeline) { return create(swaggerInterface, httpPipeline, createDefaultSerializer()); }
@Override public Object invoke(Object proxy, final Method method, Object[] args) { try { SwaggerMethodParser methodParser = null; HttpRequest request = null; if (method.isAnnotationPresent(ResumeOperation.class)) { OperationDescription opDesc = (OperationDescription) args[0]; Method resumeMethod = null; Method[] methods = method.getDeclaringClass().getMethods(); for (Method origMethod : methods) { if (origMethod.getName().equals(opDesc.methodName())) { resumeMethod = origMethod; break; } } methodParser = methodParser(resumeMethod); request = createHttpRequest(opDesc, methodParser, args); final Type returnType = methodParser.returnType(); return handleResumeOperation(request, opDesc, methodParser, returnType); } else { methodParser = methodParser(method); request = createHttpRequest(methodParser, args); final Single<HttpResponse> asyncResponse = sendHttpRequestAsync(request); final Type returnType = methodParser.returnType(); return handleAsyncHttpResponse(request, asyncResponse, methodParser, returnType); } } catch (Exception e) { throw Exceptions.propagate(e); } }
/** * Initializes an instance of GeneratedStorageClient client. */ public GeneratedStorageClient() { this(RestProxy.createDefaultPipeline()); }
Object result; final Single<HttpResponse> asyncExpectedResponse = ensureExpectedStatus(asyncHttpResponse, methodParser); final Type singleTypeParam = TypeUtil.getTypeArgument(returnType); result = asyncExpectedResponse.flatMap(response -> handleRestResponseReturnTypeAsync(response, methodParser, singleTypeParam)); handleRestResponseReturnTypeAsync(httpResponse, methodParser, returnType)) .blockingGet();
protected Object handleAsyncHttpResponse(HttpRequest httpRequest, Single<HttpResponse> asyncHttpResponse, SwaggerMethodParser methodParser, Type returnType) { return handleRestReturnType(httpRequest, asyncHttpResponse, methodParser, returnType); }
Single<?> asyncResult; if (TypeUtil.isTypeOrSubTypeOf(entityType, RestResponse.class)) { Constructor<? extends RestResponse<?, ?>> responseConstructor = getRestResponseConstructor(entityType); final Map<String, String> rawHeaders = responseHeaders.toMap(); asyncResult = handleBodyReturnTypeAsync(response, methodParser, bodyType) .map((Function<Object, RestResponse<?, ?>>) body -> responseConstructor.newInstance(response.request(), responseStatusCode, deserializedHeaders, rawHeaders, body)) .toSingle(responseConstructor.newInstance(response.request(), responseStatusCode, deserializedHeaders, rawHeaders, null)); asyncResult = handleBodyReturnTypeAsync(response, methodParser, entityType).toSingle();
protected SerializerAdapter<?> createSerializerAdapter() { return RestProxy.createDefaultSerializer(); } }
/** * Create a proxy implementation of the provided Swagger interface. * @param swaggerInterface The Swagger interface to provide a proxy implementation for. * @param httpPipeline The RequestPolicy and HttpClient pipline that will be used to send Http * requests. * @param serializer The serializer that will be used to convert POJOs to and from request and * response bodies. * @param <A> The type of the Swagger interface. * @return A proxy implementation of the provided Swagger interface. */ @SuppressWarnings("unchecked") public static <A> A create(Class<A> swaggerInterface, HttpPipeline httpPipeline, SerializerAdapter<?> serializer) { final SwaggerInterfaceParser interfaceParser = new SwaggerInterfaceParser(swaggerInterface, serializer); final RestProxy restProxy = new RestProxy(httpPipeline, serializer, interfaceParser); return (A) Proxy.newProxyInstance(swaggerInterface.getClassLoader(), new Class[]{swaggerInterface}, restProxy); } }
/** * Create the default HttpPipeline. * @return the default HttpPipeline. */ public static HttpPipeline createDefaultPipeline() { return createDefaultPipeline((RequestPolicyFactory) null); }
Observable<OperationStatus<Object>> createOperationStatusObservable(HttpRequest httpRequest, HttpResponse httpResponse, SwaggerMethodParser methodParser, Type operationStatusResultType) { OperationStatus<Object> operationStatus; if (!isDone()) { operationStatus = new OperationStatus<>(this, httpRequest); } else { try { final Object resultObject = restProxy.handleRestReturnType(httpRequest, Single.just(httpResponse), methodParser, operationStatusResultType); operationStatus = new OperationStatus<>(resultObject, status()); } catch (RestException e) { operationStatus = new OperationStatus<>(e, OperationState.FAILED); } } return Observable.just(operationStatus); }
/** * Initializes an instance of GeneratedContainers. * * @param client the instance of the service client containing this operation class. */ public GeneratedContainers(GeneratedStorageClient client) { this.service = RestProxy.create(ContainersService.class, client); this.client = client; }
/** * Initializes an instance of GeneratedStorageClient client. */ public GeneratedStorageClient() { this(RestProxy.createDefaultPipeline()); }
private Single<HttpResponse> ensureExpectedStatus(final HttpResponse response, final SwaggerMethodParser methodParser) { return ensureExpectedStatus(response, methodParser, null); }
/** * Initializes an instance of GeneratedBlockBlobs. * * @param client the instance of the service client containing this operation class. */ public GeneratedBlockBlobs(GeneratedStorageClient client) { this.service = RestProxy.create(BlockBlobsService.class, client); this.client = client; }
/** * Create the default HttpPipeline. * @param credentials The credentials to use to apply authentication to the pipeline. * @return the default HttpPipeline. */ public static HttpPipeline createDefaultPipeline(ServiceClientCredentials credentials) { return createDefaultPipeline(new CredentialsPolicyFactory(credentials)); }
/** * Initializes an instance of GeneratedPageBlobs. * * @param client the instance of the service client containing this operation class. */ public GeneratedPageBlobs(GeneratedStorageClient client) { this.service = RestProxy.create(PageBlobsService.class, client); this.client = client; }
/** * Initializes an instance of GeneratedBlobs. * * @param client the instance of the service client containing this operation class. */ public GeneratedBlobs(GeneratedStorageClient client) { this.service = RestProxy.create(BlobsService.class, client); this.client = client; }