Skip to content

Commit

Permalink
Merge pull request #10 from afrancis-payx/ssl
Browse files Browse the repository at this point in the history
Support HTTP requests when SSL is enabled.
  • Loading branch information
radu-gheorghe authored Mar 19, 2020
2 parents 9db9aac + 31bca79 commit e75d666
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 66 deletions.
24 changes: 18 additions & 6 deletions src/main/java/fetchers/HTTPFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,33 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

import addresses.SolrAddress;

public class HTTPFetcher {

String baseURL;

public HTTPFetcher(SolrAddress solrAddress) throws MalformedURLException {
baseURL = "http://" + solrAddress.getHost() + ":" + solrAddress.getJettyPort() + "/solr/";
Boolean ssl = false;

public HTTPFetcher(SolrAddress solrAddress, Boolean ssl) throws MalformedURLException {
this.ssl = ssl;
String proto = "http";
if (ssl) {
proto = "https";
}
baseURL = proto + "://" + solrAddress.getHost() + ":" + solrAddress.getJettyPort() + "/solr/";
}

public String get(String endpoint) throws IOException {
URL url = new URL(baseURL + endpoint);
try {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
HttpURLConnection con;
if (ssl) {
con = (HttpsURLConnection) url.openConnection();
} else {
con = (HttpURLConnection) url.openConnection();
}
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
Expand Down
43 changes: 27 additions & 16 deletions src/main/java/fetchers/SolrStuffFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public class SolrStuffFetcher {
OutputWriter writer;
public String cmdLine;
public String solrLogsSourceDir;

public SolrStuffFetcher(OutputWriter writer, String cmdLine){
this.writer = writer;
this.cmdLine = cmdLine;

}

public String getParamRegex(String regex) throws Exception {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(cmdLine);
Expand All @@ -35,11 +35,22 @@ public String getParamRegex(String regex) throws Exception {
throw new Exception("Can't find a match for " + regex);
}
}

public String getSolrHome() throws Exception {
return getParamRegex("\\-Dsolr\\.solr\\.home=(.*?) ");
}


public Boolean getSolrSSL() {
try {
if (getParamRegex("\\-Dsolr\\.jetty\\.keystore=(.*?) ").length() > 0) {
return true;
}
} catch (Exception e){
e.printStackTrace();
}
return false;
}

public void fetchSolrXML() {
String outputDir = writer.getOutputDir();
File solrHome;
Expand All @@ -57,32 +68,32 @@ public void fetchSolrXML() {
e.printStackTrace();
}
}

public void fetchGCLogs() {
String outputDir = writer.getOutputDir();
String solrLogsOutputDir = outputDir + File.separator + "logs";

Path solrLogsOutputDirHandle = Paths.get(solrLogsOutputDir);
try {
Files.createDirectory(solrLogsOutputDirHandle);
} catch (IOException e1) {
//this may be created when getting regular logs, so we'll ignore it
//System.out.println("Can't create the directory " + solrLogsOutputDir);
}

File GCLog;
try {
GCLog = new File(getParamRegex("\\-Xloggc:(.*?) "));
} catch (Exception e1) {
e1.printStackTrace();
return;
}

String GCbaseName = GCLog.getName();
File GCLogDir = GCLog.getParentFile();

File LogDir = new File(solrLogsSourceDir);

if (LogDir.getAbsolutePath().equals(GCLogDir.getAbsolutePath())) {
System.out.println("GC logs are in the same place as regular logs. Not copying them twice");
} else {
Expand All @@ -97,16 +108,16 @@ public void fetchGCLogs() {
}
}
}

public void fetchLogs() {
String outputDir = writer.getOutputDir();
String solrLogsOutputDir = outputDir + File.separator + "logs";

File solrLogsOutputDirHandle = new File(solrLogsOutputDir);
if (!solrLogsOutputDirHandle.mkdir()) {
System.out.println("Can't create output dir " + solrLogsOutputDir);
}

try {
solrLogsSourceDir = getParamRegex("\\-Dsolr\\.log\\.dir=(.*?) ");
} catch (Exception e1) {
Expand All @@ -120,7 +131,7 @@ public void fetchLogs() {
e.printStackTrace();
}
}

public String getBinSolr() {
String binSolr;
try {
Expand All @@ -132,7 +143,7 @@ public String getBinSolr() {
}
return binSolr;
}

@SuppressWarnings("unchecked")
public void getCoreConfigs(String coreStatus, String configLocalLocation) throws IOException {
JSONParser parser = new JSONParser(coreStatus);
Expand Down
Loading

0 comments on commit e75d666

Please sign in to comment.