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);
}
}
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;
}
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;
}
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);
}
}
}
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);
}
}
Aggregations