All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xceptance.xlt.engine.XltOfflineWebConnection Maven / Gradle / Ivy

Go to download

XLT (Xceptance LoadTest) is an extensive load and performance test tool developed and maintained by Xceptance.

There is a newer version: 8.1.0
Show newest version
/*
 * Copyright (c) 2005-2022 Xceptance Software Technologies GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xceptance.xlt.engine;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpStatus;
import org.apache.http.impl.EnglishReasonPhraseCatalog;

import com.gargoylesoftware.htmlunit.WebConnection;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebResponseData;
import com.gargoylesoftware.htmlunit.util.NameValuePair;

/**
 * Class description.
 * 
 * @author Jörg Werner (Xceptance Software Technologies GmbH)
 */
public class XltOfflineWebConnection implements WebConnection
{
    /**
     * Static page fragment
     */
    private static final String SIMPLE_HTML_PAGE = "" +
                                                   " " + "" +
                                                   "   XLT-Test" + "" + "" + "   " + "" + "";

    /**
     * A faked html response
     */
    private static final byte[] HTML_RESPONSE_BODY = SIMPLE_HTML_PAGE.getBytes(StandardCharsets.UTF_8);

    /**
     * A constant for an empty header list.
     */
    private static final List HTML_RESPONSE_HEADER_LIST;

    static
    {
        HTML_RESPONSE_HEADER_LIST = new ArrayList();
        HTML_RESPONSE_HEADER_LIST.add(new NameValuePair("Content-Type", "text/html; charset=UTF-8"));
        HTML_RESPONSE_HEADER_LIST.add(new NameValuePair("Content-Length", String.valueOf(HTML_RESPONSE_BODY.length)));
        HTML_RESPONSE_HEADER_LIST.add(new NameValuePair("Cache-Control", "no-cache"));
        HTML_RESPONSE_HEADER_LIST.add(new NameValuePair("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void close() throws IOException
    {
        // nothing to do
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public WebResponse getResponse(WebRequest webRequest)
    {

        // create a dummy response data with an appropriate (?) status code
        final WebResponseData webResponseData = new WebResponseData(HTML_RESPONSE_BODY, HttpStatus.SC_OK,
                                                                    EnglishReasonPhraseCatalog.INSTANCE.getReason(HttpStatus.SC_OK, null),
                                                                    HTML_RESPONSE_HEADER_LIST);
        try
        {
            Thread.sleep(45);
        }
        catch (final InterruptedException e1)
        {
        }

        // create response using dummy data
        return new WebResponse(webResponseData, webRequest.getUrl(), webRequest.getHttpMethod(), 45);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy