use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class CrossServerNotification method getHandler.
@Override
public MessageHandler getHandler() {
return new MessageHandler() {
@Override
public void handle(Message m, String clientId) {
if (!(m instanceof CrossServerNotification)) {
return;
}
CrossServerNotification message = (CrossServerNotification) m;
Collection<Session> sessions = SessionCache.getSoapSessions(m.getRecipientAccountId());
if (sessions == null) {
log.warn("no active sessions for account %s", m.getRecipientAccountId());
return;
}
RemoteNotifications soapNtfn = null, jsonNtfn = null;
try {
org.dom4j.Document dom = org.dom4j.DocumentHelper.parseText(message.getPayload());
soapNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), XMLElement.mFactory));
jsonNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), JSONElement.mFactory));
} catch (DocumentException e) {
log.warn("cannot parse notification from %s", clientId, e);
return;
}
for (Session session : sessions) {
log.debug("notifying session %s", session.toString());
SoapSession ss = (SoapSession) session;
SoapProtocol responseProtocol = ss.getResponseProtocol();
if (responseProtocol == SoapProtocol.Soap11 || responseProtocol == SoapProtocol.Soap12) {
ss.addRemoteNotifications(soapNtfn);
} else if (responseProtocol == SoapProtocol.SoapJS) {
ss.addRemoteNotifications(jsonNtfn);
}
ss.forcePush();
}
}
};
}
use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class ElementTest method dom4jSAXReaderWhichUsesSecureProcessing.
@Test
public void dom4jSAXReaderWhichUsesSecureProcessing() throws XmlParseException, SAXException, DocumentException {
org.dom4j.io.SAXReader dom4jSAXReader;
org.dom4j.Document doc;
dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithNoEntityRefNoDocType.getBytes(StandardCharsets.UTF_8)));
Assert.assertNotNull("org.dom4j.Document object should not be null", doc);
Assert.assertEquals("Round tripped XML", provisioningXMLWithNoEntityRefNoDocType, doc.asXML());
dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
try {
doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithEntityRefButNoDecl.getBytes(StandardCharsets.UTF_8)));
Assert.assertNotNull("org.dom4j.Document object should not be null", doc);
Assert.fail("DocumentException should have been thrown");
} catch (DocumentException de) {
Assert.assertTrue(de.getMessage().contains("The entity \"xxe\" was referenced, but not declared."));
}
dom4jSAXReader = W3cDomUtil.getDom4jSAXReaderWhichUsesSecureProcessing();
try {
doc = dom4jSAXReader.read(new ByteArrayInputStream(provisioningXMLWithEntityRefAndDecl.getBytes(StandardCharsets.UTF_8)));
} catch (DocumentException de) {
Assert.assertTrue(de.getMessage().contains("DOCTYPE is disallowed when the feature " + "\"http://apache.org/xml/features/disallow-doctype-decl\" set to true"));
}
}
use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class LocalConfigUpgrade method main.
public static void main(String[] args) throws ServiceException {
CliUtil.toolSetup();
CommandLine cl = null;
try {
CommandLineParser parser = new GnuParser();
Options options = getAllOptions();
cl = parser.parse(options, args);
if (cl == null)
throw new ParseException("");
} catch (ParseException pe) {
usage(pe.getMessage());
}
if (cl.hasOption(O_HELP)) {
usage(null);
}
if (!cl.hasOption(O_BUG)) {
usage("no bug specified");
}
if (!cl.hasOption(O_TAG)) {
usage("no backup suffix tag specified");
}
LocalConfig lc = null;
try {
lc = new LocalConfig(cl.getOptionValue("c"));
lc.backup(cl.getOptionValue("t"));
} catch (DocumentException de) {
ZimbraLog.misc.error("failed reading config file", de);
System.exit(1);
} catch (ConfigException ce) {
ZimbraLog.misc.error("failed reading config file", ce);
System.exit(2);
} catch (IOException ioe) {
ZimbraLog.misc.error("failed to backup config file", ioe);
System.exit(3);
}
String[] bugs = cl.getOptionValues(O_BUG);
for (String bug : bugs) {
if (!sUpgrades.containsKey(bug)) {
ZimbraLog.misc.warn("local config upgrade can't handle bug " + bug);
continue;
}
LocalConfigUpgrade lcu = sUpgrades.get(bug);
System.out.println("== Running local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
try {
lcu.upgrade(lc);
System.out.println("== Done local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
} catch (ConfigException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
lc.save();
} catch (IOException ioe) {
ZimbraLog.misc.error("failed writing config file", ioe);
System.exit(1);
} catch (ConfigException ce) {
ZimbraLog.misc.error("failed writing config file", ce);
System.exit(1);
}
}
use of org.dom4j.DocumentException in project tdi-studio-se by Talend.
the class AlfrescoOutputModelManager method removeModel.
/**
* Removes an Alfresco model definition file.
*
* @param oldModelFilePath
* @throws AlfrescoOutputException
*/
public void removeModel(String oldModelFilePath) throws AlfrescoOutputException {
if (!this.availableModels.remove(oldModelFilePath)) {
//$NON-NLS-1$
throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.notYetAdded"));
}
// parsing the model
org.dom4j.Document modelDoc = null;
try {
modelDoc = new SAXReader().read(new File(oldModelFilePath));
} catch (DocumentException dex) {
throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + oldModelFilePath, dex);
}
Element modelElt = modelDoc.getRootElement();
//$NON-NLS-1$
Element namespacesElt = modelElt.element("namespaces");
if (namespacesElt != null) {
//$NON-NLS-1$
List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
for (Element namespace : namespaces) {
//$NON-NLS-1$
String namespacePrefix = namespace.attributeValue("prefix");
this.availablePrefixToNamespaceMap.remove(namespacePrefix);
}
}
//$NON-NLS-1$
Element typesElt = modelElt.element("types");
if (typesElt != null) {
//$NON-NLS-1$
List<Element> types = (List<Element>) typesElt.elements("type");
this.availableTypes.removeAllAlfrescoModelElement(types);
}
//$NON-NLS-1$
Element aspectsElt = modelElt.element("aspects");
if (aspectsElt != null) {
//$NON-NLS-1$
List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
this.availableAspects.removeAllAlfrescoModelElement(aspects);
}
}
use of org.dom4j.DocumentException in project tdi-studio-se by Talend.
the class ComponentFolderManager method writeXMLContent.
/**
* DOC slanglois Comment method "writeXMLContent".
*
* @param iFile
* @param document
* @param enCode
* @throws CoreException
*/
private void writeXMLContent(IFile iFile, Document document, String enCode) throws CoreException {
PrintWriter pw = null;
XMLWriter writer = null;
byte[] byteArray = null;
// get xml content as inputstream
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = tf.newTransformer();
} catch (TransformerConfigurationException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
DOMSource source = new DOMSource(document);
transformer.setOutputProperty(OutputKeys.ENCODING, enCode);
//$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
ByteArrayOutputStream sw = new ByteArrayOutputStream();
pw = new PrintWriter(sw);
StreamResult result = new StreamResult(pw);
try {
transformer.transform(source, result);
} catch (TransformerException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
try {
sw.flush();
} catch (IOException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
} finally {
if (pw != null) {
pw.close();
}
}
byteArray = sw.toByteArray();
// format the xml content
SAXReader saxReader = new SAXReader();
org.dom4j.Document dom4jDocument = null;
try {
dom4jDocument = saxReader.read(new ByteArrayInputStream(byteArray));
} catch (DocumentException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
/** format the output like the webBrowser */
OutputFormat format = OutputFormat.createPrettyPrint();
/** give the xml encoding */
format.setEncoding(enCode);
sw = new ByteArrayOutputStream();
try {
writer = new XMLWriter(sw, format);
} catch (UnsupportedEncodingException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
}
try {
writer.write(dom4jDocument);
writer.flush();
} catch (IOException e1) {
// e1.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e1);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// e.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(e);
}
}
}
byteArray = sw.toByteArray();
// write content
iFile.setContents(new ByteArrayInputStream(byteArray), true, false, null);
}
Aggregations