Search in sources :

Example 76 with Marshaller

use of javax.xml.bind.Marshaller in project spring-framework by spring-projects.

the class Jaxb2Marshaller method createMarshaller.

/**
	 * Return a newly created JAXB marshaller. JAXB marshallers are not necessarily thread safe.
	 */
protected Marshaller createMarshaller() {
    try {
        Marshaller marshaller = getJaxbContext().createMarshaller();
        initJaxbMarshaller(marshaller);
        return marshaller;
    } catch (JAXBException ex) {
        throw convertJaxbException(ex);
    }
}
Also used : GenericMarshaller(org.springframework.oxm.GenericMarshaller) MimeMarshaller(org.springframework.oxm.mime.MimeMarshaller) Marshaller(javax.xml.bind.Marshaller) AttachmentMarshaller(javax.xml.bind.attachment.AttachmentMarshaller) JAXBException(javax.xml.bind.JAXBException)

Example 77 with Marshaller

use of javax.xml.bind.Marshaller in project ddf by codice.

the class CswEndpoint method queryCsw.

private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
    if (LOGGER.isDebugEnabled()) {
        try {
            Writer writer = new StringWriter();
            try {
                Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
                marshaller.marshal(jaxbElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Unable to marshall {} to XML.  Exception {}", GetRecordsType.class, e);
            }
            LOGGER.debug(writer.toString());
        } catch (Exception e) {
            LOGGER.debug("Unable to create debug message for getRecordsType: {}", e);
        }
    }
    QueryType query = (QueryType) request.getAbstractQuery().getValue();
    CswRecordCollection response = new CswRecordCollection();
    response.setRequest(request);
    response.setOutputSchema(request.getOutputSchema());
    response.setMimeType(request.getOutputFormat());
    response.setElementName(query.getElementName());
    response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
    response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
    if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
        QueryRequest queryRequest = queryFactory.getQuery(request);
        try {
            queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
            LOGGER.debug("Attempting to execute query: {}", queryRequest);
            QueryResponse queryResponse = framework.query(queryRequest);
            response.setSourceResponse(queryResponse);
        } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
            LOGGER.debug("Unable to query", e);
            throw new CswException(e);
        }
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Marshaller(javax.xml.bind.Marshaller) QueryRequest(ddf.catalog.operation.QueryRequest) JAXBException(javax.xml.bind.JAXBException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) FederationException(ddf.catalog.federation.FederationException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) MimeTypeParseException(javax.activation.MimeTypeParseException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ParseException(com.vividsolutions.jts.io.ParseException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StringWriter(java.io.StringWriter) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 78 with Marshaller

use of javax.xml.bind.Marshaller in project ddf by codice.

the class BSTAuthenticationToken method getBinarySecurityToken.

/**
     * Creates a binary security token based on the provided credential.
     */
private synchronized String getBinarySecurityToken(String credential) {
    Writer writer = new StringWriter();
    Marshaller marshaller = null;
    BinarySecurityTokenType binarySecurityTokenType = createBinarySecurityTokenType(credential);
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement = new JAXBElement<BinarySecurityTokenType>(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "BinarySecurityToken"), BinarySecurityTokenType.class, binarySecurityTokenType);
    if (BINARY_TOKEN_CONTEXT != null) {
        try {
            marshaller = BINARY_TOKEN_CONTEXT.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        } catch (JAXBException e) {
            LOGGER.debug("Exception while creating UsernameToken marshaller.", e);
        }
        if (marshaller != null) {
            try {
                marshaller.marshal(binarySecurityTokenElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Exception while writing username token.", e);
            }
        }
    }
    String binarySecurityToken = writer.toString();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Binary Security Token: {}", binarySecurityToken);
    }
    return binarySecurityToken;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) BinarySecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 79 with Marshaller

use of javax.xml.bind.Marshaller in project ddf by codice.

the class WfsSource method logMessage.

private void logMessage(GetFeatureType getFeature) {
    if (LOGGER.isDebugEnabled()) {
        try {
            StringWriter writer = new StringWriter();
            String context = StringUtils.join(new String[] { Wfs20Constants.OGC_FILTER_PACKAGE, Wfs20Constants.OGC_GML_PACKAGE, Wfs20Constants.OGC_OWS_PACKAGE, Wfs20Constants.OGC_WFS_PACKAGE }, ":");
            JAXBContext contextObj = JAXBContext.newInstance(context, WfsSource.class.getClassLoader());
            Marshaller marshallerObj = contextObj.createMarshaller();
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshallerObj.marshal(new net.opengis.wfs.v_2_0_0.ObjectFactory().createGetFeature(getFeature), writer);
            LOGGER.debug("WfsSource {}: {}", getId(), writer.toString());
        } catch (JAXBException e) {
            LOGGER.debug("An error occurred debugging the GetFeature request", e);
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 80 with Marshaller

use of javax.xml.bind.Marshaller in project trex-stateless-gui by cisco-system-traffic-generator.

the class XMLFileManager method saveXML.

/**
     * Save data object as XML file
     *
     * @param fileName
     * @param dataToSave
     * @param classType
     */
public static void saveXML(String fileName, Object dataToSave, Class classType) {
    try {
        File file = new File(FileManager.createDirectoryIfNotExists(FileManager.getLocalFilePath()) + fileName);
        JAXBContext context = JAXBContext.newInstance(classType);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(dataToSave, file);
    } catch (JAXBException ex) {
        LOG.error("Error saving file " + fileName, ex);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File)

Aggregations

Marshaller (javax.xml.bind.Marshaller)280 JAXBContext (javax.xml.bind.JAXBContext)162 JAXBException (javax.xml.bind.JAXBException)100 StringWriter (java.io.StringWriter)82 Test (org.junit.Test)33 JAXBElement (javax.xml.bind.JAXBElement)32 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 File (java.io.File)29 Unmarshaller (javax.xml.bind.Unmarshaller)21 IOException (java.io.IOException)20 FileOutputStream (java.io.FileOutputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)15 QName (javax.xml.namespace.QName)14 Element (org.w3c.dom.Element)14 HashMap (java.util.HashMap)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)11 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7