// 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;
        HttpPost httpPost = new HttpPost(reviewEndpoint);

        String asJson = GSON.toJson(reviewInput);

        StringEntity entity = null;
        try {
            entity = new StringEntity(asJson);
        } catch (UnsupportedEncodingException e) {
            logger.error("Failed to create JSON for posting to Gerrit", e);
            if (altLogger != null) {
                altLogger.print("ERROR Failed to create JSON for posting to Gerrit: " + e.toString());
            }
            return null;
        }
        entity.setContentType("application/json");
        httpPost.setEntity(entity);
        return httpPost;
    }

    /**
     * What it says resolve Endpoint URL.
     *
     * @return the url.
     */
    private String resolveEndpointURL() {
        String gerritFrontEndUrl = config.getGerritFrontEndUrl();
        if (!gerritFrontEndUrl.endsWith("/")) {
            gerritFrontEndUrl = gerritFrontEndUrl + "/";
        }

// 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;

        HttpPost httpPost = new HttpPost(reviewEndpoint);

        String asJson = GSON.toJson(reviewInput);

        StringEntity entity = null;
        try {
            entity = new StringEntity(asJson);
        } catch (UnsupportedEncodingException e) {
            logger.error("Failed to create JSON for posting to Gerrit", e);
            if (altLogger != null) {
                altLogger.print("ERROR Failed to create JSON for posting to Gerrit: " + e.toString());
            }
            return null;
        }
        entity.setContentType("application/json");
        httpPost.setEntity(entity);
        return httpPost;
    }

    /**
     * What it says resolve Endpoint URL.
     *
     * @return the url.
     */
    private String resolveEndpointURL() {
        String gerritFrontEndUrl = config.getGerritFrontEndUrl();
        if (!gerritFrontEndUrl.endsWith("/")) {
            gerritFrontEndUrl = gerritFrontEndUrl + "/";
        }

        ChangeId changeId = new ChangeId(event.getChange().getProject(), event.getChange().getBranch(),