|
| 1 | +/** |
| 2 | + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
| 3 | + */ |
| 4 | +package com.oracle.bmc.core.internal.http; |
| 5 | + |
| 6 | +import java.io.InputStream; |
| 7 | +import java.util.Date; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Map; |
| 10 | +import java.util.HashMap; |
| 11 | + |
| 12 | +import javax.ws.rs.client.*; |
| 13 | +import javax.ws.rs.core.*; |
| 14 | + |
| 15 | +import com.oracle.bmc.http.internal.*; |
| 16 | +import static com.oracle.bmc.util.internal.HttpUtils.*; |
| 17 | +import com.oracle.bmc.model.*; |
| 18 | +import com.oracle.bmc.core.model.*; |
| 19 | +import com.oracle.bmc.core.requests.*; |
| 20 | +import com.oracle.bmc.core.responses.*; |
| 21 | + |
| 22 | +import com.google.common.base.Function; |
| 23 | +import com.google.common.base.Optional; |
| 24 | + |
| 25 | +import lombok.extern.slf4j.Slf4j; |
| 26 | + |
| 27 | +@javax.annotation.Generated(value = "OracleSDKGenerator", comments = "API Version: 20160918") |
| 28 | +@Slf4j |
| 29 | +public class GetWindowsInstanceInitialCredentialsConverter { |
| 30 | + private static final ResponseConversionFunctionFactory RESPONSE_CONVERSION_FACTORY = |
| 31 | + new ResponseConversionFunctionFactory(); |
| 32 | + |
| 33 | + public static GetWindowsInstanceInitialCredentialsRequest interceptRequest( |
| 34 | + GetWindowsInstanceInitialCredentialsRequest request) { |
| 35 | + |
| 36 | + return request; |
| 37 | + } |
| 38 | + |
| 39 | + public static Invocation.Builder fromRequest( |
| 40 | + RestClient client, GetWindowsInstanceInitialCredentialsRequest request) { |
| 41 | + if (request == null) { |
| 42 | + throw new NullPointerException("request instance is required"); |
| 43 | + } |
| 44 | + |
| 45 | + if (request.getInstanceId() == null) { |
| 46 | + throw new NullPointerException("instanceId is required"); |
| 47 | + } |
| 48 | + |
| 49 | + WebTarget target = |
| 50 | + client.getBaseTarget() |
| 51 | + .path("/20160918") |
| 52 | + .path("instances") |
| 53 | + .path(encodePathSegment(request.getInstanceId())) |
| 54 | + .path("initialCredentials"); |
| 55 | + |
| 56 | + Invocation.Builder ib = target.request(); |
| 57 | + |
| 58 | + ib.accept(MediaType.APPLICATION_JSON); |
| 59 | + |
| 60 | + return ib; |
| 61 | + } |
| 62 | + |
| 63 | + public static Function<Response, GetWindowsInstanceInitialCredentialsResponse> fromResponse() { |
| 64 | + final Function<Response, GetWindowsInstanceInitialCredentialsResponse> transformer = |
| 65 | + new Function<Response, GetWindowsInstanceInitialCredentialsResponse>() { |
| 66 | + @Override |
| 67 | + public GetWindowsInstanceInitialCredentialsResponse apply( |
| 68 | + Response rawResponse) { |
| 69 | + LOG.trace( |
| 70 | + "Transform function invoked for GetWindowsInstanceInitialCredentialsResponse"); |
| 71 | + Function<Response, WithHeaders<InstanceCredentials>> responseFn = |
| 72 | + RESPONSE_CONVERSION_FACTORY.create(InstanceCredentials.class); |
| 73 | + |
| 74 | + WithHeaders<InstanceCredentials> response = responseFn.apply(rawResponse); |
| 75 | + MultivaluedMap<String, String> headers = response.getHeaders(); |
| 76 | + |
| 77 | + GetWindowsInstanceInitialCredentialsResponse.Builder builder = |
| 78 | + GetWindowsInstanceInitialCredentialsResponse.builder(); |
| 79 | + |
| 80 | + builder.instanceCredentials(response.getItem()); |
| 81 | + |
| 82 | + Optional<List<String>> opcRequestIdHeader = |
| 83 | + HeaderUtils.get(headers, "opc-request-id"); |
| 84 | + if (opcRequestIdHeader.isPresent()) { |
| 85 | + builder.opcRequestId( |
| 86 | + HeaderUtils.toValue( |
| 87 | + "opc-request-id", |
| 88 | + opcRequestIdHeader.get().get(0), |
| 89 | + String.class)); |
| 90 | + } |
| 91 | + |
| 92 | + GetWindowsInstanceInitialCredentialsResponse responseWrapper = |
| 93 | + builder.build(); |
| 94 | + |
| 95 | + return responseWrapper; |
| 96 | + } |
| 97 | + }; |
| 98 | + return transformer; |
| 99 | + } |
| 100 | +} |
0 commit comments