/*
 * Copyright (c) 2011. Piraso Alvin R. de Leon. All Rights Reserved.
 *
 * See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The Piraso licenses this file to You 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 ard.piraso.api.entry;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Http request entry.
 */
public class HttpRequestEntry extends RequestEntry {
    private String uri;

    private String queryString;

    private String method;

    private String remoteAddr;

    private Map<String, String> headers;

    private Map<String, String[]> parameters;

    private List<CookieEntry> cookies;

    public HttpRequestEntry() {}

    public HttpRequestEntry(String uri) {
        super(uri);
        this.uri = uri;
    }

    public void addHeader(String name, String value) {
        if(headers == null) {
            headers = new LinkedHashMap<String, String>();
        }

        headers.put(name, value);
    }

    public void addCookie(CookieEntry cookieEntry) {
        if(cookies == null) {
            cookies = new ArrayList<CookieEntry>();
        }

        cookies.add(cookieEntry);
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(LinkedHashMap<String, String> headers) {
        this.headers = headers;
    }

    public Map<String, String[]> getParameters() {
        return parameters;
    }

    public void setParameters(LinkedHashMap<String, String[]> parameters) {
        this.parameters = parameters;
    }

    public String getQueryString() {
        return queryString;
    }

    public void setQueryString(String queryString) {
        this.queryString = queryString;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public List<CookieEntry> getCookies() {
        return cookies;
    }

    public void setCookies(List<CookieEntry> cookies) {
        this.cookies = cookies;
    }

    public String getRemoteAddr() {
        return remoteAddr;
    }

    public void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }
}

@@ -800,16 +800,61 @@
 entry;%0A%0A
+import org.apache.commons.lang.StringUtils;%0A%0A
 import j
@@ -2954,11 +2954,297 @@
 r;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        StringBuilder buf = new StringBuilder(super.toString());%0A%0A        if(StringUtils.isNotEmpty(getQueryString())) %7B%0A            buf.append(%22?%22);%0A            buf.append(getQueryString());%0A        %7D%0A%0A        return buf.toString();%0A    %7D
 %0A%7D%0A

add querystring to toString of httprequest.