Search in sources :

Example 86 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project cobigen by devonfw.

the class OpenAPIInputReader method extractParameters.

/**
 * @param operationOverlay overlay of the operation to get all parameters from
 * @return a list of {@link ParameterDef} from a collection of parameters of an operation
 */
private List<ParameterDef> extractParameters(Overlay<Operation> operationOverlay) {
    Collection<? extends Parameter> parameters = operationOverlay.get().getParameters();
    Collection<String> tags = operationOverlay.get().getTags();
    RequestBody requestBody = operationOverlay.get().getRequestBody();
    List<ParameterDef> parametersList = new LinkedList<>();
    ParameterDef parameter;
    for (Parameter param : parameters) {
        parameter = new ParameterDef();
        parameter.setIsBody(false);
        switch(param.getIn()) {
            case "path":
                parameter.setInPath(true);
                break;
            case "query":
                parameter.setInQuery(true);
                break;
            case "header":
                parameter.setInHeader(true);
                break;
        }
        parameter.setName(param.getName());
        Schema schema = param.getSchema();
        Map<String, Object> constraints = extractConstraints(schema);
        if (param.isRequired()) {
            constraints.put(ModelConstant.NOTNULL, true);
        } else {
            constraints.put(ModelConstant.NOTNULL, false);
        }
        parameter.setConstraints(constraints);
        parameter.setDescription(param.getDescription());
        if (schema.getType().equals(Constants.ARRAY)) {
            parameter.setIsCollection(true);
            if (schema.getItemsSchema() != null) {
                parameter.setIsEntity(true);
            }
        }
        try {
            if (Overlay.isReference(operationOverlay.getOverlay(), param.getKey())) {
                parameter.setIsEntity(true);
                parameter.setType(schema.getName());
            } else {
                parameter.setType(schema.getType());
                parameter.setFormat(schema.getFormat());
            }
        } catch (NullPointerException e) {
            throw new CobiGenRuntimeException("Error at parameter " + param.getName() + ". Invalid OpenAPI file, path parameters need to have a schema defined.");
        }
        parametersList.add(parameter);
    }
    if (requestBody != null) {
        Schema mediaSchema;
        for (String media : requestBody.getContentMediaTypes().keySet()) {
            parameter = new ParameterDef();
            parameter.setIsBody(true);
            parameter.setMediaType(media);
            if (tags.contains(Constants.SEARCH_CRITERIA) || tags.contains(Constants.SEARCH_CRITERIA.toLowerCase())) {
                parameter.setIsSearchCriteria(true);
                parameter.setName("criteria");
            }
            if (requestBody.getContentMediaTypes().get(media).getSchema() != null) {
                mediaSchema = requestBody.getContentMediaTypes().get(media).getSchema();
                parameter.setIsEntity(true);
                parameter.setType(requestBody.getContentMediaType(media).getSchema().getName());
                if (!parameter.getIsSearchCriteria()) {
                    char[] c = mediaSchema.getName().toCharArray();
                    c[0] = Character.toLowerCase(c[0]);
                    parameter.setName(new String(c));
                }
            }
            if (parameter.getType() != null) {
                Map<String, Object> constraints = new HashMap<>();
                constraints.put(ModelConstant.NOTNULL, true);
                parameter.setConstraints(constraints);
                parametersList.add(parameter);
            }
        }
    }
    return parametersList;
}
Also used : CobiGenRuntimeException(com.devonfw.cobigen.api.exception.CobiGenRuntimeException) ParameterDef(com.devonfw.cobigen.openapiplugin.model.ParameterDef) HashMap(java.util.HashMap) Schema(com.reprezen.kaizen.oasparser.model3.Schema) LinkedList(java.util.LinkedList) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) RequestBody(com.reprezen.kaizen.oasparser.model3.RequestBody)

Example 87 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project okta-oidc-android by okta.

the class OkHttp method buildRequest.

