Search in sources :

Example 1 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class LdapFindMemberPipe method doPipeWithException.

public PipeRunResult doPipeWithException(Object input, IPipeLineSession session) throws PipeRunException {
    String dnSearchIn_work;
    String dnFind_work;
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
        }
    }
    dnSearchIn_work = getParameterValue(pvl, "dnSearchIn");
    if (dnSearchIn_work == null) {
        dnSearchIn_work = getDnSearchIn();
    }
    dnFind_work = getParameterValue(pvl, "dnFind");
    if (dnFind_work == null) {
        dnFind_work = getDnFind();
    }
    boolean found = false;
    if (StringUtils.isNotEmpty(dnSearchIn_work) && StringUtils.isNotEmpty(dnFind_work)) {
        try {
            found = findMember(getHost(), getPort(), dnSearchIn_work, isUseSsl(), dnFind_work, isRecursiveSearch());
        } catch (NamingException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on ldap lookup", e);
        }
    }
    if (!found) {
        String msg = getLogPrefix(session) + "dn [" + dnFind_work + "] not found as member in url [" + retrieveUrl(getHost(), getPort(), dnSearchIn_work, isUseSsl()) + "]";
        if (notFoundForward == null) {
            throw new PipeRunException(this, msg);
        } else {
            log.info(msg);
            return new PipeRunResult(notFoundForward, input);
        }
    }
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) NamingException(javax.naming.NamingException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 2 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class BatchTransformerPipeBase method getReader.

protected BufferedReader getReader(String streamId, Object input, IPipeLineSession session) throws PipeRunException {
    Connection connection = null;
    try {
        connection = querySender.getConnection();
        PreparedStatement statement = null;
        String msg = (String) input;
        statement = querySender.getStatement(connection, streamId, msg, false);
        ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
        if (querySender.paramList != null) {
            querySender.applyParameters(statement, prc.getValues(querySender.paramList));
        }
        ResultSet rs = statement.executeQuery();
        if (rs == null || !rs.next()) {
            throw new SenderException("query has empty resultset");
        }
        return new ResultSetReader(connection, rs, getReader(rs, getCharset(), streamId, session));
    } catch (Exception e) {
        throw new PipeRunException(this, "cannot open reader", e);
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 3 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class ApiPrincipalPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    if (getAction().equals("get")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        return new PipeRunResult(getForward(), userPrincipal.getData());
    }
    if (getAction().equals("set")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        userPrincipal.setData((String) input);
        cache.put(userPrincipal.getToken(), userPrincipal, authTTL);
        return new PipeRunResult(getForward(), "");
    }
    if (getAction().equals("create")) {
        // TODO type of token? (jwt, saml)
        String uidString = (new UID()).toString();
        Random random = new Random();
        String token = random.nextInt() + uidString + Integer.toHexString(uidString.hashCode()) + random.nextInt(8);
        ApiPrincipal userPrincipal = new ApiPrincipal(authTTL);
        userPrincipal.setData((String) input);
        userPrincipal.setToken(token);
        if (getAuthenticationMethod().equals("cookie")) {
            Cookie cookie = new Cookie("authenticationToken", token);
            cookie.setPath("/");
            cookie.setMaxAge(authTTL);
            HttpServletResponse response = (HttpServletResponse) session.get(IPipeLineSession.HTTP_RESPONSE_KEY);
            response.addCookie(cookie);
        }
        cache.put(token, userPrincipal, authTTL);
        return new PipeRunResult(getForward(), token);
    }
    if (getAction().equals("remove")) {
        ApiPrincipal userPrincipal = (ApiPrincipal) session.get(IPipeLineSession.API_PRINCIPAL_KEY);
        if (userPrincipal == null)
            throw new PipeRunException(this, getLogPrefix(session) + "unable to locate ApiPrincipal");
        cache.remove(userPrincipal.getToken());
        return new PipeRunResult(getForward(), "");
    }
    return new PipeRunResult(findForward("exception"), "this is not supposed to happen... like ever!");
}
Also used : Cookie(javax.servlet.http.Cookie) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) UID(java.rmi.server.UID) Random(java.util.Random) PipeRunException(nl.nn.adapterframework.core.PipeRunException) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 4 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class ExecuteJdbcProperties method doPost.

private String doPost(IPipeLineSession session) throws PipeRunException {
    String action = (String) session.get("action");
    String name = (String) session.get("name");
    String value = (String) session.get("value");
    FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    String form_jmsRealm = (String) session.get("jmsRealm");
    if (StringUtils.isEmpty(name)) {
        throw new PipeRunException(this, getLogPrefix(session) + "Name should not be empty");
    }
    String result = null;
    String remoteUser = (String) session.get("principal");
    if ("insert".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("insert");
            if (StringUtils.isEmpty(remoteUser)) {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE) VALUES (?, ?, CURRENT_TIMESTAMP)");
            } else {
                qs.setQuery("INSERT INTO IBISPROP (NAME, VALUE, LASTMODDATE, LASTMODBY) VALUES (?, ?, CURRENT_TIMESTAMP, ?)");
            }
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            if (StringUtils.isNotEmpty(remoteUser)) {
                param = new Parameter();
                param.setName("lastmodby");
                param.setValue(remoteUser);
                qs.addParameter(param);
            }
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc insert query", t);
        } finally {
            qs.close();
        }
    } else if ("update".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("update");
            qs.setQuery("UPDATE IBISPROP SET VALUE=?, LASTMODDATE=CURRENT_TIMESTAMP, LASTMODBY=? WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("value");
            param.setValue(value);
            qs.addParameter(param);
            param = new Parameter();
            param.setName("lastmodby");
            if (StringUtils.isNotEmpty(remoteUser)) {
                param.setValue(remoteUser);
            }
            qs.addParameter(param);
            param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc update query", t);
        } finally {
            qs.close();
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(form_jmsRealm);
            qs.setQueryType("delete");
            qs.setQuery("DELETE IBISPROP WHERE NAME=?");
            Parameter param = new Parameter();
            param.setName("name");
            param.setValue(name);
            qs.addParameter(param);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("", session);
            result = qs.sendMessage("", "", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc delete query", t);
        } finally {
            qs.close();
        }
    } else {
        throw new PipeRunException(this, getLogPrefix(session) + "Unknown action [" + action + "]");
    }
    session.put("result", result);
    return "<dummy/>";
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 5 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException in project iaf by ibissource.

the class ShowConfig method doGet.

private String doGet(IPipeLineSession session) throws PipeRunException {
    String parm_name = (String) session.get("name");
    if (StringUtils.isEmpty(parm_name)) {
        return retrieveAllConfigs(session);
    } else {
        session.put("contentType", "application/octet-stream");
        String parm_jmsRealm = (String) session.get("jmsRealm");
        if (StringUtils.isEmpty(parm_jmsRealm)) {
            parm_jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
            if (parm_jmsRealm == null) {
                throw new PipeRunException(this, getLogPrefix(session) + "No datasource jmsRealm available");
            }
        }
        FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
        String queryResult;
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(parm_jmsRealm);
            qs.setQueryType("select");
            qs.setQuery("SELECT CONFIG FROM IBISCONFIG WHERE NAME = ? ORDER BY NAME");
            Parameter param = new Parameter();
            param.setName("name");
            param.setSessionKey("name");
            qs.addParameter(param);
            qs.setScalar(true);
            qs.setScalarExtended(true);
            qs.setBlobsCompressed(false);
            qs.setStreamResultToServlet(true);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
            queryResult = qs.sendMessage("dummy", "dummy", prc);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
        if (queryResult.length() == 0) {
        // means result is found and streamed
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "Could not retrieve configuration for name [" + parm_name + "]");
        }
        return queryResult;
    }
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5