Skip to content

Commit

Permalink
Fix java.net.URI class does not support underscore in the URI
Browse files Browse the repository at this point in the history
  • Loading branch information
malakaganga committed Dec 5, 2024
1 parent 0cff277 commit e413843
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import org.apache.http.params.HttpParams;

import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -195,13 +197,23 @@ private SSLIOSession createClientModeSSLsession(IOSession iosession, SSLContext
int port;
if (endpoint != null && !endpoint.isEmpty()) {
URI endpointURI;
URL endpointURL;
try {
endpointURI = new URI(endpoint);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid endpointURI");
}
hostname = endpointURI.getHost();
port = endpointURI.getPort();
if (hostname == null) {
try {
endpointURL = new URL(endpoint);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid endpointURL");
}
hostname = endpointURL.getHost();
port = endpointURL.getPort();
}
} else {
hostname = ((InetSocketAddress) address).getHostName();
port = ((InetSocketAddress) address).getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@
*/
package org.apache.synapse.transport.http.conn;

import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;

import org.apache.http.conn.ssl.AbstractVerifier;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.ssl.SSLSetupHandler;
import org.apache.synapse.transport.certificatevalidation.CertificateVerificationException;
import org.apache.synapse.transport.certificatevalidation.CertificateVerificationManager;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;

public class ClientSSLSetupHandler implements SSLSetupHandler {

private final static String[] LOCALHOSTS = {"::1", "127.0.0.1",
Expand Down Expand Up @@ -167,7 +170,16 @@ public void verify(IOSession iosession, SSLSession sslsession) throws SSLExcepti
if (endpoint != null && !endpoint.isEmpty()) {
try {
URI endpointURI = new URI(endpoint);
URL endpointURL;
address = endpointURI.getHost();
if (address == null) {
try {
endpointURL = new URL(endpoint);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid endpointURL");
}
address = endpointURL.getHost();
}
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid endpointURI: "+ endpoint, e);
}
Expand Down

0 comments on commit e413843

Please sign in to comment.