Search in sources :

Example 56 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.

the class VeeamClient method parseRestoreSessionResponse.

private RestoreSession parseRestoreSessionResponse(HttpResponse response) throws IOException {
    checkResponseOK(response);
    final ObjectMapper objectMapper = new XmlMapper();
    return objectMapper.readValue(response.getEntity().getContent(), RestoreSession.class);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 57 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.

the class VeeamClient method findDCHierarchy.

// /////////////////////////////////////////////////////////////////
// ////////////// Private Veeam Helper Methods /////////////////////
// /////////////////////////////////////////////////////////////////
private String findDCHierarchy(final String vmwareDcName) {
    LOG.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName);
    try {
        final HttpResponse response = get("/hierarchyRoots");
        checkResponseOK(response);
        final ObjectMapper objectMapper = new XmlMapper();
        final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
        for (final Ref ref : references.getRefs()) {
            if (ref.getName().equals(vmwareDcName) && ref.getType().equals("HierarchyRootReference")) {
                return ref.getUid();
            }
        }
    } catch (final IOException e) {
        LOG.error("Failed to list Veeam jobs due to:", e);
        checkResponseTimeOut(e);
    }
    throw new CloudRuntimeException("Failed to find hierarchy reference for VMware datacenter " + vmwareDcName + " in Veeam, please ask administrator to check Veeam B&R manager configuration");
}
Also used : EntityReferences(org.apache.cloudstack.backup.veeam.api.EntityReferences) Ref(org.apache.cloudstack.backup.veeam.api.Ref) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 58 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project dhis2-core by dhis2.

the class StAXNodeSerializer method startSerialize.

@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
    writer = xmlFactory.createXMLStreamWriter(outputStream);
    generator = (new XmlFactory()).createGenerator(writer);
    generator.setCodec(new XmlMapper());
    writer.setDefaultNamespace(rootNode.getDefaultNamespace());
}
Also used : XmlFactory(com.fasterxml.jackson.dataformat.xml.XmlFactory) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 59 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project dhis2-core by dhis2.

the class AbstractJobParametersDeserializer method deserialize.

@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    final ObjectCodec oc = p.getCodec();
    final JsonNode jsonNode;
    if (oc instanceof XmlMapper) {
        jsonNode = createJsonNode(p, ctxt);
        return objectMapper.treeToValue(jsonNode, overrideClass);
    } else {
        jsonNode = oc.readTree(p);
        // serialization settings
        return oc.treeToValue(jsonNode, overrideClass);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 60 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project dhis2-core by dhis2.

the class JobConfigurationSerializationTest method xmlWithJson.

@Test
void xmlWithJson() throws IOException {
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    xmlMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false);
    JobConfiguration jc = xmlMapper.readValue("<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" + "      <jobStatus>SCHEDULED</jobStatus>\n" + "      <displayName>Test Analytic</displayName>\n" + "      <enabled>true</enabled>\n" + "      <leaderOnlyJob>true</leaderOnlyJob>\n" + "      <externalAccess>false</externalAccess>\n" + "      <jobType>ANALYTICS_TABLE</jobType>\n" + "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" + "      <favorite>false</favorite>\n" + "      <configurable>true</configurable>\n" + "      <access>\n" + "        <read>true</read>\n" + "        <update>true</update>\n" + "        <externalize>false</externalize>\n" + "        <delete>true</delete>\n" + "        <write>true</write>\n" + "        <manage>true</manage>\n" + "      </access>\n" + "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" + "      <jobParameters>\n" + "        <lastYears>2</lastYears>\n" + "        <skipResourceTables>true</skipResourceTables>\n" + "        <skipTableTypes>\n" + "          <skipTableType>ENROLLMENT</skipTableType>\n" + "          <skipTableType>ORG_UNIT_TARGET</skipTableType>\n" + "          <skipTableType>VALIDATION_RESULT</skipTableType>\n" + "        </skipTableTypes>" + "        <skipPrograms>\n" + "          <String>" + UID1 + "</String>\n" + "          <String>" + UID2 + "</String>\n" + "        </skipPrograms>" + "      </jobParameters>\n" + "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" + "    </jobConfiguration>", JobConfiguration.class);
    assertEquals(JobStatus.SCHEDULED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getName());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertTrue(jc.isEnabled());
    assertTrue(jc.isLeaderOnlyJob());
    assertEquals(JobType.ANALYTICS_TABLE, jc.getJobType());
    assertNull(jc.getNextExecutionTime());
    assertEquals("0 0 12 ? * MON-FRI", jc.getCronExpression());
    assertNotNull(jc.getJobParameters());
    assertEquals((Integer) 2, ((AnalyticsJobParameters) jc.getJobParameters()).getLastYears());
    assertTrue(((AnalyticsJobParameters) jc.getJobParameters()).isSkipResourceTables());
    assertNotNull(((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes());
    assertEquals(3, ((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes().size());
    assertThat(((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes(), Matchers.hasItems(AnalyticsTableType.ENROLLMENT, AnalyticsTableType.ORG_UNIT_TARGET, AnalyticsTableType.VALIDATION_RESULT));
    assertThat(((AnalyticsJobParameters) jc.getJobParameters()).getSkipPrograms(), Matchers.hasItems(UID1, UID2));
}
Also used : AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)62 IOException (java.io.IOException)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Test (org.junit.Test)15 InputStream (java.io.InputStream)9 File (java.io.File)8 HttpResponse (org.apache.http.HttpResponse)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (ninja.exceptions.BadRequestException)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 Ref (org.apache.cloudstack.backup.veeam.api.Ref)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)2 FileInputStream (java.io.FileInputStream)2