Search in sources :

Example 11 with StringBufferInputStream

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();
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) Test(org.junit.Test)

Example 12 with StringBufferInputStream

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));
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) StringBufferInputStream(java.io.StringBufferInputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 13 with StringBufferInputStream

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());
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) StringBufferInputStream(java.io.StringBufferInputStream) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 14 with StringBufferInputStream

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;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 15 with StringBufferInputStream

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;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

StringBufferInputStream (java.io.StringBufferInputStream)34 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 SQLException (java.sql.SQLException)6 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)2 VFile (io.vertigo.dynamo.file.model.VFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Instant (java.time.Instant)2 Matchers.anyString (org.mockito.Matchers.anyString)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)2 Element (org.w3c.dom.Element)2 Table (com.mapr.db.Table)1 Description (io.qameta.allure.Description)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1