List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
/** * JAXB object translation methods *///from w ww .j a v a 2s . c o m public static Object transformXmlObj2XmlObj(Class sourceClass, Class destClass, Object source) { try { JAXBContext sourceContext = JAXBContext.newInstance(sourceClass); JAXBSource jaxbSource = new JAXBSource(sourceContext, source); JAXBContext destContext = JAXBContext.newInstance(destClass); Unmarshaller unmarshaller = destContext.createUnmarshaller(); return unmarshaller.unmarshal(jaxbSource); } catch (JAXBException ex) { System.err.println(ex.getMessage()); return null; } }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Export mail from openkm repository to filesystem. */// www. j a v a 2 s . com public static ImpExpStats exportMail(String token, String mailPath, String destPath, String metadata, Writer out, InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException, AccessDeniedException, ParseException, NoSuchGroupException, MessagingException { MailModule mm = ModuleManager.getMailModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Mail mailChild = mm.getProperties(token, mailPath); Gson gson = new Gson(); ImpExpStats stats = new ImpExpStats(); MimeMessage msg = MailUtils.create(token, mailChild); FileOutputStream fos = new FileOutputStream(destPath); msg.writeTo(fos); IOUtils.closeQuietly(fos); FileLogger.info(BASE_NAME, "Created document ''{0}''", mailChild.getPath()); // Metadata if (metadata.equals("JSON")) { MailMetadata mmd = ma.getMetadata(mailChild); String json = gson.toJson(mmd); fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { fos = new FileOutputStream(destPath + ".xml"); MailMetadata mmd = ma.getMetadata(mailChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(MailMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(mmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } if (out != null) { out.write(deco.print(mailChild.getPath(), mailChild.getSize(), null)); out.flush(); } // Stats stats.setSize(stats.getSize() + mailChild.getSize()); stats.setMails(stats.getMails() + 1); return stats; }
From source file:com.microfocus.application.automation.tools.octane.executor.UFTTestDetectionService.java
/** * Serialize detectionResult to file in XML format * * @param fileToWriteTo/*from w w w . jav a2 s . c om*/ * @param taskListenerLog * @param detectionResult */ public static void publishDetectionResults(File fileToWriteTo, TaskListener taskListenerLog, UftTestDiscoveryResult detectionResult) { try { detectionResult.writeToFile(fileToWriteTo); } catch (JAXBException e) { String msg = "Failed to persist detection results because of JAXBException : " + e.getMessage(); if (taskListenerLog != null) { taskListenerLog.error(msg); } logger.error(msg); } }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java
private static void validateResponse(TextMessage response, String correlationId) throws SpatialModelValidationException { try {//w ww. j a v a 2 s. c o m if (response == null) { throw new SpatialModelValidationException( "Error when validating response in ResponseMapper: Response is Null"); } if (response.getJMSCorrelationID() == null) { throw new SpatialModelValidationException( "No correlationId in response (Null) . Expected was: " + correlationId); } if (!correlationId.equalsIgnoreCase(response.getJMSCorrelationID())) { throw new SpatialModelValidationException("Wrong correlationId in response. Expected was: " + correlationId + " But actual was: " + response.getJMSCorrelationID()); } try { Fault fault = JAXBUtils.unMarshallMessage(response.getText(), Fault.class); throw new SpatialModelValidationException(fault.getCode() + " : " + fault.getFault()); } catch (JAXBException e) { log.info("Expected Exception"); // Exception received in case if the validation is success } } catch (JMSException e) { log.error("JMS exception during validation ", e); throw new SpatialModelValidationException("JMS exception during validation " + e.getMessage()); } }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Performs a recursive repository content export with metadata *//*from w w w. j a v a 2 s . c o m*/ private static ImpExpStats exportDocumentsHelper(String token, String fldPath, File fs, String metadata, boolean history, Writer out, InfoDecorator deco) throws FileNotFoundException, PathNotFoundException, AccessDeniedException, RepositoryException, IOException, DatabaseException, ParseException, NoSuchGroupException, MessagingException { log.debug("exportDocumentsHelper({}, {}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, fs, metadata, history, out, deco }); ImpExpStats stats = new ImpExpStats(); DocumentModule dm = ModuleManager.getDocumentModule(); FolderModule fm = ModuleManager.getFolderModule(); MailModule mm = ModuleManager.getMailModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Gson gson = new Gson(); String path = null; File fsPath = null; if (firstTime) { path = fs.getPath(); fsPath = new File(path); firstTime = false; } else { // Repository path needs to be "corrected" under Windoze path = fs.getPath() + File.separator + PathUtils.getName(fldPath).replace(':', '_'); fsPath = new File(path); fsPath.mkdirs(); FileLogger.info(BASE_NAME, "Created folder ''{0}''", fsPath.getPath()); if (out != null) { out.write(deco.print(fldPath, 0, null)); out.flush(); } } for (Iterator<Mail> it = mm.getChildren(token, fldPath).iterator(); it.hasNext();) { Mail mailChild = it.next(); path = fsPath.getPath() + File.separator + PathUtils.getName(mailChild.getPath()).replace(':', '_'); ImpExpStats mailStats = exportMail(token, mailChild.getPath(), path + ".eml", metadata, out, deco); // Stats stats.setSize(stats.getSize() + mailStats.getSize()); stats.setMails(stats.getMails() + mailStats.getMails()); } for (Iterator<Document> it = dm.getChildren(token, fldPath).iterator(); it.hasNext();) { Document docChild = it.next(); path = fsPath.getPath() + File.separator + PathUtils.getName(docChild.getPath()).replace(':', '_'); ImpExpStats docStats = exportDocument(token, docChild.getPath(), path, metadata, history, out, deco); // Stats stats.setSize(stats.getSize() + docStats.getSize()); stats.setDocuments(stats.getDocuments() + docStats.getDocuments()); } for (Iterator<Folder> it = fm.getChildren(token, fldPath).iterator(); it.hasNext();) { Folder fldChild = it.next(); ImpExpStats tmp = exportDocumentsHelper(token, fldChild.getPath(), fsPath, metadata, history, out, deco); path = fsPath.getPath() + File.separator + PathUtils.getName(fldChild.getPath()).replace(':', '_'); // Metadata if (metadata.equals("JSON")) { FolderMetadata fmd = ma.getMetadata(fldChild); String json = gson.toJson(fmd); FileOutputStream fos = new FileOutputStream(path + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); fos.close(); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(path + ".xml"); FolderMetadata fmd = ma.getMetadata(fldChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(FolderMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(fmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } // Stats stats.setSize(stats.getSize() + tmp.getSize()); stats.setDocuments(stats.getDocuments() + tmp.getDocuments()); stats.setFolders(stats.getFolders() + tmp.getFolders() + 1); stats.setOk(stats.isOk() && tmp.isOk()); } log.debug("exportDocumentsHelper: {}", stats); return stats; }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Export document from openkm repository to filesystem. *//* ww w . j ava 2 s .co m*/ public static ImpExpStats exportDocument(String token, String docPath, String destPath, String metadata, boolean history, Writer out, InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException, AccessDeniedException, ParseException, NoSuchGroupException { DocumentModule dm = ModuleManager.getDocumentModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Document docChild = dm.getProperties(token, docPath); Gson gson = new Gson(); ImpExpStats stats = new ImpExpStats(); // Version history if (history) { // Create dummy document file new File(destPath).createNewFile(); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); FileOutputStream fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } for (Version ver : dm.getVersionHistory(token, docChild.getPath())) { String versionPath = destPath + "#v" + ver.getName() + "#"; FileOutputStream vos = new FileOutputStream(versionPath); InputStream vis = dm.getContentByVersion(token, docChild.getPath(), ver.getName()); IOUtils.copy(vis, vos); IOUtils.closeQuietly(vis); IOUtils.closeQuietly(vos); FileLogger.info(BASE_NAME, "Created document ''{0}'' version ''{1}''", docChild.getPath(), ver.getName()); // Metadata if (metadata.equals("JSON")) { VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); String json = gson.toJson(vmd); vos = new FileOutputStream(versionPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, vos); IOUtils.closeQuietly(vos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(VersionMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(vmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } } else { FileOutputStream fos = new FileOutputStream(destPath); InputStream is = dm.getContent(token, docChild.getPath(), false); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); FileLogger.info(BASE_NAME, "Created document ''{0}''", docChild.getPath()); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } if (out != null) { out.write(deco.print(docChild.getPath(), docChild.getActualVersion().getSize(), null)); out.flush(); } // Stats stats.setSize(stats.getSize() + docChild.getActualVersion().getSize()); stats.setDocuments(stats.getDocuments() + 1); return stats; }
From source file:com.hpe.application.automation.tools.octane.executor.UFTTestDetectionService.java
/** * Serialize detectionResult to file in XML format * * @param fileToWriteTo/*from w w w.ja v a 2 s. co m*/ * @param taskListenerLog * @param detectionResult */ public static void publishDetectionResults(File fileToWriteTo, TaskListener taskListenerLog, UFTTestDetectionResult detectionResult) { try { JAXBContext jaxbContext = JAXBContext.newInstance(UFTTestDetectionResult.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(detectionResult, fileToWriteTo); } catch (JAXBException e) { if (taskListenerLog != null) { taskListenerLog.error("Failed to persist detection results: " + e.getMessage()); } logger.error("Failed to persist detection results: " + e.getMessage()); } }
From source file:org.fcrepo.fixity.web.provider.FixityJaxbContextResolver.java
/** * TODO/* ww w. j a v a 2 s .c o m*/ */ public FixityJaxbContextResolver() { try { context = JAXBContext.newInstance(DailyStatistics.class, Statistics.class, DatastreamFixityResult.class, DatastreamFixityError.class, DatastreamFixityRepaired.class, DatastreamFixitySuccess.class, ObjectFixityResult.class); } catch (JAXBException e) { LOG.error(e.getMessage(), e); throw new IllegalStateException("Not able to instantiate Jaxb context", e); } }
From source file:gov.nih.nci.cabig.caaers.web.rule.ContextListener.java
private RuleUi load(String fileName) { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); try {//ww w.ja va 2 s . com Unmarshaller unmarshaller = JAXBContext.newInstance("com.semanticbits.rules.ui").createUnmarshaller(); RuleUi ruleUi = (RuleUi) unmarshaller.unmarshal(inputStream); return ruleUi; } catch (JAXBException e) { throw new CaaersSystemException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.oracle.demo.ops.event.spring.converter.ParcelLogEventMessageConverter.java
@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { //System.out.println("MessageConverter! "); try {/* w w w .java 2 s. c o m*/ return MyMarshaller.unmarshalEvent((TextMessage) message); } catch (JAXBException e) { throw new MessageConversionException("Error in MessageConverter: " + e.getMessage(), e); } }