Search in sources :

Example 6 with DomBuilderException

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

the class CorePipeLineProcessor method processPipeLine.

public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
    // Object is the object that is passed to and returned from Pipes
    Object object = (Object) message;
    PipeRunResult pipeRunResult;
    // the PipeLineResult
    PipeLineResult pipeLineResult = new PipeLineResult();
    if (object == null || (object instanceof String && StringUtils.isEmpty(object.toString()))) {
        if (StringUtils.isNotEmpty(pipeLine.getAdapterToRunBeforeOnEmptyInput())) {
            log.debug("running adapterBeforeOnEmptyInput");
            IAdapter adapter = pipeLine.getAdapter().getConfiguration().getIbisManager().getRegisteredAdapter(pipeLine.getAdapterToRunBeforeOnEmptyInput());
            if (adapter == null) {
                log.warn("adapterToRunBefore with specified name [" + pipeLine.getAdapterToRunBeforeOnEmptyInput() + "] could not be retrieved");
            } else {
                PipeLineResult plr = adapter.processMessage(messageId, message, pipeLineSession);
                if (plr == null || !plr.getState().equals("success")) {
                    throw new PipeRunException(null, "adapterToRunBefore [" + pipeLine.getAdapterToRunBeforeOnEmptyInput() + "] ended with state [" + plr.getState() + "]");
                }
                message = plr.getResult();
                log.debug("input after running adapterBeforeOnEmptyInput [" + message + "]");
                object = (Object) message;
            }
        }
    }
    // ready indicates wether the pipeline processing is complete
    boolean ready = false;
    // get the first pipe to run
    IPipe pipeToRun = pipeLine.getPipe(pipeLine.getFirstPipe());
    boolean inputValidateError = false;
    IPipe inputValidator = pipeLine.getInputValidator();
    if (inputValidator != null) {
        log.debug("validating input");
        PipeRunResult validationResult = pipeProcessor.processPipe(pipeLine, inputValidator, messageId, message, pipeLineSession);
        if (validationResult != null) {
            if (!validationResult.getPipeForward().getName().equals("success")) {
                PipeForward validationForward = validationResult.getPipeForward();
                if (validationForward.getPath() == null) {
                    throw new PipeRunException(pipeToRun, "forward [" + validationForward.getName() + "] of inputValidator has emtpy forward path");
                }
                log.warn("setting first pipe to [" + validationForward.getPath() + "] due to validation fault");
                inputValidateError = true;
                pipeToRun = pipeLine.getPipe(validationForward.getPath());
                if (pipeToRun == null) {
                    throw new PipeRunException(pipeToRun, "forward [" + validationForward.getName() + "], path [" + validationForward.getPath() + "] does not correspond to a pipe");
                }
            }
            Object validatedMessage = validationResult.getResult();
            if (validatedMessage != null) {
                object = validatedMessage;
                message = validatedMessage.toString();
            }
        }
    }
    if (!inputValidateError) {
        IPipe inputWrapper = pipeLine.getInputWrapper();
        if (inputWrapper != null) {
            log.debug("wrapping input");
            PipeRunResult wrapResult = pipeProcessor.processPipe(pipeLine, inputWrapper, messageId, message, pipeLineSession);
            if (wrapResult != null && !wrapResult.getPipeForward().getName().equals("success")) {
                PipeForward wrapForward = wrapResult.getPipeForward();
                if (wrapForward.getPath() == null) {
                    throw new PipeRunException(pipeToRun, "forward [" + wrapForward.getName() + "] of inputWrapper has emtpy forward path");
                }
                log.warn("setting first pipe to [" + wrapForward.getPath() + "] due to wrap fault");
                pipeToRun = pipeLine.getPipe(wrapForward.getPath());
                if (pipeToRun == null) {
                    throw new PipeRunException(pipeToRun, "forward [" + wrapForward.getName() + "], path [" + wrapForward.getPath() + "] does not correspond to a pipe");
                }
            } else {
                message = wrapResult.getResult().toString();
            }
            log.debug("input after wrapping [" + message + "]");
            object = (Object) message;
        }
    }
    pipeLine.getRequestSizeStats().addValue(message.length());
    if (pipeLine.isStoreOriginalMessageWithoutNamespaces()) {
        if (XmlUtils.isWellFormed(message)) {
            String removeNamespaces_xslt = XmlUtils.makeRemoveNamespacesXslt(true, true);
            try {
                String xsltResult = null;
                Transformer transformer = XmlUtils.createTransformer(removeNamespaces_xslt);
                xsltResult = XmlUtils.transformXml(transformer, message);
                pipeLineSession.put("originalMessageWithoutNamespaces", xsltResult);
            } catch (IOException e) {
                throw new PipeRunException(pipeToRun, "cannot retrieve removeNamespaces", e);
            } catch (TransformerConfigurationException te) {
                throw new PipeRunException(pipeToRun, "got error creating transformer from removeNamespaces", te);
            } catch (TransformerException te) {
                throw new PipeRunException(pipeToRun, "got error transforming removeNamespaces", te);
            } catch (DomBuilderException te) {
                throw new PipeRunException(pipeToRun, "caught DomBuilderException", te);
            }
        } else {
            log.warn("original message is not well-formed");
            pipeLineSession.put("originalMessageWithoutNamespaces", message);
        }
    }
    boolean outputValidated = false;
    try {
        while (!ready) {
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipeToRun, messageId, object, pipeLineSession);
            object = pipeRunResult.getResult();
            if (!(pipeToRun instanceof AbstractPipe)) {
                if (object != null && object instanceof String) {
                    StatisticsKeeper sizeStat = pipeLine.getPipeSizeStatistics(pipeToRun);
                    if (sizeStat != null) {
                        sizeStat.addValue(((String) object).length());
                    }
                }
            }
            PipeForward pipeForward = pipeRunResult.getPipeForward();
            if (pipeForward == null) {
                throw new PipeRunException(pipeToRun, "Pipeline of [" + pipeLine.getOwner().getName() + "] received result from pipe [" + pipeToRun.getName() + "] without a pipeForward");
            }
            // get the next pipe to run
            String nextPath = pipeForward.getPath();
            if ((null == nextPath) || (nextPath.length() == 0)) {
                throw new PipeRunException(pipeToRun, "Pipeline of [" + pipeLine.getOwner().getName() + "] got an path that equals null or has a zero-length value from pipe [" + pipeToRun.getName() + "]. Check the configuration, probably forwards are not defined for this pipe.");
            }
            PipeLineExit plExit = pipeLine.getPipeLineExits().get(nextPath);
            if (null != plExit) {
                boolean outputWrapError = false;
                IPipe outputWrapper = pipeLine.getOutputWrapper();
                if (outputWrapper != null) {
                    log.debug("wrapping PipeLineResult");
                    PipeRunResult wrapResult = pipeProcessor.processPipe(pipeLine, outputWrapper, messageId, object, pipeLineSession);
                    if (wrapResult != null && !wrapResult.getPipeForward().getName().equals("success")) {
                        PipeForward wrapForward = wrapResult.getPipeForward();
                        if (wrapForward.getPath() == null) {
                            throw new PipeRunException(pipeToRun, "forward [" + wrapForward.getName() + "] of outputWrapper has emtpy forward path");
                        }
                        log.warn("setting next pipe to [" + wrapForward.getPath() + "] due to wrap fault");
                        outputWrapError = true;
                        pipeToRun = pipeLine.getPipe(wrapForward.getPath());
                        if (pipeToRun == null) {
                            throw new PipeRunException(pipeToRun, "forward [" + wrapForward.getName() + "], path [" + wrapForward.getPath() + "] does not correspond to a pipe");
                        }
                    } else {
                        log.debug("wrap succeeded");
                        object = wrapResult.getResult();
                    }
                    log.debug("PipeLineResult after wrapping [" + object.toString() + "]");
                }
                if (!outputWrapError) {
                    IPipe outputValidator = pipeLine.getOutputValidator();
                    if ((outputValidator != null) && !outputValidated) {
                        outputValidated = true;
                        log.debug("validating PipeLineResult");
                        PipeRunResult validationResult;
                        validationResult = pipeProcessor.processPipe(pipeLine, outputValidator, messageId, object, pipeLineSession);
                        if (validationResult != null && !validationResult.getPipeForward().getName().equals("success")) {
                            PipeForward validationForward = validationResult.getPipeForward();
                            if (validationForward.getPath() == null) {
                                throw new PipeRunException(pipeToRun, "forward [" + validationForward.getName() + "] of outputValidator has emtpy forward path");
                            }
                            log.warn("setting next pipe to [" + validationForward.getPath() + "] due to validation fault");
                            pipeToRun = pipeLine.getPipe(validationForward.getPath());
                            if (pipeToRun == null) {
                                throw new PipeRunException(pipeToRun, "forward [" + validationForward.getName() + "], path [" + validationForward.getPath() + "] does not correspond to a pipe");
                            }
                        } else {
                            log.debug("validation succeeded");
                            object = validationResult.getResult();
                            ready = true;
                        }
                    } else {
                        ready = true;
                    }
                } else {
                    ready = true;
                }
                if (ready) {
                    String state = plExit.getState();
                    pipeLineResult.setState(state);
                    pipeLineResult.setExitCode(plExit.getExitCode());
                    if (object != null && !plExit.getEmptyResult()) {
                        pipeLineResult.setResult(object.toString());
                    } else {
                        pipeLineResult.setResult(null);
                    }
                    ready = true;
                    if (log.isDebugEnabled()) {
                        // for performance reasons
                        String skString = "";
                        for (Iterator it = pipeLineSession.keySet().iterator(); it.hasNext(); ) {
                            String key = (String) it.next();
                            Object value = pipeLineSession.get(key);
                            skString = skString + "\n " + key + "=[" + value + "]";
                        }
                        log.debug("Available session keys at finishing pipeline of adapter [" + pipeLine.getOwner().getName() + "]:" + skString);
                        log.debug("Pipeline of adapter [" + pipeLine.getOwner().getName() + "] finished processing messageId [" + messageId + "] result: [" + object + "] with exit-state [" + state + "]");
                    }
                }
            } else {
                pipeToRun = pipeLine.getPipe(pipeForward.getPath());
                if (pipeToRun == null) {
                    throw new PipeRunException(null, "Pipeline of adapter [" + pipeLine.getOwner().getName() + "] got an erroneous definition. Pipe to execute [" + pipeForward.getPath() + "] is not defined.");
                }
            }
        }
    } finally {
        for (int i = 0; i < pipeLine.getExitHandlers().size(); i++) {
            IPipeLineExitHandler exitHandler = pipeLine.getExitHandlers().get(i);
            try {
                if (log.isDebugEnabled())
                    log.debug("processing ExitHandler [" + exitHandler.getName() + "]");
                exitHandler.atEndOfPipeLine(messageId, pipeLineResult, pipeLineSession);
            } catch (Throwable t) {
                log.warn("Caught Exception processing ExitHandler [" + exitHandler.getName() + "]", t);
            }
        }
    }
    return pipeLineResult;
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IPipeLineExitHandler(nl.nn.adapterframework.core.IPipeLineExitHandler) IOException(java.io.IOException) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) AbstractPipe(nl.nn.adapterframework.pipes.AbstractPipe) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Iterator(java.util.Iterator) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe) TransformerException(javax.xml.transform.TransformerException) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit)

