Search in sources :

Example 71 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class HumanTaskServerConfiguration method getAuthenticationConfig.

private void getAuthenticationConfig(File file, TRegServiceAuth authentication) {
    // Since secretResolver only accept Element we have to build Element here.
    SecretResolver secretResolver = null;
    InputStream in = null;
    try {
        in = new FileInputStream(file);
        StAXOMBuilder builder = new StAXOMBuilder(in);
        secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
    } catch (Exception e) {
        log.warn("Error occurred while retrieving secured TaskEngineProtocolHandler configuration.", e);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
    // Get Username
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS)) {
        this.registrationServiceAuthUsername = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded Registration service admin username from secure vault");
        }
    } else {
        if (authentication.getUsername() != null) {
            this.registrationServiceAuthUsername = authentication.getUsername();
        }
    }
    // Get Password
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS)) {
        this.registrationServiceAuthPassword = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded  Registration service admin password from secure vault");
        }
    } else {
        if (authentication.getPassword() != null) {
            this.registrationServiceAuthPassword = authentication.getPassword();
        }
    }
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) XmlException(org.apache.xmlbeans.XmlException)

Example 72 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-business-process by wso2.

the class ArchiveBasedHumanTaskDeploymentUnitBuilder method readInTheWSDLFile.

/**
 * Read the WSDL file given the input stream for the WSDL source
 *
 * @param in           WSDL input stream
 * @param entryName    ZIP file entry name
 * @param fromRegistry whether the wsdl is read from registry
 * @return WSDL Definition
 * @throws javax.wsdl.WSDLException at parser error
 */
public static Definition readInTheWSDLFile(InputStream in, String entryName, boolean fromRegistry) throws WSDLException {
    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
    // switch off the verbose mode for all usecases
    reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
    reader.setFeature("javax.wsdl.importDocuments", true);
    Definition def;
    Document doc;
    try {
        doc = XMLUtils.newDocument(in);
    } catch (ParserConfigurationException e) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Configuration Error", e);
    } catch (SAXException e) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "Parser SAX Error", e);
    } catch (IOException e) {
        throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error", e);
    }
    // Log when and from where the WSDL is loaded.
    if (log.isDebugEnabled()) {
        log.debug("Reading 1.1 WSDL with base uri = " + entryName);
        log.debug("  the document base uri = " + entryName);
    }
    if (fromRegistry) {
        throw new UnsupportedOperationException("This operation is not currently " + "supported in this version of WSO2 BPS.");
    } else {
        def = reader.readWSDL(entryName, doc.getDocumentElement());
    }
    def.setDocumentBaseURI(entryName);
    return def;
}
Also used : WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HumanInteractionsDocument(org.wso2.carbon.humantask.HumanInteractionsDocument) HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) Document(org.w3c.dom.Document) WSDLReader(javax.wsdl.xml.WSDLReader) SAXException(org.xml.sax.SAXException)

Example 73 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project product-iots by wso2.

the class CarbonServerManagerExtension method startServerUsingCarbonHome.

