Search in sources :

Example 31 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class GetFromSession method doPipe.

/**
 * This is where the action takes place. Pipes may only throw a PipeRunException,
 * to be handled by the caller of this object.
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Object result = session.get(getSessionKey());
    if (result == null) {
        log.warn(getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
    } else {
        if (Parameter.TYPE_MAP.equals(getType()) && result instanceof Map) {
            Map<String, String> items = (Map<String, String>) result;
            XmlBuilder itemsXml = new XmlBuilder("items");
            for (Iterator it = items.keySet().iterator(); it.hasNext(); ) {
                String item = (String) it.next();
                XmlBuilder itemXml = new XmlBuilder("item");
                itemXml.addAttribute("name", item);
                itemXml.setValue(items.get(item));
                itemsXml.addSubElement(itemXml);
            }
            result = itemsXml.toXML();
        }
        log.debug(getLogPrefix(session) + "got [" + result.toString() + "] from pipeLineSession under key [" + getSessionKey() + "]");
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) Map(java.util.Map)

Example 32 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class HttpSender method getResponseBodyAsString.

public String getResponseBodyAsString(HttpResponseHandler responseHandler) throws IOException {
    String charset = responseHandler.getContentType();
    log.debug(getLogPrefix() + "response body uses charset [" + charset + "]");
    if ("HEAD".equals(getMethodType())) {
        XmlBuilder headersXml = new XmlBuilder("headers");
        Header[] headers = responseHandler.getAllHeaders();
        for (Header header : headers) {
            XmlBuilder headerXml = new XmlBuilder("header");
            headerXml.addAttribute("name", header.getName());
            headerXml.setCdataValue(header.getValue());
            headersXml.addSubElement(headerXml);
        }
        return headersXml.toXML();
    }
    String responseBody = responseHandler.getResponseAsString(true);
    int rbLength = responseBody.length();
    long rbSizeWarn = Misc.getResponseBodySizeWarnByDefault();
    if (rbLength >= rbSizeWarn) {
        log.warn(getLogPrefix() + "retrieved result size [" + Misc.toFileSize(rbLength) + "] exceeds [" + Misc.toFileSize(rbSizeWarn) + "]");
    }
    return responseBody;
}
Also used : Header(org.apache.http.Header) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 33 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class Adios2XmlPipe method makeXml.

/**
 * The calcbox tool Adios exports the file "NNRSCONS.PAS" = adiosDefinities in configuration attributes.
 * this file containts both "rubrieken" and "records" which together form
 * the adios message te be send to the calcbox
 * the most difficult format used is record[recordindex],label[index]:waarde;
 * mind the delimiters,where a record has or hasnot an indexnummer and a label likewise.
 */
public String makeXml(String s, IPipeLineSession session) throws PipeRunException {
    XmlBuilder bericht = new XmlBuilder("adios");
    bericht.addAttribute("type", "rekenuitvoer");
    String rekenbox = findRekenbox(session);
    if (rekenbox != null) {
        bericht.addAttribute("rekenbox", rekenbox);
    }
    StringTokenizer st1 = new StringTokenizer(s, ";\n\r");
    while (st1.hasMoreTokens()) {
        String regel = st1.nextToken();
        StringTokenizer st2 = new StringTokenizer(regel, ":");
        if (st2.hasMoreTokens()) {
            String label = st2.nextToken();
            // log.debug("label ["+label+"]");
            String waarde;
            if (regel.length() > label.length()) {
                // 'waarde' might contain colons, so nextToken() doesn't work correctly
                waarde = regel.substring(regel.indexOf(':') + 1);
            } else {
                waarde = "NVT";
            }
            waarde = waarde.trim();
            XmlBuilder rubriek = new XmlBuilder("rubriek");
            String prefix = "";
            StringTokenizer st3 = new StringTokenizer(label, ",");
            while (st3.hasMoreTokens()) {
                String item = st3.nextToken();
                if (st3.hasMoreTokens()) {
                    addItem(item, rubriek, nummer2record, prefix + "record", prefix + "recordnr", prefix + "recordindex");
                    prefix = prefix + "sub";
                } else {
                    addItem(item, rubriek, nummer2rubriek, "naam", "nummer", "index");
                }
            }
            rubriek.addAttribute("label", label);
            rubriek.addAttribute("waarde", waarde);
            bericht.addSubElement(rubriek);
        }
    }
    return bericht.toXML(true);
}
Also used : StringTokenizer(java.util.StringTokenizer) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 34 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class BisWrapperPipe method prepareResult.

