Search in sources :

Example 76 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class SchedulerSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException {
    try {
        String correlationID = session == null ? "" : session.getMessageId();
        ParameterValueList values = paramList.getValues(message, session);
        String jobName = getName() + correlationID;
        String cronExpression = values.getParameterValue("_cronexpression").asStringValue();
        if (StringUtils.isNotEmpty(jobNamePattern)) {
            jobName = values.getParameterValue("_jobname").asStringValue();
        }
        schedule(jobName, cronExpression, correlationID, message.asString());
        return new Message(jobName);
    } catch (SenderException e) {
        throw e;
    } catch (Exception e) {
        throw new SenderException("Error during scheduling " + message, e);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SchedulerException(org.quartz.SchedulerException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 77 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class ServiceDispatcher method dispatchRequest.

/**
 * Dispatch a request.
 *
 * @since 4.3
 */
public String dispatchRequest(String serviceName, String correlationId, String request, Map<String, Object> requestContext) throws ListenerException {
    if (log.isDebugEnabled()) {
        log.debug("dispatchRequest for service [" + serviceName + "] correlationId [" + correlationId + "] message [" + request + "]");
    }
    ServiceClient client = registeredListeners.get(serviceName);
    if (client == null) {
        throw new ListenerException("service [" + serviceName + "] is not registered");
    }
    String result;
    try {
        result = client.processRequest(correlationId, new Message(request), requestContext).asString();
    } catch (IOException e) {
        throw new ListenerException(e);
    }
    if (result == null) {
        log.warn("result is null!");
    }
    return result;
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Message(nl.nn.adapterframework.stream.Message) IOException(java.io.IOException)

Example 78 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class XmlUtils method setTransformerParameters.

/**
 * sets all the parameters of the transformer using a Map with parameter values.
 * @throws IOException
 */
public static void setTransformerParameters(Transformer t, Map<String, Object> parameters) throws IOException {
    t.clearParameters();
    if (parameters == null) {
        return;
    }
    for (String paramName : parameters.keySet()) {
        Object value = parameters.get(paramName);
        if (value != null) {
            if (value instanceof Reader || value instanceof InputStream || value instanceof byte[] || value instanceof Message) {
                try {
                    value = Message.asString(value);
                } catch (IOException e) {
                    throw new IOException("Cannot get value of parameter [" + paramName + "]", e);
                }
            }
            t.setParameter(paramName, value);
            log.debug("setting parameter [" + paramName + "] on transformer from class [" + value.getClass().getTypeName() + "]");
        } else {
            log.info("omitting setting of parameter [" + paramName + "] on transformer, as it has a null-value");
        }
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) InputStream(java.io.InputStream) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 79 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class ExecuteJdbcQuery method execute.

@POST
@RolesAllowed({ "IbisTester" })
@Path("/jdbc/query")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response execute(LinkedHashMap<String, Object> json) throws ApiException {
    String datasource = null, resultType = null, query = null, queryType = null, result = "", returnType = MediaType.APPLICATION_XML;
    boolean avoidLocking = false, trimSpaces = false;
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("datasource")) {
            datasource = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("resultType")) {
            resultType = entry.getValue().toString().toLowerCase();
            if (resultType.equalsIgnoreCase("csv")) {
                returnType = MediaType.TEXT_PLAIN;
            }
            if (resultType.equalsIgnoreCase("json")) {
                returnType = MediaType.APPLICATION_JSON;
            }
        }
        if (key.equalsIgnoreCase("avoidLocking")) {
            avoidLocking = Boolean.parseBoolean(entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("trimSpaces")) {
            trimSpaces = Boolean.parseBoolean(entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("query")) {
            query = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("queryType")) {
            queryType = entry.getValue().toString();
        }
    }
    if ("AUTO".equals(queryType)) {
        // defaults to other
        queryType = "other";
        // if it matches, set it to select
        String[] commands = new String[] { "select", "show" };
        for (String command : commands) {
            if (query.toLowerCase().startsWith(command)) {
                queryType = "select";
                break;
            }
        }
    }
    if (datasource == null || resultType == null || query == null) {
        throw new ApiException("Missing data, datasource, resultType and query are expected.", 400);
    }
    secLog.info(String.format("executing query [%s] on datasource [%s] queryType [%s] avoidLocking [%s]", query, datasource, queryType, avoidLocking));
    // We have all info we need, lets execute the query!
    DirectQuerySender qs;
    try {
        qs = (DirectQuerySender) getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
    } catch (Exception e) {
        throw new ApiException("An error occured on creating or closing the connection", e);
    }
    try {
        qs.setName("QuerySender");
        qs.setDatasourceName(datasource);
        qs.setQueryType(queryType);
        qs.setTrimSpaces(trimSpaces);
        qs.setAvoidLocking(avoidLocking);
        qs.setBlobSmartGet(true);
        qs.setPrettyPrint(true);
        qs.configure(true);
        qs.open();
        Message message = qs.sendMessage(new Message(query), null);
        if (resultType.equalsIgnoreCase("csv")) {
            AbstractQueryOutputTransformer filter = new QueryOutputToCSV();
            result = filter.parse(message);
        } else if (resultType.equalsIgnoreCase("json")) {
            AbstractQueryOutputTransformer filter = new QueryOutputToJson();
            result = filter.parse(message);
        } else {
            result = message.asString();
        }
    } catch (Throwable t) {
        throw new ApiException("Error executing query", t);
    } finally {
        qs.close();
    }
    return Response.status(Response.Status.CREATED).type(returnType).entity(result).build();
}
Also used : QueryOutputToJson(nl.nn.adapterframework.jdbc.transformer.QueryOutputToJson) Message(nl.nn.adapterframework.stream.Message) QueryOutputToCSV(nl.nn.adapterframework.jdbc.transformer.QueryOutputToCSV) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) AbstractQueryOutputTransformer(nl.nn.adapterframework.jdbc.transformer.AbstractQueryOutputTransformer) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 80 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class SlotIdRecord method execute.

@POST
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/jdbc/summary")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response execute(LinkedHashMap<String, Object> json) throws ApiException {
    // PUT defaults to no content
    Response.ResponseBuilder response = Response.noContent();
    String query = null;
    String datasource = null;
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("datasource")) {
            datasource = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("query")) {
            query = entry.getValue().toString();
        }
    }
    if (datasource == null)
        return response.status(Response.Status.BAD_REQUEST).build();
    String result = "";
    try {
        IbisstoreSummaryQuerySender qs;
        qs = (IbisstoreSummaryQuerySender) getIbisContext().createBeanAutowireByName(IbisstoreSummaryQuerySender.class);
        qs.setSlotmap(getSlotmap());
        try {
            qs.setName("QuerySender");
            qs.setDatasourceName(datasource);
            qs.setQueryType("select");
            qs.setBlobSmartGet(true);
            qs.setAvoidLocking(true);
            qs.configure(true);
            qs.open();
            result = qs.sendMessage(new Message(query != null ? query : qs.getDbmsSupport().getIbisStoreSummaryQuery()), null).asString();
        } catch (Throwable t) {
            throw new ApiException("An error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
    } catch (Exception e) {
        throw new ApiException("An error occured on creating or closing the connection", e);
    }
    String resultObject = "{ \"result\":" + result + "}";
    return Response.status(Response.Status.CREATED).entity(resultObject).build();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Message(nl.nn.adapterframework.stream.Message) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Message (nl.nn.adapterframework.stream.Message)598 Test (org.junit.Test)385 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)220 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)114 IOException (java.io.IOException)112 SenderException (nl.nn.adapterframework.core.SenderException)97 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)54 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)54 Parameter (nl.nn.adapterframework.parameters.Parameter)52 PipeForward (nl.nn.adapterframework.core.PipeForward)41 Date (java.util.Date)37 TimeoutException (nl.nn.adapterframework.core.TimeoutException)31 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)31 PipeRunException (nl.nn.adapterframework.core.PipeRunException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)29 InputStream (java.io.InputStream)29 ParameterList (nl.nn.adapterframework.parameters.ParameterList)28 ListenerException (nl.nn.adapterframework.core.ListenerException)27 ParameterException (nl.nn.adapterframework.core.ParameterException)25 SAXException (org.xml.sax.SAXException)19