protected Request buildRequest(Uri uri, ConnectionParameters param) {
    try {
        mTrustAllSslContext = SSLContext.getInstance("SSL");
        mTrustAllSslContext.init(null, mTrustManager, new java.security.SecureRandom());
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException(e);
    }
    mTrustAllSslSocketFactory = mTrustAllSslContext.getSocketFactory();
    if (sOkHttpClient == null) {
        sOkHttpClient = new OkHttpClient.Builder().readTimeout(param.readTimeOutMs(), TimeUnit.MILLISECONDS).connectTimeout(param.connectionTimeoutMs(), TimeUnit.MILLISECONDS).hostnameVerifier((hostname, session) -> true).sslSocketFactory(mTrustAllSslSocketFactory, (X509TrustManager) mTrustManager[0]).build();
    }
    Request.Builder requestBuilder = new Request.Builder().url(uri.toString());
    for (Map.Entry<String, String> headerEntry : param.requestProperties().entrySet()) {
        String key = headerEntry.getKey();
        requestBuilder.addHeader(key, headerEntry.getValue());
    }
    if (param.requestMethod() == ConnectionParameters.RequestMethod.GET) {
        requestBuilder = requestBuilder.get();
    } else {
        Map<String, String> postParameters = param.postParameters();
        if (postParameters != null) {
            FormBody.Builder formBuilder = new FormBody.Builder();
            for (Map.Entry<String, String> postEntry : postParameters.entrySet()) {
                String key = postEntry.getKey();
                formBuilder.add(key, postEntry.getValue());
            }
            RequestBody formBody = formBuilder.build();
            requestBuilder.post(formBody);
        } else {
            requestBuilder.post(RequestBody.create(null, ""));
        }
    }
    return requestBuilder.build();
}
Also used : SSLContext(javax.net.ssl.SSLContext) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) TrustManager(javax.net.ssl.TrustManager) RequestBody(okhttp3.RequestBody) FormBody(okhttp3.FormBody) Map(java.util.Map) Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) OktaHttpClient(com.okta.oidc.net.OktaHttpClient) Request(okhttp3.Request) ConnectionParameters(com.okta.oidc.net.ConnectionParameters) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InputStream(java.io.InputStream) Request(okhttp3.Request) FormBody(okhttp3.FormBody) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) Map(java.util.Map) RequestBody(okhttp3.RequestBody)

Example 88 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.

the class Client method issuePostFeedRequest.

public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName, Resource resource, String resourceFormat) throws IOException {
    String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
    byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
    RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
    Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
    return executeBundleRequest(request, resourceFormat, new Headers.Builder().build(), null, retryCount, timeout);
}
Also used : Request(okhttp3.Request) RequestBody(okhttp3.RequestBody)

Example 89 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.

the class Client method issuePutRequest.

public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, Headers headers, String message, long timeout) throws IOException {
    if (payload == null)
        throw new EFhirClientException("PUT requests require a non-null payload");
    RequestBody body = RequestBody.create(payload);
    Request.Builder request = new Request.Builder().url(resourceUri.toURL()).put(body);
    return executeFhirRequest(request, resourceFormat, headers, message, retryCount, timeout);
}
Also used : Request(okhttp3.Request) EFhirClientException(org.hl7.fhir.dstu3.utils.client.EFhirClientException) RequestBody(okhttp3.RequestBody)

Example 90 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.

the class Client method issuePostRequest.

public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, Headers headers, String message, long timeout) throws IOException {
    if (payload == null)
        throw new EFhirClientException("POST requests require a non-null payload");
    RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
    Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
    return executeFhirRequest(request, resourceFormat, headers, message, retryCount, timeout);
}
Also used : Request(okhttp3.Request) EFhirClientException(org.hl7.fhir.dstu3.utils.client.EFhirClientException) RequestBody(okhttp3.RequestBody)

Aggregations

RequestBody (okhttp3.RequestBody)1358 Request (okhttp3.Request)785 Response (okhttp3.Response)598 IOException (java.io.IOException)420 Test (org.junit.Test)235 OkHttpClient (okhttp3.OkHttpClient)216 MultipartBody (okhttp3.MultipartBody)213 MediaType (okhttp3.MediaType)204 Call (okhttp3.Call)198 JSONObject (org.json.JSONObject)183 ResponseBody (okhttp3.ResponseBody)177 Callback (okhttp3.Callback)115 FormBody (okhttp3.FormBody)106 Buffer (okio.Buffer)98 File (java.io.File)92 Map (java.util.Map)90 JsonObject (io.vertx.core.json.JsonObject)89 Headers (okhttp3.Headers)88 HashMap (java.util.HashMap)83 HttpUrl (okhttp3.HttpUrl)80