Search in sources :

Example 11 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project java-chassis by ServiceComb.

the class TestParamSerializer method testSerialize.

@Test
public void testSerialize() {
    boolean status = true;
    Assert.assertNotNull(paramSerializer);
    String[] stringArray = new String[1];
    stringArray[0] = "abc";
    ProtobufGenerator obj = null;
    try {
        obj = new ProtobufGenerator(Mockito.mock(IOContext.class), 2, Mockito.mock(ObjectCodec.class), Mockito.mock(OutputStream.class));
    } catch (IOException exce) {
    }
    Assert.assertNotNull(obj);
    new MockUp<ProtobufGenerator>() {

        @Mock
        public void writeStartObject() throws IOException {
        }

        ProtobufSchema protobufSchema = new ProtobufSchema(null, null);

        @Mock
        public ProtobufSchema getSchema() {
            return protobufSchema;
        }
    };
    ProtobufMessage protobufMessage = new ProtobufMessage(null, null);
    new MockUp<ProtobufSchema>() {

        @Mock
        public ProtobufMessage getRootType() {
            return protobufMessage;
        }
    };
    List<ProtobufField> listProtobufField = new ArrayList<ProtobufField>();
    listProtobufField.add(Mockito.mock(ProtobufField.class));
    new MockUp<ProtobufMessage>() {

        @Mock
        public Iterable<ProtobufField> fields() {
            return listProtobufField;
        }
    };
    new MockUp<JsonGenerator>() {

        @Mock
        public void writeObjectField(String fieldName, Object pojo) throws IOException {
        }
    };
    new MockUp<ProtobufGenerator>() {

        @Mock
        public void writeEndObject() throws IOException {
        }
    };
    try {
        paramSerializer.serialize(stringArray, obj, Mockito.mock(SerializerProvider.class));
    } catch (JsonProcessingException e) {
        status = false;
    } catch (IOException e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : ArrayList(java.util.ArrayList) ProtobufSchema(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema) MockUp(mockit.MockUp) IOException(java.io.IOException) ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) ProtobufGenerator(com.fasterxml.jackson.dataformat.protobuf.ProtobufGenerator) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) Test(org.junit.Test)

Example 12 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project azure-sdk-for-java by Azure.

the class VirtualMachineImpl method capture.

