Search in sources :

Example 71 with SenderException

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

the class NetStorageSender method getMethod.

@Override
public HttpRequestBase getMethod(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
    NetStorageAction netStorageAction = new NetStorageAction(getAction());
    netStorageAction.setVersion(actionVersion);
    netStorageAction.setHashAlgorithm(hashAlgorithm);
    if (parameters != null)
        netStorageAction.mapParameters(parameters);
    try {
        URL url = uri.build().toURL();
        setMethodType(netStorageAction.getMethod());
        log.debug("opening [" + netStorageAction.getMethod() + "] connection to [" + url + "] with action [" + getAction() + "]");
        NetStorageCmsSigner signer = new NetStorageCmsSigner(url, accessTokenCf.getUsername(), accessTokenCf.getPassword(), netStorageAction, getSignType());
        Map<String, String> headers = signer.computeHeaders();
        boolean queryParametersAppended = false;
        StringBuffer path = new StringBuffer(uri.getPath());
        if (getMethodType().equals("GET")) {
            if (parameters != null) {
                queryParametersAppended = appendParameters(queryParametersAppended, path, parameters, headersParamsMap);
                log.debug(getLogPrefix() + "path after appending of parameters [" + path.toString() + "]");
            }
            HttpGet method = new HttpGet(uri.build());
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
                method.setHeader(entry.getKey(), entry.getValue());
            }
            log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
            return method;
        } else if (getMethodType().equals("PUT")) {
            HttpPut method = new HttpPut(uri.build());
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
                method.setHeader(entry.getKey(), entry.getValue());
            }
            log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
            if (netStorageAction.getFile() != null) {
                HttpEntity entity = new InputStreamEntity(netStorageAction.getFile());
                method.setEntity(entity);
            }
            return method;
        } else if (getMethodType().equals("POST")) {
            HttpPost method = new HttpPost(uri.build());
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
                method.setHeader(entry.getKey(), entry.getValue());
            }
            log.debug(getLogPrefix() + "HttpSender constructed GET-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
            if (netStorageAction.getFile() != null) {
                HttpEntity entity = new InputStreamEntity(netStorageAction.getFile());
                method.setEntity(entity);
            }
            return method;
        }
    } catch (Exception e) {
        throw new SenderException(e);
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) 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) InputStreamEntity(org.apache.http.entity.InputStreamEntity) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map)

Example 72 with SenderException

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

the class CmisHttpSender method invoke.

public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
    // Prepare the message. We will overwrite things later...
    this.headers = headers;
    int responseCode = -1;
    IPipeLineSession pls = new PipeLineSessionBase();
    pls.put("writer", writer);
    pls.put("url", url);
    ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
    try {
        sendMessageWithTimeoutGuarded(null, null, prc);
        return (Response) pls.get("response");
    } catch (Exception e) {
        throw new CmisConnectionException(getUrl(), responseCode, e);
    }
}
Also used : Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 73 with SenderException

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

the class CmisHttpSender method extractResult.

@Override
public String extractResult(HttpResponseHandler responseHandler, ParameterResolutionContext prc) throws SenderException, IOException {
    int responseCode = -1;
    try {
        StatusLine statusline = responseHandler.getStatusLine();
        responseCode = statusline.getStatusCode();
        InputStream responseStream = null;
        InputStream errorStream = null;
        Map<String, List<String>> headerFields = responseHandler.getHeaderFields();
        if (responseCode == 200 || responseCode == 201 || responseCode == 203 || responseCode == 206) {
            responseStream = responseHandler.getResponse();
        } else {
            errorStream = new ByteArrayInputStream("ERROR".getBytes());
            responseHandler.close();
        }
        Response response = new Response(responseCode, statusline.toString(), headerFields, responseStream, errorStream);
        prc.getSession().put("response", response);
    } catch (Exception e) {
        throw new CmisConnectionException(getUrl(), responseCode, e);
    }
    return "response";
}
Also used : StatusLine(org.apache.http.StatusLine) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) List(java.util.List) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 74 with SenderException

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

the class CmisSender method sendMessageForActionCreate.

private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String fileName = (String) prc.getSession().get(getFileNameSessionKey());
    InputStream inputStream = null;
    if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
        inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
    } else {
        String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
        byte[] bytes = Base64.decodeBase64((String) fileContent);
        inputStream = new ByteArrayInputStream(bytes);
    }
    long fileLength = 0;
    try {
        fileLength = inputStream.available();
    } catch (IOException e) {
        log.warn(getLogPrefix() + "could not determine file size", e);
    }
    String mediaType;
    Map props = new HashMap();
    Element cmisElement;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            cmisElement = XmlUtils.buildElement(message);
        } else {
            cmisElement = XmlUtils.buildElement("<cmis/>");
        }
        String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
        if (StringUtils.isNotEmpty(objectTypeId)) {
            props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        } else {
            props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        }
        String name = XmlUtils.getChildTagAsString(cmisElement, "name");
        if (StringUtils.isEmpty(fileName)) {
            fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
        }
        mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
        if (StringUtils.isNotEmpty(name)) {
            props.put(PropertyIds.NAME, name);
        } else if (StringUtils.isNotEmpty(fileName)) {
            props.put(PropertyIds.NAME, fileName);
        } else {
            props.put(PropertyIds.NAME, "[unknown]");
        }
        Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
        if (propertiesElement != null) {
            processProperties(propertiesElement, props);
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
    }
    if (StringUtils.isEmpty(mediaType)) {
        mediaType = getDefaultMediaType();
    }
    if (isUseRootFolder()) {
        Folder folder = session.getRootFolder();
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        Document document = folder.createDocument(props, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
        return document.getId();
    } else {
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        ObjectId objectId = session.createDocument(props, null, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
        return objectId.getId();
    }
}
Also used : HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 75 with SenderException

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

the class EsbJmsTransactionalStorage method storeMessage.

public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments, String label, Serializable message) throws SenderException {
    Session session = null;
    try {
        Map parameterValues = createParameterValues(messageId, correlationId, receivedDate, comments, label, message);
        String logRequest;
        if (getType().equalsIgnoreCase("E")) {
            log.debug(getLogPrefix() + "creating exceptionLog request");
            logRequest = exceptionLogTp.transform("<dummy/>", parameterValues, true);
        } else {
            log.debug(getLogPrefix() + "creating auditLog request");
            logRequest = auditLogTp.transform("<dummy/>", parameterValues, true);
        }
        session = createSession();
        TextMessage msg = createTextMessage(session, null, logRequest);
        String returnMessage = send(session, getDestination(), msg);
        log.debug(getLogPrefix() + "sent message [" + logRequest + "] " + "to [" + getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "]");
        return returnMessage;
    } catch (Exception e) {
        throw new SenderException(e);
    } finally {
        closeSession(session);
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) TextMessage(javax.jms.TextMessage) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) SenderException(nl.nn.adapterframework.core.SenderException) ListenerException(nl.nn.adapterframework.core.ListenerException) Session(javax.jms.Session)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9