Search in sources :

Example 1 with InvalidMatcherException

use of com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException in project ats-framework by Axway.

the class ActionResponseObject method resolveHttpHeaders.

@Override
protected void resolveHttpHeaders(Node actionResponse) throws XmlReaderException, InvalidMatcherException {
    Node[] expectedHeaders = xmlUtilities.getSignificantResponseHeaders(actionResponse);
    for (int iExpected = 0; iExpected < expectedHeaders.length; iExpected++) {
        String headerName = xmlUtilities.getNodeAttribute(expectedHeaders[iExpected], TOKEN_HEADER_NAME_ATTRIBUTE);
        String headerValue = xmlUtilities.getNodeAttribute(expectedHeaders[iExpected], TOKEN_HEADER_VALUE_ATTRIBUTE);
        TemplateHeaderMatchMode matchMode;
        if (headerValue.contains("${=")) {
            matchMode = TemplateHeaderMatchMode.EXTRACT;
        } else if (headerValue.contains("${")) {
            if (headerValue.startsWith("${CONTAINS=")) {
                headerValue = headerValue.substring("${CONTAINS=".length(), headerValue.length() - 1);
                matchMode = TemplateHeaderMatchMode.CONTAINS;
            } else if (headerValue.startsWith("${RANGE=")) {
                headerValue = headerValue.substring("${RANGE=".length(), headerValue.length() - 1);
                matchMode = TemplateHeaderMatchMode.RANGE;
            } else if (headerValue.startsWith("${LIST=")) {
                headerValue = headerValue.substring("${LIST=".length(), headerValue.length() - 1);
                matchMode = TemplateHeaderMatchMode.LIST;
            } else if (headerValue.startsWith("${REGEX=")) {
                headerValue = headerValue.substring("${REGEX=".length(), headerValue.length() - 1);
                matchMode = TemplateHeaderMatchMode.REGEX;
            } else if ("${RANDOM}".equals(headerValue)) {
                matchMode = TemplateHeaderMatchMode.RANDOM;
                headerValue = null;
            } else {
                // the "Location" header can contain some user parameters like ${serverUrl}
                if (headerName.equalsIgnoreCase(HeaderMatcher.LOCATION_HEADER_NAME)) {
                    // TODO: For that header again we may have variables inside.
                    // Generally cookies are automatically processed but if there is var. we should effectively use it
                    // as regex RANDOM area or replace var before whole location header match
                    matchMode = TemplateHeaderMatchMode.EQUALS;
                } else {
                    throw new InvalidMatcherException(headerValue + " contains unknown matcher key");
                }
            }
        } else {
            // when nothing is specified - we match the header value as is
            matchMode = TemplateHeaderMatchMode.EQUALS;
        }
        // we need the headers in order to construct the request
        httpHeaders.add(new ActionHeader(headerName, headerValue));
        // we need the headers matcher in order to verify the response
        httpHeaderMatchers.add(new HeaderMatcher(headerName, headerValue, matchMode));
    }
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher) Node(org.w3c.dom.Node) TemplateHeaderMatchMode(com.axway.ats.agent.core.templateactions.model.matchers.mode.TemplateHeaderMatchMode) InvalidMatcherException(com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException)

Aggregations

InvalidMatcherException (com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException)1 HeaderMatcher (com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher)1 TemplateHeaderMatchMode (com.axway.ats.agent.core.templateactions.model.matchers.mode.TemplateHeaderMatchMode)1 Node (org.w3c.dom.Node)1