Search in sources :

Example 1 with ObjectMapper

use of com.mashape.unirest.http.ObjectMapper in project blueocean-plugin by jenkinsci.

the class PipelineBaseTest method setup.

@Before
public void setup() throws Exception {
    if (System.getProperty("DISABLE_HTTP_HEADER_TRACE") == null) {
        InputStream is = this.getClass().getResourceAsStream("/logging.properties");
        LogManager.getLogManager().readConfiguration(is);
    }
    this.baseUrl = j.jenkins.getRootUrl() + getContextPath();
    this.jwtToken = getJwtToken(j.jenkins);
    Unirest.setObjectMapper(new ObjectMapper() {

        public <T> T readValue(String value, Class<T> valueType) {
            try {
                if (value.isEmpty()) {
                    value = "{}";
                }
                T r = JsonConverter.om.readValue(value, valueType);
                LOGGER.info("Response:\n" + JsonConverter.om.writeValueAsString(r));
                return r;
            } catch (IOException e) {
                LOGGER.info("Failed to parse JSON: " + value + ". " + e.getMessage());
                throw new RuntimeException(e);
            }
        }

        public String writeValue(Object value) {
            try {
                String str = JsonConverter.om.writeValueAsString(value);
                LOGGER.info("Request:\n" + str);
                return str;
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
    });
//        HttpClientParams params = new HttpClientParams();
//
//        HttpClient client = new HttpClient();
//        Unirest.setHttpClient();
}
Also used : X_BLUEOCEAN_JWT(io.jenkins.blueocean.auth.jwt.JwtToken.X_BLUEOCEAN_JWT) InputStream(java.io.InputStream) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.mashape.unirest.http.ObjectMapper) Before(org.junit.Before)

Example 2 with ObjectMapper

use of com.mashape.unirest.http.ObjectMapper in project blueocean-plugin by jenkinsci.

the class BaseTest method setup.

@Before
public void setup() throws Exception {
    if (System.getProperty("DISABLE_HTTP_HEADER_TRACE") == null) {
        InputStream is = this.getClass().getResourceAsStream("/logging.properties");
        LogManager.getLogManager().readConfiguration(is);
    }
    this.baseUrl = j.jenkins.getRootUrl() + getContextPath();
    this.jwtToken = getJwtToken(j.jenkins);
    Unirest.setObjectMapper(new ObjectMapper() {

        public <T> T readValue(String value, Class<T> valueType) {
            try {
                if (value.isEmpty()) {
                    value = "{}";
                }
                T r = JsonConverter.om.readValue(value, valueType);
                LOGGER.info("Response:\n" + JsonConverter.om.writeValueAsString(r));
                return r;
            } catch (IOException e) {
                LOGGER.info("Failed to parse JSON: " + value + ". " + e.getMessage());
                throw new RuntimeException(e);
            }
        }

        public String writeValue(Object value) {
            try {
                String str = JsonConverter.om.writeValueAsString(value);
                LOGGER.info("Request:\n" + str);
                return str;
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
    });
//        HttpClientParams params = new HttpClientParams();
//
//        HttpClient client = new HttpClient();
//        Unirest.setHttpClient();
}
Also used : X_BLUEOCEAN_JWT(io.jenkins.blueocean.auth.jwt.JwtToken.X_BLUEOCEAN_JWT) InputStream(java.io.InputStream) JSONObject(net.sf.json.JSONObject) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.mashape.unirest.http.ObjectMapper) Before(org.junit.Before)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.mashape.unirest.http.ObjectMapper)2 X_BLUEOCEAN_JWT (io.jenkins.blueocean.auth.jwt.JwtToken.X_BLUEOCEAN_JWT)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Before (org.junit.Before)2 JSONObject (net.sf.json.JSONObject)1