Search in sources :

Example 26 with XmlBuilder

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

the class NetStorageSender method extractResult.

@Override
public String extractResult(HttpResponseHandler responseHandler, ParameterResolutionContext prc) throws SenderException, IOException {
    int statusCode = responseHandler.getStatusLine().getStatusCode();
    boolean ok = false;
    if (StringUtils.isNotEmpty(getResultStatusCodeSessionKey())) {
        prc.getSession().put(getResultStatusCodeSessionKey(), Integer.toString(statusCode));
        ok = true;
    } else {
        if (statusCode == HttpServletResponse.SC_OK) {
            ok = true;
        } else {
            if (isIgnoreRedirects()) {
                if (statusCode == HttpServletResponse.SC_MOVED_PERMANENTLY || statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY || statusCode == HttpServletResponse.SC_TEMPORARY_REDIRECT) {
                    ok = true;
                }
            }
        }
    }
    if (!ok) {
        throw new SenderException(getLogPrefix() + "httpstatus " + statusCode + ": " + responseHandler.getStatusLine().getReasonPhrase() + " body: " + getResponseBodyAsString(responseHandler));
    }
    XmlBuilder result = new XmlBuilder("result");
    HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
    if (response == null) {
        XmlBuilder statuscode = new XmlBuilder("statuscode");
        statuscode.setValue(statusCode + "");
        result.addSubElement(statuscode);
        String responseString = getResponseBodyAsString(responseHandler);
        responseString = XmlUtils.skipDocTypeDeclaration(responseString.trim());
        responseString = XmlUtils.skipXmlDeclaration(responseString);
        if (statusCode == HttpURLConnection.HTTP_OK) {
            XmlBuilder message = new XmlBuilder("message");
            message.setValue(responseString, false);
            result.addSubElement(message);
        } else {
            // Validate Server-Time drift
            String dateString = responseHandler.getHeader("Date");
            if (!StringUtils.isEmpty(dateString)) {
                Date currentDate = new Date();
                DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
                long responseDate = 0;
                try {
                    Date date = format.parse(dateString);
                    responseDate = date.getTime();
                } catch (Exception e) {
                }
                if (responseDate != 0 && currentDate.getTime() - responseDate > 30 * 1000)
                    throw new SenderException("Local server Date is more than 30s out of sync with Remote server");
            }
            XmlBuilder message = new XmlBuilder("error");
            message.setValue(responseString);
            result.addSubElement(message);
            log.warn(String.format("Unexpected Response from Server: %d %s\n%s", statusCode, responseString, responseHandler.getHeaderFields()));
        }
    }
    return result.toXML();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) HttpServletResponse(javax.servlet.http.HttpServletResponse) SenderException(nl.nn.adapterframework.core.SenderException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 27 with XmlBuilder

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

the class CmisSender method sendMessageForActionGet.

private String sendMessageForActionGet(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    if (StringUtils.isEmpty(message)) {
        throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId");
    }
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(message));
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    Document document = (Document) object;
    ContentStream contentStream = document.getContentStream();
    try {
        InputStream inputStream = contentStream.getStream();
        if (isStreamResultToServlet()) {
            HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
            String contentType = contentStream.getMimeType();
            if (StringUtils.isNotEmpty(contentType)) {
                log.debug(getLogPrefix() + "setting response Content-Type header [" + contentType + "]");
                response.setHeader("Content-Type", contentType);
            }
            String contentDisposition = "attachment; filename=\"" + contentStream.getFileName() + "\"";
            log.debug(getLogPrefix() + "setting response Content-Disposition header [" + contentDisposition + "]");
            response.setHeader("Content-Disposition", contentDisposition);
            OutputStream outputStream;
            outputStream = response.getOutputStream();
            Misc.streamToStream(inputStream, outputStream);
            log.debug(getLogPrefix() + "copied document content input stream [" + inputStream + "] to output stream [" + outputStream + "]");
            return "";
        } else if (isGetProperties()) {
            if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
                prc.getSession().put(getFileInputStreamSessionKey(), inputStream);
            } else {
                byte[] bytes = Misc.streamToBytes(inputStream);
                prc.getSession().put(getFileContentSessionKey(), Base64.encodeBase64String(bytes));
            }
            XmlBuilder cmisXml = new XmlBuilder("cmis");
            XmlBuilder propertiesXml = new XmlBuilder("properties");
            for (Iterator it = document.getProperties().iterator(); it.hasNext(); ) {
                Property property = (Property) it.next();
                propertiesXml.addSubElement(getPropertyXml(property));
            }
            cmisXml.addSubElement(propertiesXml);
            return cmisXml.toXML();
        } else {
            return Misc.streamToString(inputStream, null, false);
        }
    } catch (IOException e) {
        throw new SenderException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Example 28 with XmlBuilder

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

the class CmisSender method sendMessageForActionFind.

private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "query")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<query/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
    String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
    String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
    String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
    String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(maxItems)) {
        operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
    }
    boolean sav = false;
    if (StringUtils.isNotEmpty(searchAllVersions)) {
        sav = Boolean.parseBoolean(searchAllVersions);
    }
    if (StringUtils.isNotEmpty(includeAllowableActions)) {
        operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
    }
    ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
    if (StringUtils.isNotEmpty(skipCount)) {
        long sc = Long.parseLong(skipCount);
        q = q.skipTo(sc);
    }
    if (StringUtils.isNotEmpty(maxItems)) {
        q = q.getPage();
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder rowsetXml = new XmlBuilder("rowset");
    for (QueryResult qResult : q) {
        XmlBuilder rowXml = new XmlBuilder("row");
        for (PropertyData<?> property : qResult.getProperties()) {
            rowXml.addSubElement(getPropertyXml(property));
        }
        rowsetXml.addSubElement(rowXml);
    }
    cmisXml.addSubElement(rowsetXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) Element(org.w3c.dom.Element) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 29 with XmlBuilder

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

the class CmisSender method sendMessageForActionFetch.

private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<cmis/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
    String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
    boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
    boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
    boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(filter))
        operationContext.setFilterString(filter);
    operationContext.setIncludeAllowableActions(includeAllowableActions);
    operationContext.setIncludePolicies(includePolicies);
    operationContext.setIncludeAcls(includeAcl);
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(objectIdstr), operationContext);
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder propertiesXml = new XmlBuilder("properties");
    for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
        Property property = (Property) it.next();
        propertiesXml.addSubElement(getPropertyXml(property));
    }
    cmisXml.addSubElement(propertiesXml);
    XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
    Set<Action> actions = object.getAllowableActions().getAllowableActions();
    for (Action action : actions) {
        XmlBuilder actionXml = new XmlBuilder("action");
        actionXml.setValue(action.value());
        allowableActionsXml.addSubElement(actionXml);
    }
    cmisXml.addSubElement(allowableActionsXml);
    XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
    if (object.getAcl() != null)
        isExactAclXml.setValue(object.getAcl().isExact().toString());
    cmisXml.addSubElement(isExactAclXml);
    XmlBuilder policiesXml = new XmlBuilder("policyIds");
    List<ObjectId> policies = object.getPolicyIds();
    if (policies != null) {
        for (ObjectId objectId : policies) {
            XmlBuilder policyXml = new XmlBuilder("policyId");
            policyXml.setValue(objectId.getId());
            policiesXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(policiesXml);
    XmlBuilder relationshipsXml = new XmlBuilder("relationships");
    List<Relationship> relationships = object.getRelationships();
    if (relationships != null) {
        for (Relationship relation : relationships) {
            XmlBuilder policyXml = new XmlBuilder("relation");
            policyXml.setValue(relation.getId());
            relationshipsXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(relationshipsXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) Action(org.apache.chemistry.opencmis.commons.enums.Action) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Element(org.w3c.dom.Element) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Example 30 with XmlBuilder

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

the class CreateRestViewPipe method retrieveMenuBarParameter.

private String retrieveMenuBarParameter(String srcPrefix) {
    XmlBuilder menuBar = new XmlBuilder("menuBar");
    XmlBuilder imagelinkMenu = new XmlBuilder("imagelinkMenu");
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/showConfigurationStatus", "configurationStatus", "Show Configuration Status"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/showConfiguration", "configuration", "Show Configuration"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showLogging.do", "logging", "Show Logging"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "sendJmsMessage.do", "jms-message", "Send a message with JMS"));
    if (appConstants.getBoolean("active.ifsa", false)) {
        imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/testIfsaService", "ifsa-message", "Call an IFSA Service"));
    }
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "browseQueue.do", "browsejms", "Browse a queue with JMS"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/testPipeLine", "testPipeLine", "Test a PipeLine of an Adapter"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "testService.do", "service", "Test a ServiceListener"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/webservices", "wsdl", "Webservices"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showSchedulerStatus.do", "scheduler", "Show Scheduler status"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showEnvironmentVariables.do", "properties", "Show Environment Variables"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "executeJdbcQuery.do", "execquery", "Execute a Jdbc Query"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "browseJdbcTable.do", "browsetable", "Browse a Jdbc Table"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "DumpIbisConsole", "dump", "Dump Ibis Console"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showSecurityItems.do", "security", "Show Security Items"));
    if (MonitorManager.getInstance().isEnabled()) {
        imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showMonitors.do", "monitoring", "Show Monitors"));
    }
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showIbisstoreSummary.do", "showsummary", "Show Ibisstore Summary"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "larva", "larva", "Larva Test Tool"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "testtool", "ladybug", "Ladybug Test Tool"));
    imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "javascript:void(0)", "info", "Information"));
    if (appConstants.getBoolean("console.active", false)) {
        imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "iaf/gui", "theme", "Try our new GUI 3.0 and leave feedback!"));
    }
    menuBar.addSubElement(imagelinkMenu);
    return menuBar.toXML();
}
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