Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java.net.URI class does not support underscore in the URI #2253

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading