use of java.io.StringBufferInputStream in project pentaho-platform by pentaho.
the class PentahoSolutionSpringApplicationContextTest method shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven.
@Test(timeout = 2000, expected = SAXException.class)
public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException {
appContext.getResourceDocument(new StringBufferInputStream(XmlTestConstants.MALICIOUS_XML));
fail();
}
use of java.io.StringBufferInputStream in project pentaho-platform by pentaho.
the class RepositorySyncWebService method sync.
public RepositorySyncStatus sync(String repositoryId, String repositoryUrl) throws RepositorySyncException {
boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
"true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
if (singleDiServerInstance) {
return RepositorySyncStatus.SINGLE_DI_SERVER_INSTANCE;
}
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
try {
repositoriesMeta.readData();
} catch (Exception e) {
// $NON-NLS-1$
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_READ_DATA"), e);
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_READ_DATA"), // $NON-NLS-1$
e);
}
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryId);
if (repositoryMeta == null) {
try {
repositoryMeta = getRepositoryMeta(repositoryId, repositoryUrl);
if (repositoryMeta == null) {
// $NON-NLS-1$
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_LOAD_PLUGIN"));
throw new RepositorySyncException(Messages.getInstance().getString(// $NON-NLS-1$
"RepositorySyncWebService.UNABLE_TO_LOAD_PLUGIN"));
}
repositoriesMeta.addRepository(repositoryMeta);
repositoriesMeta.writeData();
return RepositorySyncStatus.REGISTERED;
} catch (KettleException e) {
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_REGISTER_REPOSITORY", repositoryId), // $NON-NLS-1$
e);
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_REGISTER_REPOSITORY", repositoryId), // $NON-NLS-1$
e);
}
} else {
String xml = repositoryMeta.getXML();
Element node;
try {
node = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder().parse(new StringBufferInputStream(xml)).getDocumentElement();
} catch (Exception e) {
node = null;
}
if (node != null) {
// $NON-NLS-1$
NodeList list = node.getElementsByTagName("repository_location_url");
if (list != null && list.getLength() == 1) {
String url = list.item(0).getTextContent();
if (url.equals(repositoryUrl)) {
// now test base URL
String fullyQualifiedServerUrl = null;
if (PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() != null) {
fullyQualifiedServerUrl = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
if (url.endsWith("/")) {
// $NON-NLS-1$
url = url.substring(0, url.length() - 2);
}
if (fullyQualifiedServerUrl.endsWith("/")) {
// $NON-NLS-1$
fullyQualifiedServerUrl = fullyQualifiedServerUrl.substring(0, fullyQualifiedServerUrl.length() - 2);
}
if (url.startsWith(fullyQualifiedServerUrl)) {
return RepositorySyncStatus.ALREADY_REGISTERED;
}
}
log.error(Messages.getInstance().getString("RepositorySyncWebService.FULLY_QUALIFIED_SERVER_URL_SYNC_PROBLEM", fullyQualifiedServerUrl, // $NON-NLS-1$
url));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.FULLY_QUALIFIED_SERVER_URL_SYNC_PROBLEM", fullyQualifiedServerUrl, // $NON-NLS-1$
url));
} else {
log.error(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_SYNC_PROBLEM", repositoryId, url, // $NON-NLS-1$
repositoryUrl));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_SYNC_PROBLEM", repositoryId, url, // $NON-NLS-1$
repositoryUrl));
}
}
}
log.error(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_XML_PARSING_PROBLEM", repositoryId, // $NON-NLS-1$
xml));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_XML_PARSING_PROBLEM_CLIENT_MESSAGE", // $NON-NLS-1$
repositoryId));
}
}
use of java.io.StringBufferInputStream in project mule by mulesoft.
the class ScatterGatherRouterTestCase method consumablePayload.
@Test
@Description("Consumable payloads are not supported.")
public void consumablePayload() throws Exception {
MessageProcessorChain route1 = newChain(empty(), event -> event);
MessageProcessorChain route2 = newChain(empty(), event -> event);
router.setRoutes(asList(route1, route2));
muleContext.getInjector().inject(router);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
router.initialise();
expectedException.expect(instanceOf(MuleRuntimeException.class));
router.process(CoreEvent.builder(testEvent()).message(Message.of(new StringBufferInputStream(TEST_PAYLOAD))).build());
}
use of java.io.StringBufferInputStream in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method getModelForEdit.
/**
* must release model (from edit) after
* @param filename relative to this class (TestStructuredPartitioner)
*/
private IStructuredModel getModelForEdit(String filename) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new StringBufferInputStream("");
model = modelManager.getModelForEdit(filename, inStream, null);
} catch (IOException ex) {
ex.printStackTrace();
}
return model;
}
use of java.io.StringBufferInputStream in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method doComputePartitioningTest.
/**
* Compute the partitions for the given filename using the default partitioner
* for that file type.
*
* @param filename
* @return int
* @throws IOException
* @throws BadLocationException
*/
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new StringBufferInputStream("");
IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (DEBUG_PRINT_RESULT && useFormatter) {
double baseTen = Math.log(10);
formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
formatter.setGroupingUsed(false);
}
partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
if (DEBUG_PRINT_RESULT) {
String contents = null;
System.out.println("\nfilename: " + filename);
for (int i = 0; i < partitions.length; i++) {
try {
contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
} catch (BadLocationException e) {
contents = "*error*";
}
if (useFormatter)
System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
else
System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
}
}
checkSeams();
model.releaseFromEdit();
inStream.close();
if (partitions == null)
return -1;
return partitions.length;
}
Aggregations