@Override
public String capture(String containerName, String vhdPrefix, boolean overwriteVhd) {
    VirtualMachineCaptureParametersInner parameters = new VirtualMachineCaptureParametersInner();
    parameters.withDestinationContainerName(containerName);
    parameters.withOverwriteVhds(overwriteVhd);
    parameters.withVhdPrefix(vhdPrefix);
    VirtualMachineCaptureResultInner captureResult = this.manager().inner().virtualMachines().capture(this.resourceGroupName(), this.name(), parameters);
    if (captureResult == null) {
        return null;
    }
    ObjectMapper mapper = new ObjectMapper();
    //Object to JSON string
    try {
        return mapper.writeValueAsString(captureResult.output());
    } catch (JsonProcessingException e) {
        throw Exceptions.propagate(e);
    }
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project ORCID-Source by ORCID.

the class S3MessageProcessor method update_1_2_API.

private void update_1_2_API(String orcid) {
    if (is12IndexingEnabled) {
        try {
            OrcidMessage profile = orcid12ApiClient.fetchPublicProfile(orcid);
            // Update API 1.2
            if (profile != null) {
                s3Updater.updateS3(orcid, profile);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (LockedRecordException | DeprecatedRecordException e) {
            try {
                if (e instanceof LockedRecordException) {
                    LOG.error("Record " + orcid + " is locked");
                    exceptionHandler.handle12LockedRecordException(orcid, ((LockedRecordException) e).getOrcidMessage());
                } else {
                    LOG.error("Record " + orcid + " is deprecated");
                    exceptionHandler.handle12DeprecatedRecordException(orcid, ((DeprecatedRecordException) e).getOrcidDeprecated());
                }
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            } catch (JsonProcessingException | AmazonClientException | JAXBException e1) {
                LOG.error("Unable to handle LockedRecordException for record " + orcid, e1);
                recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (Exception e) {
            // something else went wrong fetching record from ORCID and
            // threw a
            // runtime exception
            LOG.error("Unable to fetch record " + orcid + " for 1.2 API");
            LOG.error(e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
        }
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JAXBException(javax.xml.bind.JAXBException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 14 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project oxAuth by GluuFederation.

the class ServletLoggingFilter method getRequestDescription.

protected String getRequestDescription(RequestWrapper requestWrapper) {
    HttpRequest httpRequest = new HttpRequest();
    httpRequest.setSenderIP(requestWrapper.getLocalAddr());
    httpRequest.setMethod(requestWrapper.getMethod());
    httpRequest.setPath(requestWrapper.getRequestURI());
    httpRequest.setParams(requestWrapper.isFormPost() ? null : requestWrapper.getParameters());
    httpRequest.setHeaders(requestWrapper.getHeaders());
    httpRequest.setBody(requestWrapper.getContent());
    try {
        return OBJECT_MAPPER.writeValueAsString(httpRequest);
    } catch (JsonProcessingException e) {
        log.warn("Cannot serialize Request to JSON", e);
        return null;
    }
}
Also used : HttpRequest(org.xdi.oxauth.audit.debug.entity.HttpRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 15 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project asterixdb by apache.

the class RestApiServlet method doHandle.

private void doHandle(IServletResponse response, String query, SessionOutput sessionOutput, ResultDelivery resultDelivery) throws JsonProcessingException {
    try {
        response.setStatus(HttpResponseStatus.OK);
        IHyracksClientConnection hcc = (IHyracksClientConnection) ctx.get(HYRACKS_CONNECTION_ATTR);
        IHyracksDataset hds = (IHyracksDataset) ctx.get(HYRACKS_DATASET_ATTR);
        if (hds == null) {
            synchronized (ctx) {
                hds = (IHyracksDataset) ctx.get(HYRACKS_DATASET_ATTR);
                if (hds == null) {
                    hds = new HyracksDataset(hcc, appCtx.getCompilerProperties().getFrameSize(), ResultReader.NUM_READERS);
                    ctx.put(HYRACKS_DATASET_ATTR, hds);
                }
            }
        }
        IParser parser = parserFactory.createParser(query);
        List<Statement> aqlStatements = parser.parse();
        validate(aqlStatements);
        MetadataManager.INSTANCE.init();
        IStatementExecutor translator = statementExecutorFactory.create(appCtx, aqlStatements, sessionOutput, compilationProvider, componentProvider);
        translator.compileAndExecute(hcc, hds, resultDelivery, null, new IStatementExecutor.Stats());
    } catch (AsterixException | TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError pe) {
        response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
        GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
        String errorMessage = ResultUtil.buildParseExceptionMessage(pe, query);
        ObjectNode errorResp = ResultUtil.getErrorResponse(2, errorMessage, "", ResultUtil.extractFullStackTrace(pe));
        sessionOutput.out().write(new ObjectMapper().writeValueAsString(errorResp));
    } catch (Exception e) {
        GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
        response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
        ResultUtil.apiErrorHandler(sessionOutput.out(), e);
    }
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Statement(org.apache.asterix.lang.common.base.Statement) TokenMgrError(org.apache.asterix.lang.aql.parser.TokenMgrError) AsterixException(org.apache.asterix.common.exceptions.AsterixException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) AsterixException(org.apache.asterix.common.exceptions.AsterixException) HyracksDataset(org.apache.hyracks.client.dataset.HyracksDataset) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(org.apache.asterix.lang.common.base.IParser)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)648 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)205 IOException (java.io.IOException)156 HashMap (java.util.HashMap)105 Map (java.util.Map)77 ArrayList (java.util.ArrayList)67 JsonNode (com.fasterxml.jackson.databind.JsonNode)54 List (java.util.List)50 Test (org.junit.Test)44 InputStream (java.io.InputStream)24 Collectors (java.util.stream.Collectors)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 Function (java.util.function.Function)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Date (java.util.Date)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)15 URL (java.net.URL)15