<commit_before>package com.cx.client.rest;


import com.cx.client.CxPluginHelper;
import com.cx.client.dto.LoginRequest;
import com.cx.client.dto.OSAFile;
import com.cx.client.exception.CxClientException;
import com.cx.client.rest.dto.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.client.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.security.KeyManagementException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by: Dorg.
 * Date: 16/06/2016.
 */
public class CxRestClient {

    private final String username;
    private final String password;
    private Client client;
    private WebTarget root;

    public static final String OSA_SCAN_PROJECT_PATH = "osa/scans";
    public static final String OSA_SCAN_STATUS_PATH = "osa/scans/{scanId}";
    public static final String OSA_SCAN_SUMMARY_PATH = "osa/reports";
    public static final String OSA_SCAN_LIBRARIES_PATH = "/osa/libraries";
    public static final String OSA_SCAN_VULNERABILITIES_PATH = "/osa/vulnerabilities";
    private static final String AUTHENTICATION_PATH = "auth/login";
    private static final String ROOT_PATH = "CxRestAPI";
    public static final String CSRF_TOKEN_HEADER = "CXCSRFToken";
    public static final long MAX_ITEMS = 1000000;
    private ArrayList<Object> cookies;
    private String csrfToken;
    private ObjectMapper mapper = new ObjectMapper();

    private static final Logger log = LoggerFactory.getLogger(CxRestClient.class);


    private ClientResponseFilter clientResponseFilter = new ClientResponseFilter() {

        public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) throws IOException {
            // copy cookies
            if (clientResponseContext.getCookies() != null) {
                if (cookies == null) {
                    cookies = new ArrayList<Object>();
                }
                //cookies.clear();
                cookies.addAll(clientResponseContext.getCookies().values());

                if (clientResponseContext.getCookies().get(CSRF_TOKEN_HEADER) != null) {
                    csrfToken = clientResponseContext.getCookies().get(CSRF_TOKEN_HEADER).getValue();
                }
            }
        }

    };


    private ClientRequestFilter clientRequestFilter = new ClientRequestFilter() {
        public void filter(ClientRequestContext clientRequestContext) throws IOException {
            if (cookies != null) {
                clientRequestContext.getHeaders().put("Cookie", cookies);
            }

            if (csrfToken != null) {
                clientRequestContext.getHeaders().putSingle(CSRF_TOKEN_HEADER, csrfToken);
            }

            Object contentType = clientRequestContext.getHeaders().getFirst("Content-Type");
            String header = contentType == null ? "v=1" : contentType + ";v=1";
            clientRequestContext.getHeaders().putSingle("Content-Type", header);<commit_msg>revert add version to osa REST calls<commit_after>package com.cx.client.rest;


import com.cx.client.CxPluginHelper;
import com.cx.client.dto.LoginRequest;
import com.cx.client.dto.OSAFile;
import com.cx.client.exception.CxClientException;
import com.cx.client.rest.dto.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.client.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.security.KeyManagementException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by: Dorg.
 * Date: 16/06/2016.
 */
public class CxRestClient {

    private final String username;
    private final String password;
    private Client client;
    private WebTarget root;

    public static final String OSA_SCAN_PROJECT_PATH = "osa/scans";
    public static final String OSA_SCAN_STATUS_PATH = "osa/scans/{scanId}";
    public static final String OSA_SCAN_SUMMARY_PATH = "osa/reports";
    public static final String OSA_SCAN_LIBRARIES_PATH = "/osa/libraries";
    public static final String OSA_SCAN_VULNERABILITIES_PATH = "/osa/vulnerabilities";
    private static final String AUTHENTICATION_PATH = "auth/login";
    private static final String ROOT_PATH = "CxRestAPI";
    public static final String CSRF_TOKEN_HEADER = "CXCSRFToken";
    public static final long MAX_ITEMS = 1000000;
    private ArrayList<Object> cookies;
    private String csrfToken;
    private ObjectMapper mapper = new ObjectMapper();

    private static final Logger log = LoggerFactory.getLogger(CxRestClient.class);


    private ClientResponseFilter clientResponseFilter = new ClientResponseFilter() {

        public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) throws IOException {
            // copy cookies
            if (clientResponseContext.getCookies() != null) {
                if (cookies == null) {
                    cookies = new ArrayList<Object>();
                }
                //cookies.clear();
                cookies.addAll(clientResponseContext.getCookies().values());

                if (clientResponseContext.getCookies().get(CSRF_TOKEN_HEADER) != null) {
                    csrfToken = clientResponseContext.getCookies().get(CSRF_TOKEN_HEADER).getValue();
                }
            }
        }

    };


    private ClientRequestFilter clientRequestFilter = new ClientRequestFilter() {
        public void filter(ClientRequestContext clientRequestContext) throws IOException {
            if (cookies != null) {
                clientRequestContext.getHeaders().put("Cookie", cookies);
            }

            if (csrfToken != null) {
                clientRequestContext.getHeaders().putSingle(CSRF_TOKEN_HEADER, csrfToken);
            }
{'fraction_non_alphanumeric': 0.09365853658536585, 'fraction_numerical': 0.005853658536585366, 'mean_word_length': 3.2420689655172414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2974534', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1654, 'n_words': 379}