private String prepareResult(String errorCode, String errorText, String serviceName, String actionName, String detailText) throws DomBuilderException, IOException, TransformerException {
    XmlBuilder resultElement = new XmlBuilder("Result");
    resultElement.addAttribute("xmlns", "http://www.ing.com/CSP/XSD/General/Message_2");
    XmlBuilder statusElement = new XmlBuilder("Status");
    if (errorCode == null) {
        statusElement.setValue("OK");
    } else {
        statusElement.setValue("ERROR");
    }
    resultElement.addSubElement(statusElement);
    if (errorCode != null) {
        XmlBuilder errorListElement = new XmlBuilder("ErrorList");
        XmlBuilder errorElement = new XmlBuilder("Error");
        XmlBuilder codeElement = new XmlBuilder("Code");
        codeElement.setValue(errorCode);
        errorElement.addSubElement(codeElement);
        XmlBuilder reasonElement = new XmlBuilder("Reason");
        reasonElement.setCdataValue(errorText);
        errorElement.addSubElement(reasonElement);
        XmlBuilder serviceElement = new XmlBuilder("Service");
        XmlBuilder serviceNameElement = new XmlBuilder("Name");
        serviceNameElement.setValue(serviceName);
        serviceElement.addSubElement(serviceNameElement);
        XmlBuilder serviceContextElement = new XmlBuilder("Context");
        serviceContextElement.setValue("1");
        serviceElement.addSubElement(serviceContextElement);
        XmlBuilder actionElement = new XmlBuilder("Action");
        XmlBuilder actionNameElement = new XmlBuilder("Name");
        actionNameElement.setValue(actionName);
        actionElement.addSubElement(actionNameElement);
        XmlBuilder actionVersionElement = new XmlBuilder("Version");
        actionVersionElement.setValue("1");
        actionElement.addSubElement(actionVersionElement);
        serviceElement.addSubElement(actionElement);
        errorElement.addSubElement(serviceElement);
        XmlBuilder detailListElement = new XmlBuilder("DetailList");
        XmlBuilder detailElement = new XmlBuilder("Detail");
        XmlBuilder detailCodeElement = new XmlBuilder("Code");
        detailElement.addSubElement(detailCodeElement);
        XmlBuilder detailTextElement = new XmlBuilder("Text");
        detailTextElement.setCdataValue(detailText);
        detailElement.addSubElement(detailTextElement);
        detailListElement.addSubElement(detailElement);
        errorElement.addSubElement(detailListElement);
        errorListElement.addSubElement(errorElement);
        resultElement.addSubElement(errorListElement);
    }
    return resultElement.toXML();
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 35 with XmlBuilder

use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.

the class XmlValidatorErrorHandler method addReason.

protected void addReason(String message, String xpath, String location) {
    if (xpath == null) {
        xpath = xmlValidatorContentHandler.getXpath();
    }
    XmlBuilder reason = new XmlBuilder("reason");
    XmlBuilder detail;
    detail = new XmlBuilder("xpath");
    detail.setValue(xpath);
    reason.addSubElement(detail);
    detail = new XmlBuilder("location");
    detail.setValue(location);
    reason.addSubElement(detail);
    detail = new XmlBuilder("message");
    detail.setValue(message);
    reason.addSubElement(detail);
    xmlReasons.addSubElement(reason);
    if (StringUtils.isNotEmpty(location)) {
        message = location + ": " + message;
    }
    message = xpath + ": " + message;
    errorOccured = true;
    if (reasons == null) {
        reasons = message;
    } else {
        reasons = reasons + "\n" + message;
    }
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Aggregations

XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)108 IOException (java.io.IOException)18 Iterator (java.util.Iterator)17 ArrayList (java.util.ArrayList)12 Date (java.util.Date)12 SenderException (nl.nn.adapterframework.core.SenderException)12 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)10 Configuration (nl.nn.adapterframework.configuration.Configuration)9 SchedulerException (org.quartz.SchedulerException)8 ServletException (javax.servlet.ServletException)7 TransformerException (javax.xml.transform.TransformerException)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)6 JmsException (nl.nn.adapterframework.jms.JmsException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Adapter (nl.nn.adapterframework.core.Adapter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Map (java.util.Map)4