Example 7 with DomBuilderException

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

the class ParameterValue method asCollection.

public Collection<Node> asCollection() throws ParameterException {
    if (value == null) {
        return null;
    }
    try {
        log.debug("rendering Parameter [" + getDefinition().getName() + "] value [" + value + "] as Collection");
        Element holder = XmlUtils.buildElement("<root>" + value + "</root>");
        return XmlUtils.getChildTags(holder, "*");
    } catch (DomBuilderException e) {
        throw new ParameterException("Parameter [" + getDefinition().getName() + "] cannot create Collection from [" + value + "]", e);
    }
}
Also used : Element(org.w3c.dom.Element) ParameterException(nl.nn.adapterframework.core.ParameterException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException)

Example 8 with DomBuilderException

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

the class ConfigurationUtils method getTweakedConfiguration.

public static String getTweakedConfiguration(Configuration configuration, String originalConfig, String tweakXslt, Map<String, Object> parameters) throws ConfigurationException {
    URL tweak_xsltSource = ClassUtils.getResourceURL(configuration.getClassLoader(), tweakXslt);
    if (tweak_xsltSource == null) {
        throw new ConfigurationException("cannot find resource [" + tweakXslt + "]");
    }
    try {
        Transformer tweak_transformer = XmlUtils.createTransformer(tweak_xsltSource);
        XmlUtils.setTransformerParameters(tweak_transformer, parameters);
        // jar:file: ... .jar!/xml/xsl/active.xsl; Line #34; Column #13; java.lang.NullPointerException
        return XmlUtils.transformXml(tweak_transformer, originalConfig, true);
    } catch (IOException e) {
        throw new ConfigurationException("cannot retrieve [" + tweakXslt + "]", e);
    } catch (TransformerConfigurationException tce) {
        throw new ConfigurationException("got error creating transformer from file [" + tweakXslt + "]", tce);
    } catch (TransformerException te) {
        throw new ConfigurationException("got error transforming resource [" + tweak_xsltSource.toString() + "] from [" + tweakXslt + "]", te);
    } catch (DomBuilderException de) {
        throw new ConfigurationException("caught DomBuilderException", de);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) URL(java.net.URL) TransformerException(javax.xml.transform.TransformerException)

Example 9 with DomBuilderException

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

the class TestTool method createParametersMapFromParamProperties.

/**
 * Create a Map for a specific property based on other properties that are
 * the same except for a .param1.name, .param1.value or .param1.valuefile
 * suffix.  The property with the .name suffix specifies the key for the
 * Map, the property with the value suffix specifies the value for the Map.
 * A property with a the .valuefile suffix can be used as an alternative
 * for a property with a .value suffix to specify the file to read the
 * value for the Map from. More than one param can be specified by using
 * param2, param3 etc.
 *
 * @param propertiesDirectory suffix for filenames specified by properties
 *                            with a .valuefile suffix. Can be left empty.
 * @param properties
 * @param property
 * @param writers
 * @return
 */
private static Map createParametersMapFromParamProperties(Properties properties, String property, Map writers, boolean createParameterObjects, ParameterResolutionContext parameterResolutionContext) {
    debugMessage("Search parameters for property '" + property + "'", writers);
    Map result = new HashMap();
    boolean processed = false;
    int i = 1;
    while (!processed) {
        String name = properties.getProperty(property + ".param" + i + ".name");
        if (name != null) {
            Object value;
            String type = properties.getProperty(property + ".param" + i + ".type");
            if ("httpResponse".equals(type)) {
                String outputFile;
                String filename = properties.getProperty(property + ".param" + i + ".filename");
                if (filename != null) {
                    outputFile = properties.getProperty(property + ".param" + i + ".filename.absolutepath");
                } else {
                    outputFile = properties.getProperty(property + ".param" + i + ".outputfile");
                }
                HttpServletResponseMock httpServletResponseMock = new HttpServletResponseMock();
                httpServletResponseMock.setOutputFile(outputFile);
                value = httpServletResponseMock;
            } else if ("httpRequest".equals(type)) {
                value = properties.getProperty(property + ".param" + i + ".value");
                if ("multipart".equals(value)) {
                    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
                    // following line is required to avoid
                    // "(FileUploadException) the request was rejected because
                    // no multipart boundary was found"
                    request.setContentType("multipart/mixed;boundary=gc0p4Jq0M2Yt08jU534c0p");
                    List<Part> parts = new ArrayList<Part>();
                    boolean partsProcessed = false;
                    int j = 1;
                    while (!partsProcessed) {
                        String filename = properties.getProperty(property + ".param" + i + ".part" + j + ".filename");
                        if (filename == null) {
                            partsProcessed = true;
                        } else {
                            String partFile = properties.getProperty(property + ".param" + i + ".part" + j + ".filename.absolutepath");
                            String partType = properties.getProperty(property + ".param" + i + ".part" + j + ".type");
                            String partName = properties.getProperty(property + ".param" + i + ".part" + j + ".name");
                            if ("file".equalsIgnoreCase(partType)) {
                                File file = new File(partFile);
                                try {
                                    FilePart filePart = new FilePart("file" + j, (partName == null ? file.getName() : partName), file);
                                    parts.add(filePart);
                                } catch (FileNotFoundException e) {
                                    errorMessage("Could not read file '" + partFile + "': " + e.getMessage(), e, writers);
                                }
                            } else {
                                String string = readFile(partFile, writers);
                                StringPart stringPart = new StringPart((partName == null ? "string" + j : partName), string);
                                parts.add(stringPart);
                            }
                            j++;
                        }
                    }
                    Part[] allParts = new Part[parts.size()];
                    allParts = parts.toArray(allParts);
                    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(allParts, new PostMethod().getParams());
                    ByteArrayOutputStream requestContent = new ByteArrayOutputStream();
                    try {
                        multipartRequestEntity.writeRequest(requestContent);
                    } catch (IOException e) {
                        errorMessage("Could not create multipart: " + e.getMessage(), e, writers);
                    }
                    request.setContent(requestContent.toByteArray());
                    request.setContentType(multipartRequestEntity.getContentType());
                    value = request;
                } else {
                    MockHttpServletRequest request = new MockHttpServletRequest();
                    value = request;
                }
            } else {
                value = properties.getProperty(property + ".param" + i + ".value");
                if (value == null) {
                    String filename = properties.getProperty(property + ".param" + i + ".valuefile.absolutepath");
                    if (filename != null) {
                        value = readFile(filename, writers);
                    } else {
                        String inputStreamFilename = properties.getProperty(property + ".param" + i + ".valuefileinputstream.absolutepath");
                        if (inputStreamFilename != null) {
                            try {
                                value = new FileInputStream(inputStreamFilename);
                            } catch (FileNotFoundException e) {
                                errorMessage("Could not read file '" + inputStreamFilename + "': " + e.getMessage(), e, writers);
                            }
                        }
                    }
                }
            }
            if (value != null && value instanceof String) {
                if ("node".equals(properties.getProperty(property + ".param" + i + ".type"))) {
                    try {
                        value = XmlUtils.buildNode((String) value, true);
                    } catch (DomBuilderException e) {
                        errorMessage("Could not build node for parameter '" + name + "' with value: " + value, e, writers);
                    }
                } else if ("domdoc".equals(properties.getProperty(property + ".param" + i + ".type"))) {
                    try {
                        value = XmlUtils.buildDomDocument((String) value, true);
                    } catch (DomBuilderException e) {
                        errorMessage("Could not build node for parameter '" + name + "' with value: " + value, e, writers);
                    }
                } else if ("list".equals(properties.getProperty(property + ".param" + i + ".type"))) {
                    List<String> parts = new ArrayList<String>(Arrays.asList(((String) value).split("\\s*(,\\s*)+")));
                    List list = new LinkedList<String>();
                    for (String part : parts) {
                        list.add(part);
                    }
                    value = list;
                } else if ("map".equals(properties.getProperty(property + ".param" + i + ".type"))) {
                    List<String> parts = new ArrayList<String>(Arrays.asList(((String) value).split("\\s*(,\\s*)+")));
                    Map map = new LinkedHashMap<String, String>();
                    for (String part : parts) {
                        String[] splitted = part.split("\\s*(=\\s*)+", 2);
                        if (splitted.length == 2) {
                            map.put(splitted[0], splitted[1]);
                        } else {
                            map.put(splitted[0], "");
                        }
                    }
                    value = map;
                }
            }
            if (createParameterObjects) {
                String pattern = properties.getProperty(property + ".param" + i + ".pattern");
                if (value == null && pattern == null) {
                    errorMessage("Property '" + property + ".param" + i + " doesn't have a value or pattern", writers);
                } else {
                    try {
                        Parameter parameter = new Parameter();
                        parameter.setName(name);
                        if (value != null && !(value instanceof String)) {
                            parameter.setSessionKey(name);
                            parameterResolutionContext.getSession().put(name, value);
                        } else {
                            parameter.setValue((String) value);
                            parameter.setPattern(pattern);
                        }
                        parameter.configure();
                        result.put(name, parameter);
                        debugMessage("Add param with name '" + name + "', value '" + value + "' and pattern '" + pattern + "' for property '" + property + "'", writers);
                    } catch (ConfigurationException e) {
                        errorMessage("Parameter '" + name + "' could not be configured", writers);
                    }
                }
            } else {
                if (value == null) {
                    errorMessage("Property '" + property + ".param" + i + ".value' or '" + property + ".param" + i + ".valuefile' or '" + property + ".param" + i + ".valuefileinputstream' not found while property '" + property + ".param" + i + ".name' exist", writers);
                } else {
                    result.put(name, value);
                    debugMessage("Add param with name '" + name + "' and value '" + value + "' for property '" + property + "'", writers);
                }
            }
            i++;
        } else {
            processed = true;
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PostMethod(org.apache.commons.httpclient.methods.PostMethod) FileNotFoundException(java.io.FileNotFoundException) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) ArrayList(java.util.ArrayList) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) Part(org.apache.commons.httpclient.methods.multipart.Part) Parameter(nl.nn.adapterframework.parameters.Parameter) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File)

Example 10 with DomBuilderException

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

the class JmsSender method sendMessage.

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException {
    Session s = null;
    MessageProducer mp = null;
    ParameterValueList pvl = null;
    if (prc != null && paramList != null) {
        try {
            pvl = prc.getValues(paramList);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
        }
    }
    if (isSoap()) {
        if (soapHeader == null) {
            if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
                ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
                if (soapHeaderParamValue == null) {
                    log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
                } else {
                    soapHeader = soapHeaderParamValue.asStringValue("");
                }
            }
        }
        message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader);
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
    }
    try {
        s = createSession();
        mp = getMessageProducer(s, getDestination(prc));
        Destination replyQueue = null;
        // create message
        Message msg = createTextMessage(s, correlationID, message);
        if (getMessageType() != null) {
            msg.setJMSType(getMessageType());
        }
        if (getDeliveryModeInt() > 0) {
            msg.setJMSDeliveryMode(getDeliveryModeInt());
            mp.setDeliveryMode(getDeliveryModeInt());
        }
        if (getPriority() >= 0) {
            msg.setJMSPriority(getPriority());
            mp.setPriority(getPriority());
        }
        // set properties
        if (pvl != null) {
            setProperties(msg, pvl);
        }
        if (replyToName != null) {
            replyQueue = getDestination(replyToName);
        } else {
            if (isSynchronous()) {
                replyQueue = getMessagingSource().getDynamicReplyQueue(s);
            }
        }
        if (replyQueue != null) {
            msg.setJMSReplyTo(replyQueue);
            if (log.isDebugEnabled())
                log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
        }
        // send message
        send(mp, msg);
        if (log.isDebugEnabled()) {
            log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
        } else {
            if (log.isInfoEnabled()) {
                log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : ""));
            }
        }
        if (isSynchronous()) {
            String replyCorrelationId = null;
            if (replyToName != null) {
                if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = correlationID;
                } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) {
                    replyCorrelationId = msg.getJMSCorrelationID();
                } else {
                    replyCorrelationId = msg.getJMSMessageID();
                }
            }
            if (log.isDebugEnabled())
                log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms");
            MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
            try {
                Message rawReplyMsg = mc.receive(getReplyTimeout());
                if (rawReplyMsg == null) {
                    throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms");
                }
                return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper);
            } finally {
                if (mc != null) {
                    try {
                        mc.close();
                    } catch (JMSException e) {
                        log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e);
                    }
                }
            }
        }
        return msg.getJMSMessageID();
    } catch (JMSException e) {
        throw new SenderException(e);
    } catch (IOException e) {
        throw new SenderException(e);
    } catch (NamingException e) {
        throw new SenderException(e);
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    } catch (TransformerException e) {
        throw new SenderException(e);
    } catch (JmsException e) {
        throw new SenderException(e);
    } finally {
        if (mp != null) {
            try {
                mp.close();
            } catch (JMSException e) {
                log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
            }
        }
        closeSession(s);
    }
}
Also used : Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) MessageConsumer(javax.jms.MessageConsumer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(javax.jms.Message) JMSException(javax.jms.JMSException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ParameterException(nl.nn.adapterframework.core.ParameterException) NamingException(javax.naming.NamingException) MessageProducer(javax.jms.MessageProducer) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) Session(javax.jms.Session)

Aggregations

DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 SenderException (nl.nn.adapterframework.core.SenderException)10 IOException (java.io.IOException)9 Element (org.w3c.dom.Element)9 TransformerException (javax.xml.transform.TransformerException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 ParameterException (nl.nn.adapterframework.core.ParameterException)5 Map (java.util.Map)4 Transformer (javax.xml.transform.Transformer)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)4 ParameterValue (nl.nn.adapterframework.parameters.ParameterValue)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2