Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,18 @@
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
* Checks if there is a latest version in central if version is not mentioned. If there is then the version of the
Expand All @@ -64,35 +58,14 @@ public class URIDryConverter extends URIConverter {
private PrintStream errStream = System.err;
private Proxy proxy;

private static TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
//No need to implement.
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
//No need to implement.
}
}
};

public URIDryConverter(URI base, Map<PackageID, Manifest> dependencyManifests) {
this(base, dependencyManifests, false);
}

public URIDryConverter(URI base, Map<PackageID, Manifest> dependencyManifests, boolean isBuild) {
super(base, dependencyManifests, isBuild);
this.base = URI.create(base.toString() + "/modules/info/");
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
proxy = getProxy();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
// ignore errors
}
proxy = getProxy();
}

public Stream<CompilerInput> finalize(URI remoteURI, PackageID moduleID) {
Expand All @@ -101,12 +74,12 @@ public Stream<CompilerInput> finalize(URI remoteURI, PackageID moduleID) {
// Ballerina.lock already.
Matcher matcher = semVerPatchPattern.matcher(moduleID.version.value);
if ("".equals(moduleID.version.value) || "*".equals(moduleID.version.value) || matcher.matches()) {
HttpURLConnection conn;
HttpsURLConnection conn;
// set proxy if exists.
if (null == this.proxy) {
conn = (HttpURLConnection) remoteURI.toURL().openConnection();
conn = (HttpsURLConnection) remoteURI.toURL().openConnection();
} else {
conn = (HttpURLConnection) remoteURI.toURL().openConnection(this.proxy);
conn = (HttpsURLConnection) remoteURI.toURL().openConnection(this.proxy);
}
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("GET");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ private void generate(GenType type, String executionPath, String definitionPath,
writeGeneratedSources(genFiles, srcPath, implPath, type);
}


/**
* Generates ballerina source for provided Open API Definition in {@code definitionPath}.
* Generated source will be written to a ballerina module at {@code outPath}
* Method can be user for generating Ballerina clients.
*
* @param executionPath Command execution path
* @param definitionPath Input Open Api Definition file path
* @param serviceName service name
* @param outPath Destination file path to save generated source files. If not provided
* {@code definitionPath} will be used as the default destination path
* @throws IOException when file operations fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -47,11 +46,12 @@
import java.time.format.DateTimeFormatter;
import java.util.Map;

import javax.net.ssl.HttpsURLConnection;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.given;
import static org.ballerinalang.cli.module.util.Utils.convertToUrl;
import static org.ballerinalang.cli.module.util.Utils.createHttpUrlConnection;
import static org.ballerinalang.cli.module.util.Utils.initializeSsl;
import static org.ballerinalang.cli.module.util.Utils.createHttpsUrlConnection;
import static org.ballerinalang.cli.module.util.Utils.setRequestMethod;
import static org.ballerinalang.test.packaging.ModulePushTestCase.REPO_TO_CENTRAL_SUCCESS_MSG;
import static org.wso2.ballerinalang.compiler.util.ProjectDirConstants.BLANG_COMPILED_PKG_BINARY_EXT;
Expand Down Expand Up @@ -182,9 +182,8 @@ public void testSearch() throws BallerinaTestException {

@Test(description = "Test pullCount of a package from central", dependsOnMethods = "testPull", enabled = false)
public void testPullCount() throws IOException {
initializeSsl();
String url = RepoUtils.getRemoteRepoURL() + "/modules/info/" + orgName + "/" + moduleName + "/*/";
HttpURLConnection conn = createHttpUrlConnection(convertToUrl(url), "", 0, "", "");
HttpsURLConnection conn = createHttpsUrlConnection(convertToUrl(url), "", 0, "", "");
conn.setInstanceFollowRedirects(false);
setRequestMethod(conn, Utils.RequestMethod.GET);

Expand Down