Search in sources :

Example 56 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project data-prep by Talend.

the class PreparationUpdate method onExecute.

private HttpRequestBase onExecute(String id, Preparation preparation) {
    try {
        final byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation);
        final HttpPut preparationCreation = new HttpPut(preparationServiceUrl + "/preparations/" + id);
        preparationCreation.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
        preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue));
        return preparationCreation;
    } catch (JsonProcessingException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 57 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project knox by apache.

the class DefaultServiceRegistryService method renderAsJsonString.

private String renderAsJsonString(HashMap<String, HashMap<String, RegEntry>> registry) {
    String json = null;
    ObjectMapper mapper = new ObjectMapper();
    try {
        // write JSON to a file
        json = mapper.writeValueAsString((Object) registry);
    } catch (JsonProcessingException e) {
        // TODO: I18N
        e.printStackTrace();
    }
    return json;
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project libsignal-service-java by signalapp.

the class PushServiceSocket method makeServiceRequest.

private String makeServiceRequest(String urlFragment, String method, String body) throws NonSuccessfulResponseCodeException, PushNetworkException {
    Response response = getServiceConnection(urlFragment, method, body);
    int responseCode;
    String responseMessage;
    String responseBody;
    try {
        responseCode = response.code();
        responseMessage = response.message();
        responseBody = response.body().string();
    } catch (IOException ioe) {
        throw new PushNetworkException(ioe);
    }
    switch(responseCode) {
        case 413:
            throw new RateLimitException("Rate limit exceeded: " + responseCode);
        case 401:
        case 403:
            throw new AuthorizationFailedException("Authorization failed!");
        case 404:
            throw new NotFoundException("Not found");
        case 409:
            MismatchedDevices mismatchedDevices;
            try {
                mismatchedDevices = JsonUtil.fromJson(responseBody, MismatchedDevices.class);
            } catch (JsonProcessingException e) {
                Log.w(TAG, e);
                throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
            } catch (IOException e) {
                throw new PushNetworkException(e);
            }
            throw new MismatchedDevicesException(mismatchedDevices);
        case 410:
            StaleDevices staleDevices;
            try {
                staleDevices = JsonUtil.fromJson(responseBody, StaleDevices.class);
            } catch (JsonProcessingException e) {
                throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
            } catch (IOException e) {
                throw new PushNetworkException(e);
            }
            throw new StaleDevicesException(staleDevices);
        case 411:
            DeviceLimit deviceLimit;
            try {
                deviceLimit = JsonUtil.fromJson(responseBody, DeviceLimit.class);
            } catch (JsonProcessingException e) {
                throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
            } catch (IOException e) {
                throw new PushNetworkException(e);
            }
            throw new DeviceLimitExceededException(deviceLimit);
        case 417:
            throw new ExpectationFailedException();
        case 423:
            RegistrationLockFailure accountLockFailure;
            try {
                accountLockFailure = JsonUtil.fromJson(responseBody, RegistrationLockFailure.class);
            } catch (JsonProcessingException e) {
                Log.w(TAG, e);
                throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
            } catch (IOException e) {
                throw new PushNetworkException(e);
            }
            throw new LockedException(accountLockFailure.length, accountLockFailure.timeRemaining);
    }
    if (responseCode != 200 && responseCode != 204) {
        throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage);
    }
    return responseBody;
}
Also used : PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) RateLimitException(org.whispersystems.signalservice.api.push.exceptions.RateLimitException) ExpectationFailedException(org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) StaleDevicesException(org.whispersystems.signalservice.internal.push.exceptions.StaleDevicesException) IOException(java.io.IOException) Response(okhttp3.Response) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) MismatchedDevicesException(org.whispersystems.signalservice.internal.push.exceptions.MismatchedDevicesException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 59 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project feign-reactive by kptfh.

the class DefaultMethodTest method shouldWrapExceptionWithFlux.

@Test
public void shouldWrapExceptionWithFlux() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    IcecreamServiceApi client = ReactiveFeign.<IcecreamServiceApi>builder().webClient(WebClient.create()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    IceCreamOrder errorOrder = client.throwExceptionFlux().onErrorReturn(throwable -> throwable.equals(IcecreamServiceApi.RUNTIME_EXCEPTION), orderGenerated).blockFirst();
    assertThat(errorOrder).isEqualToComparingFieldByField(orderGenerated);
}
Also used : WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AllFeaturesApi(reactivefeign.allfeatures.AllFeaturesApi) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Rule(org.junit.Rule) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Example 60 with JsonProcessingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project feign-reactive by kptfh.

the class DefaultMethodTest method shouldWrapExceptionWithMono.

@Test
public void shouldWrapExceptionWithMono() throws JsonProcessingException {
    IceCreamOrder orderGenerated = new OrderGenerator().generate(1);
    IcecreamServiceApi client = ReactiveFeign.<IcecreamServiceApi>builder().webClient(WebClient.create()).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    IceCreamOrder errorOrder = client.throwExceptionMono().onErrorReturn(throwable -> throwable.equals(IcecreamServiceApi.RUNTIME_EXCEPTION), orderGenerated).block();
    assertThat(errorOrder).isEqualToComparingFieldByField(orderGenerated);
}
Also used : WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AllFeaturesApi(reactivefeign.allfeatures.AllFeaturesApi) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Rule(org.junit.Rule) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) Test(org.junit.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)741 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)241 IOException (java.io.IOException)174 HashMap (java.util.HashMap)108 Map (java.util.Map)83 ArrayList (java.util.ArrayList)74 JsonNode (com.fasterxml.jackson.databind.JsonNode)73 Test (org.junit.Test)65 List (java.util.List)56 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)36 Collectors (java.util.stream.Collectors)30 InputStream (java.io.InputStream)26 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 File (java.io.File)20 Function (java.util.function.Function)20 Logger (org.slf4j.Logger)20 Optional (java.util.Optional)19 Date (java.util.Date)18 Test (org.testng.annotations.Test)18