Example usage for javax.xml.bind JAXBException getMessage

List of usage examples for javax.xml.bind JAXBException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.tajo.catalog.store.XMLCatalogSchemaManager.java

protected StoreObject loadCatalogStore(XMLStreamReader xmlReader) throws XMLStreamException {
    try {/*from www. j  a v  a 2  s .  c om*/
        JAXBElement<StoreObject> elem = unmarshaller.unmarshal(xmlReader, StoreObject.class);
        return elem.getValue();
    } catch (JAXBException e) {
        throw new XMLStreamException(e.getMessage(), xmlReader.getLocation(), e);
    }
}

From source file:org.apereo.portal.portlet.container.EventProviderImpl.java

@Override
public Event createEvent(QName qname, Serializable value) throws IllegalArgumentException {
    if (this.isDeclaredAsPublishingEvent(qname)) {
        if (value != null && !this.isValueInstanceOfDefinedClass(qname, value)) {
            throw new IllegalArgumentException("Payload class (" + value.getClass().getCanonicalName()
                    + ") does not have the right class, check your defined event types in portlet.xml.");
        }//  www .j a  v a2  s .  c  o m

        if (value == null) {
            return new EventImpl(qname);
        }

        try {
            final Thread currentThread = Thread.currentThread();
            final ClassLoader cl = currentThread.getContextClassLoader();
            final Writer out = new StringWriter();
            final Class clazz = value.getClass();
            try {
                currentThread.setContextClassLoader(this.portletClassLoader);
                final JAXBContext jc = JAXBContext.newInstance(clazz);
                final Marshaller marshaller = jc.createMarshaller();
                final JAXBElement<Serializable> element = new JAXBElement<Serializable>(qname, clazz, value);
                marshaller.marshal(element, out);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            return new EventImpl(qname, out.toString());
        } catch (JAXBException e) {
            // maybe there is no valid jaxb binding
            // TODO throw exception?
            logger.error("Event handling failed", e);
        } catch (FactoryConfigurationError e) {
            // TODO throw exception?
            logger.warn(e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.codice.ddf.catalog.ui.forms.SearchFormsSymbolsIT.java

private static FilterWriter getWriter() {
    try {//from  w w w. jav a  2s. co m
        return new FilterWriter(true);
    } catch (JAXBException e) {
        throw new AssertionError("Could not make filter writer, " + e.getMessage());
    }
}

From source file:org.codice.ddf.catalog.ui.forms.TemplateTransformer.java

/** Convert the JSON representation of a FormTemplate to a QueryTemplateMetacard. */
@Nullable/*from w  w  w.ja  va2 s.c  om*/
public Metacard toQueryTemplateMetacard(Map<String, Object> formTemplate) {
    try {
        Map<String, Object> filterJson = (Map) formTemplate.get("filterTemplate");
        if (filterJson == null) {
            return null;
        }

        String title = (String) formTemplate.get("title");
        if (StringUtils.isBlank(title)) {
            throw new IllegalArgumentException("Search form title cannot be blank");
        }

        String description = (String) formTemplate.get("description");
        String id = (String) formTemplate.get("id");

        TransformVisitor<JAXBElement> visitor = new TransformVisitor<>(new XmlModelBuilder(registry));
        VisitableJsonElementImpl.create(new FilterNodeMapImpl(filterJson)).accept(visitor);
        JAXBElement filter = visitor.getResult();
        if (!filter.getDeclaredType().equals(FilterType.class)) {
            LOGGER.error("Error occurred during filter processing, root type should be a {} but was {}",
                    FilterType.class.getName(), filter.getDeclaredType().getName());
            return null;
        }

        QueryTemplateMetacard metacard = (id == null) ? new QueryTemplateMetacard(title, description)
                : new QueryTemplateMetacard(title, description, id);

        String filterXml = writer.marshal(filter);
        metacard.setFormsFilter(filterXml);
        Map<String, Object> querySettings = (Map<String, Object>) formTemplate.get("querySettings");
        if (querySettings != null) {
            metacard.setQuerySettings(querySettings);
        }

        return metacard;
    } catch (JAXBException e) {
        LOGGER.error("XML generation failed for query template metacard's filter", e);
    } catch (FilterProcessingException e) {
        LOGGER.error("Could not use filter JSON for template - {}", e.getMessage());
    }
    return null;
}

From source file:org.codice.ddf.catalog.ui.forms.TemplateTransformer.java

/** Convert a query template metacard into the JSON representation of FormTemplate. */
@Nullable//from   w w w  . j a v  a  2  s  .c om
public FormTemplate toFormTemplate(Metacard metacard) {
    if (!QueryTemplateMetacard.isQueryTemplateMetacard(metacard)) {
        LOGGER.debug("Metacard {} was not a query template metacard", metacard.getId());
        return null;
    }

    QueryTemplateMetacard wrapped = new QueryTemplateMetacard(metacard);
    TransformVisitor<FilterNode> visitor = new TransformVisitor<>(new JsonModelBuilder(registry));

    String metacardOwner = retrieveOwnerIfPresent(metacard);
    Map<String, List<Serializable>> securityAttributes = retrieveSecurityIfPresent(metacard);

    try {
        FilterReader reader = new FilterReader();
        String formsFilter = wrapped.getFormsFilter();
        if (formsFilter == null) {
            LOGGER.debug("Invalid form data was ingested for metacard [{}], no form filter present",
                    wrapped.getId());
            return null;
        }
        JAXBElement<FilterType> root = reader
                .unmarshalFilter(new ByteArrayInputStream(formsFilter.getBytes(StandardCharsets.UTF_8)));
        VisitableXmlElementImpl.create(root).accept(visitor);
        return new FormTemplate(wrapped, visitor.getResult(), securityAttributes, metacardOwner,
                wrapped.getQuerySettings());
    } catch (JAXBException e) {
        LOGGER.error(
                "XML parsing failed for query template metacard's filter, with metacard id " + metacard.getId(),
                e);
    } catch (FilterProcessingException e) {
        LOGGER.error("Could not use filter XML for template - {} [metacard id = {}]", e.getMessage(),
                metacard.getId());
    } catch (UnsupportedOperationException e) {
        LOGGER.error(
                "Could not use filter XML because it contains unsupported operations - {} [metacard id = {}]",
                e.getMessage(), metacard.getId());
    }
    return null;
}

From source file:org.codice.ddf.endpoints.subscriptions.SubscriptionService.java

/**
 * Constructor for Subscription REST service.
 * /*from  w  w w  . j av  a  2s .c  o m*/
 * @param EventProcessor the MTS EventProcessor to use to
 *            create/update/delete/query subscriptions
 */
public SubscriptionService(BundleContext context, EventProcessor EventProcessor) {
    this.context = context;
    this.eventProcessor = EventProcessor;

    try {
        JAXBContext jc = JAXBContext.newInstance(Subscription.class);
        this.unmarshaller = jc.createUnmarshaller();
    } catch (JAXBException e) {
        LOGGER.warn(e.getMessage(), e);
    }

}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java

/** Tests to see that JAXB configuration is working */
@Test//  w  w w .j a v a2s. c  om
public void testMarshallDescribeRecord() {

    DescribeRecordResponseType response = new DescribeRecordResponseType();

    List<SchemaComponentType> schemas = new ArrayList<>();

    SchemaComponentType schemaComponentType = new SchemaComponentType();
    schemas.add(schemaComponentType);
    response.setSchemaComponent(schemas);

    JAXBContext context;
    try {

        context = JAXBContext
                .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1");
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        StringWriter sw = new StringWriter();

        JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema,
                DescribeRecordResponseType.class, response);

        marshaller.marshal(wrappedResponse, sw);

        LOGGER.info("Response: {}", sw.toString());

    } catch (JAXBException e) {
        fail("Could not marshall message, Error: " + e.getMessage());
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java

private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) {
    // Verify the response will marshal
    try {/* ww  w.  ja va  2 s  . c om*/
        JAXBContext context = JAXBContext.newInstance(contextPath);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        StringWriter sw = new StringWriter();

        JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName,
                TransactionResponseType.class, response);

        marshaller.marshal(wrappedResponse, sw);

        LOGGER.info("Response: {}", sw.toString());

    } catch (JAXBException e) {
        fail("Could not marshal message, Error: " + e.getMessage());
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java

/**
 * Tests to see that JAXB configuration is working
 *//*from  w w w. j a va2 s  .c  o  m*/
@Test
public void testMarshallDescribeRecord() {

    DescribeRecordResponseType response = new DescribeRecordResponseType();

    List<SchemaComponentType> schemas = new ArrayList<>();

    SchemaComponentType schemaComponentType = new SchemaComponentType();
    schemas.add(schemaComponentType);
    response.setSchemaComponent(schemas);

    JAXBContext context;
    try {

        context = JAXBContext
                .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1");
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        StringWriter sw = new StringWriter();

        JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema,
                DescribeRecordResponseType.class, response);

        marshaller.marshal(wrappedResponse, sw);

        LOGGER.info("\nResponse\n" + sw.toString() + "\n\n");

    } catch (JAXBException e) {
        fail("Could not marshall message, Error: " + e.getMessage());
    }

}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java

private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) {
    // Verify the response will marshal
    try {//from w w  w  .  jav  a2 s  .  co  m
        JAXBContext context = JAXBContext.newInstance(contextPath);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        StringWriter sw = new StringWriter();

        JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName,
                TransactionResponseType.class, response);

        marshaller.marshal(wrappedResponse, sw);

        LOGGER.info("\nResponse\n" + sw.toString() + "\n\n");

    } catch (JAXBException e) {
        fail("Could not marshal message, Error: " + e.getMessage());
    }
}