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();
}
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();
}
Aggregations