public synchronized void startServerUsingCarbonHome(String carbonHome, Map<String, String> commandMap) throws AutomationFrameworkException {
    if (this.process == null) {
        this.portOffset = this.checkPortAvailability(commandMap);
        Process tempProcess = null;
        try {
            if (!commandMap.isEmpty() && this.getPortOffsetFromCommandMap(commandMap) == 0) {
                System.setProperty("carbon.home", carbonHome);
            }
            File commandDir = new File(carbonHome);
            log.info("Starting carbon server............. ");
            String scriptName = TestFrameworkUtils.getStartupScriptFileName(carbonHome);
            String[] parameters = this.expandServerStartupCommandList(commandMap);
            String[] cmdArray;
            if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                commandDir = new File(carbonHome + File.separator + "bin");
                cmdArray = new String[] { "cmd.exe", "/c", scriptName + ".bat" };
                cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
            } else {
                cmdArray = new String[] { "sh", "bin/" + scriptName + ".sh" };
                cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
            }
            this.errorStreamHandler = new ServerLogReader("errorStream", tempProcess.getErrorStream());
            this.inputStreamHandler = new ServerLogReader("inputStream", tempProcess.getInputStream());
            this.inputStreamHandler.start();
            this.errorStreamHandler.start();
            Runtime.getRuntime().addShutdownHook(new Thread() {

                public void run() {
                    try {
                        CarbonServerManagerExtension.this.serverShutdown(CarbonServerManagerExtension.this.portOffset);
                    } catch (Exception var2) {
                        CarbonServerManagerExtension.log.error("Error while server shutdown ..", var2);
                    }
                }
            });
            ClientConnectionUtil.waitForPort(defaultHttpPort + this.portOffset, DEFAULT_START_STOP_WAIT_MS, false, (String) this.automationContext.getInstance().getHosts().get("default"));
            long time = System.currentTimeMillis() + 60000L;
            // while(true) {
            // if(this.inputStreamHandler.getOutput().contains("Mgt Console URL") || System.currentTimeMillis() >= time) {
            // int httpsPort = defaultHttpsPort + this.portOffset;
            // String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
            // User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
            // ClientConnectionUtil.waitForLogin(backendURL, superUser);
            // log.info("Server started successfully.");
            // break;
            // }
            // }
            int httpsPort = defaultHttpsPort + this.portOffset;
            String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
            User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
            ClientConnectionUtil.waitForLogin(backendURL, superUser);
        } catch (XPathExpressionException | IOException var13) {
            throw new IllegalStateException("Unable to start server", var13);
        }
        this.process = tempProcess;
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ServerLogReader(org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) File(java.io.File)

Example 74 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project product-iots by wso2.

the class QSGUtils method initConfig.

public static EMMQSGConfig initConfig() {
    Properties props = new Properties();
    InputStream input = null;
    EMMQSGConfig emmConfig = null;
    try {
        input = new FileInputStream("config.properties");
        // load a properties file and set the properties
        props.load(input);
        emmConfig = EMMQSGConfig.getInstance();
        emmConfig.setEmmHost(props.getProperty("emm-host"));
        emmConfig.setDcrEndPoint(props.getProperty("dcr-endpoint"));
        emmConfig.setOauthEndPoint(props.getProperty("oauth-endpoint"));
        emmConfig.setUsername(props.getProperty("username"));
        emmConfig.setPassword(props.getProperty("password"));
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return emmConfig;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EMMQSGConfig(org.wso2.mdm.qsg.dto.EMMQSGConfig) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 75 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project identity-test-integration by wso2-incubator.

the class SampleContextEventListener method contextInitialized.

public void contextInitialized(ServletContextEvent servletContextEvent) {
    properties = new Properties();
    try {
        if (servletContextEvent.getServletContext().getContextPath().contains("travelocity.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/travelocity.properties"));
        } else if (servletContextEvent.getServletContext().getContextPath().contains("avis.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/avis.properties"));
        } else {
            String resourcePath = "/WEB-INF/classes" + servletContextEvent.getServletContext().getContextPath() + ".properties";
            InputStream resourceStream = servletContextEvent.getServletContext().getResourceAsStream(resourcePath);
            if (resourceStream != null) {
                properties.load(servletContextEvent.getServletContext().getResourceAsStream(resourcePath));
            }
        }
        InputStream keyStoreInputStream = servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/wso2carbon.jks");
        SSOAgentX509Credential credential = new SSOAgentX509KeyStoreCredential(keyStoreInputStream, properties.getProperty("KeyStorePassword").toCharArray(), properties.getProperty("IdPPublicCertAlias"), properties.getProperty("PrivateKeyAlias"), properties.getProperty("PrivateKeyPassword").toCharArray());
        SSOAgentConfig config = new SSOAgentConfig();
        config.initConfig(properties);
        config.getSAML2().setSSOAgentX509Credential(credential);
        config.getOpenId().setAttributesRequestor(new SampleAttributesRequestor());
        servletContextEvent.getServletContext().setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SSOAgentException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}
Also used : SSOAgentConfig(org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig) InputStream(java.io.InputStream) SSOAgentX509Credential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509Credential) SSOAgentException(org.wso2.carbon.identity.sso.agent.SSOAgentException) IOException(java.io.IOException) Properties(java.util.Properties) SSOAgentX509KeyStoreCredential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509KeyStoreCredential)

Aggregations

Test (org.testng.annotations.Test)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7