package com.xceptance.xrt;

import java.net.URL;

import com.gargoylesoftware.htmlunit.WebRequest;
import com.xceptance.xlt.api.actions.AbstractLightWeightPageAction;
import com.xceptance.xlt.api.htmlunit.LightWeightPage;
import com.xceptance.xlt.engine.XltWebClient;

/**
 * This class performs the REST call as configured in the REST call instance.
 * 
 * @author Patrick Thaele
 * 
 */
public class XltRESTAction extends AbstractLightWeightPageAction
{
    /**
     * The settings for the REST call.
     */
    private final RESTCall restCall;

    /**
     * Constructor with minimum settings.
     * 
     * @param restCall
     *            The instance that provides all settings for the REST call.
     */
    public XltRESTAction( RESTCall restCall )
    {
        super( restCall.getActionName() );
        this.restCall = restCall;
    }

    /**
     * Pre-validation step before every REST call.
     * 
     * @see com.xceptance.xlt.api.actions.AbstractAction#preValidate()
     */
    @Override
    public void preValidate() throws Exception
    {
        // Nothing to pre-validate
    }

    /**
     * Makes the REST call and saves the response.
     * 
     * @see com.xceptance.xlt.api.actions.AbstractAction#execute()
     */
    @Override
    protected void execute() throws Exception
    {
        // Setup the request.
        WebRequest request = new WebRequest( new URL( restCall.getUrl() ), restCall.getHttpMethod() );
        request.setAdditionalHeaders( restCall.getHttpHeaders() );

        // Set request body.
        if ( restCall.hasRequestBody() )
            request.setRequestBody( restCall.getRequestBody() );

        // Make the call.
        LightWeightPage page = ( (XltWebClient) getWebClient() ).getLightWeightPage( request );
        setLightWeightPage( page );

        // Store the response.
        restCall.setRESTResponse( page.getWebResponse() );
    }

    /**
     * Post-validation step after every REST call.
     * 
     * @see com.xceptance.xlt.api.actions.AbstractAction#postValidate()
     */
    @Override
    protected void postValidate() throws Exception
    {
        // Nothing to post-validate

    }
}

@@ -92,16 +92,66 @@
 equest;%0A
+import com.gargoylesoftware.htmlunit.WebResponse;%0A
 import c
@@ -265,16 +265,61 @@
 htPage;%0A
+import com.xceptance.xlt.api.util.XltLogger;%0A
 import c
@@ -1394,32 +1394,580 @@
 Exception%0A    %7B%0A
+        // Call it once for debugging and execution for better performance.%0A        String url = restCall.getUrl();%0A        %0A        // DEBUGGING - log URL, HTTP method, and HTTP headers%0A        XltLogger.runTimeLogger.debug( %22Start REST call...%22 );%0A        XltLogger.runTimeLogger.debug( %22# Request - URL:%5Ct%5Ct%22 + url );%0A        XltLogger.runTimeLogger.debug( %22# Request - HTTP method:%5Ct%22 + restCall.getHttpMethod() );%0A        XltLogger.runTimeLogger.debug( %22# Request - HTTP headers:%5Ct%22 + restCall.getHttpHeaders().toString() );%0A        %0A        %0A
         // Setup
@@ -2034,33 +2034,19 @@
 ew URL( 
-restCall.getUrl()
+url
  ), rest
@@ -2219,309 +2219,1124 @@
     
+%7B%0A
     
-request.setRequestBody( restCall.getRequestBody() );%0A%0A        // Make the call.%0A        LightWeightPage page = ( (XltWebClient) getWebClient() ).getLightWeightPage( request );%0A        setLightWeightPage( page );%0A%0A        // Store the response.%0A        restCall.setRESTResponse( page.getWebResponse
+        // Call it once for debugging and execution for better performance.%0A            String requestBody = restCall.getRequestBody();%0A            %0A            // DEBUGGING - log request body%0A            XltLogger.runTimeLogger.debug( %22# Request - Body:%5Ct%22 + requestBody );%0A            %0A            request.setRequestBody( requestBody );%0A        %7D%0A%0A        // Make the call.%0A        LightWeightPage page = ( (XltWebClient) getWebClient() ).getLightWeightPage( request );%0A        setLightWeightPage( page );%0A%0A        // Store the response.%0A        WebResponse response = page.getWebResponse();%0A        restCall.setRESTResponse( response );%0A        %0A        %0A        // DEBUGGING - log response code, response HTTP headers, and response body%0A        XltLogger.runTimeLogger.debug( %22Getting response...%22 );%0A        XltLogger.runTimeLogger.debug( %22# Response - Status code:%5Ct%22 + response.getStatusCode() );%0A        XltLogger.runTimeLogger.debug( %22# Response - HTTP method:%5Ct%22 + response.getResponseHeaders().toString() );%0A        XltLogger.runTimeLogger.debug( %22# Response - Body:%5Ct%22 + response.getContentAsString
 () )

Add debug logging of the REST call.