// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/rest/ChangeId.java
// public class ChangeId {
//     private static final Logger logger = LoggerFactory.getLogger(ChangeId.class);
// 
//     private final String projectName;
//     private final String branchName;
//     private final String id;
// 
//     /**
//      * Constructor.
//      *
//      * @param projectName project name
//      * @param branchName branch name
//      * @param id id
//      */
//     public ChangeId(String projectName, String branchName, String id) {
//         this.projectName = projectName;
//         this.branchName = branchName;
//         this.id = id;
//     }
// 
//     /**
//      * Constructor getting values from a change object.
//      *
//      * @param change the change
//      * @see #ChangeId(String, String, String)
//      */
//     public ChangeId(Change change) {
//         this(change.getProject(), change.getBranch(), change.getId());
//     }
// 
//     /**
//      * As the part of the URL.
//      *
//      * @return the url part.
//      */
//     public String asUrlPart() {
//         try {
//             return encode(projectName) + "~" + encode(branchName) + "~" + id;
//         } catch (UnsupportedEncodingException e) {
//             String parameter = projectName + "~" + branchName + "~" + id;
//             logger.error("Failed to encode ChangeId {}, falling back to unencoded {}", this, parameter);
//             return parameter;
//         }
//     }
// 
//     /**
//      * Encode given String for usage in URL. UTF-8 is used as per recommendation
//      * at http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
//      * @param s String to be encoded
//      * @return Encoded string
//      * @throws UnsupportedEncodingException if UTF-8 is unsupported, handled in caller for better log message
//      */
//     private String encode(final String s) throws UnsupportedEncodingException {
//         return URLEncoder.encode(s, CharEncoding.UTF_8);
//     }
// 
//     @Override
//     public String toString() {
//         return "ChangeId{"
//                 + "projectName='" + projectName + '\''
//                 + ", branchName='" + branchName + '\''
//                 + ", id='" + id + '\''
//                 + '}';
//     }
// }
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/rest/RestConnectionConfig.java
// public interface RestConnectionConfig {
// 
//     /**
//      * Base URL for Gerrit HTTP.
//      *
//      * @return the gerrit front end URL. Always ends with '/'
//      */
//     String getGerritFrontEndUrl();
// 
//     /**
//      * The credentials to use when connecting with the REST API.
//      * For example a {@link org.apache.http.auth.UsernamePasswordCredentials}.
//      *
//      * @return the credentials to use.
//      */
//     Credentials getHttpCredentials();
// 
//     /**
//      * The http or socks5 proxy url.
//      *
//      * @return the proxy url.
//      */
//     String getGerritProxy();
// }


import com.google.gson.Gson;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.ChangeBasedEvent;
import com.sonymobile.tools.gerrit.gerritevents.dto.rest.ChangeId;
import com.sonymobile.tools.gerrit.gerritevents.dto.rest.ReviewInput;
import com.sonymobile.tools.gerrit.gerritevents.rest.RestConnectionConfig;
import org.apache.http.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
/*
 *  The MIT License
 *
 *  Copyright 2013 Jyrki Puttonen. All rights reserved.
 *  Copyright 2013 Sony Mobile Communications AB. All rights reserved.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package com.sonymobile.tools.gerrit.gerritevents.workers.rest;



/**
 * An abstract Job implementation
 * to be scheduled on {@link com.sonymobile.tools.gerrit.gerritevents.GerritSendCommandQueue}.
 *
 */
public abstract class AbstractRestCommandJob implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(AbstractRestCommandJob.class);

    /**
     * The GSON API.
     */
    private static final Gson GSON = new Gson();
    /**
     * The config.
     */
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/rest/ChangeId.java
// public class ChangeId {
//     private static final Logger logger = LoggerFactory.getLogger(ChangeId.class);
// 
//     private final String projectName;
//     private final String branchName;
//     private final String id;
// 
//     /**
//      * Constructor.
//      *
//      * @param projectName project name
//      * @param branchName branch name
//      * @param id id
//      */
//     public ChangeId(String projectName, String branchName, String id) {
//         this.projectName = projectName;
//         this.branchName = branchName;
//         this.id = id;
//     }
// 
//     /**
//      * Constructor getting values from a change object.
//      *
//      * @param change the change
//      * @see #ChangeId(String, String, String)
//      */
//     public ChangeId(Change change) {
//         this(change.getProject(), change.getBranch(), change.getId());
//     }
// 
//     /**
//      * As the part of the URL.
//      *
//      * @return the url part.
//      */
//     public String asUrlPart() {
//         try {
//             return encode(projectName) + "~" + encode(branchName) + "~" + id;
//         } catch (UnsupportedEncodingException e) {
//             String parameter = projectName + "~" + branchName + "~" + id;
//             logger.error("Failed to encode ChangeId {}, falling back to unencoded {}", this, parameter);
//             return parameter;
//         }
//     }
// 
//     /**
//      * Encode given String for usage in URL. UTF-8 is used as per recommendation
//      * at http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
//      * @param s String to be encoded
//      * @return Encoded string
//      * @throws UnsupportedEncodingException if UTF-8 is unsupported, handled in caller for better log message
//      */
//     private String encode(final String s) throws UnsupportedEncodingException {
//         return URLEncoder.encode(s, CharEncoding.UTF_8);
//     }
// 
//     @Override
//     public String toString() {
//         return "ChangeId{"
//                 + "projectName='" + projectName + '\''
//                 + ", branchName='" + branchName + '\''
//                 + ", id='" + id + '\''
//                 + '}';
//     }
// }
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/rest/RestConnectionConfig.java
// public interface RestConnectionConfig {
// 
//     /**
//      * Base URL for Gerrit HTTP.
//      *
//      * @return the gerrit front end URL. Always ends with '/'
//      */
//     String getGerritFrontEndUrl();
// 
//     /**
//      * The credentials to use when connecting with the REST API.
//      * For example a {@link org.apache.http.auth.UsernamePasswordCredentials}.
//      *
//      * @return the credentials to use.
//      */
//     Credentials getHttpCredentials();
// 
//     /**
//      * The http or socks5 proxy url.
//      *
//      * @return the proxy url.
//      */
//     String getGerritProxy();
// }


// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/workers/rest/AbstractRestCommandJob.java
import com.google.gson.Gson;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.ChangeBasedEvent;
import com.sonymobile.tools.gerrit.gerritevents.dto.rest.ChangeId;
import com.sonymobile.tools.gerrit.gerritevents.dto.rest.ReviewInput;
import com.sonymobile.tools.gerrit.gerritevents.rest.RestConnectionConfig;
import org.apache.http.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;

/*
 *  The MIT License
 *
 *  Copyright 2013 Jyrki Puttonen. All rights reserved.
 *  Copyright 2013 Sony Mobile Communications AB. All rights reserved.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package com.sonymobile.tools.gerrit.gerritevents.workers.rest;



/**
 * An abstract Job implementation
 * to be scheduled on {@link com.sonymobile.tools.gerrit.gerritevents.GerritSendCommandQueue}.
 *
 */
public abstract class AbstractRestCommandJob implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(AbstractRestCommandJob.class);

    /**
     * The GSON API.
     */
    private static final Gson GSON = new Gson();
    /**
     * The config.
     */
    private final RestConnectionConfig config;