-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
There are still problems with this impl (some client tests ignored) and there is still a work around for the JNR bug 50, however this impl is already much better than the unix socket support that is already in the release. So will merge for now and put more effort in once there is a JNR fix. * WIP add unix domain sockets support in HttpClient * move unix socket client part to unix socket module #2014 * some cleanup #2014 * add missing headers #2014 * add TODO * UnixSocket client refactor * cleanup test and pom * minor changes, use LOG.isDebugEnabled() before using debug method * add UNIX SOCKET http client test with all other tests, push this to see what happen on Jenkins * fix some unit tests * fix more tests * fix load test * UnixSocket client * Demonstrate JNR bug * Worked around JNR bug 50 * close channel on client side as well * more details in log * log file path as well * #2014 disable test per default as doesn't work on some environement * Revert "#2014 disable test per default as doesn't work on some environement" * test only on unix * Allow test of specific transport(s) * Move unix socket to /tmp * move test socket to /tmp * move test socket to /tmp * ignore failing tests for now * fix bean name and possible to use sys prop org.eclipse.jetty.http.client.AbstractTest.Transports with mvn cli * test isBlank as surefire props is not null * correctly create tmp file with @before * do not delete file * use /tmp as build directory doesn't seem to work within docker... * do not delete sock file on client as it is own by the server * file must not exist when binding unix socket * #2014 fix license header * network specific tests assumed * Fixed to handle null selector keys * add assume for tests that assume a network connector Signed-off-by: olivier lamy <olamy@webtide.com> Signed-off-by: Greg Wilkins <gregw@webtide.com>
- Loading branch information
Showing
21 changed files
with
825 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...src/main/java/org/eclipse/jetty/unixsocket/client/HttpClientTransportOverUnixSockets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.unixsocket.client; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.SocketException; | ||
import java.nio.channels.SelectableChannel; | ||
import java.nio.channels.SelectionKey; | ||
import java.nio.channels.Selector; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.client.HttpDestination; | ||
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP; | ||
import org.eclipse.jetty.io.EndPoint; | ||
import org.eclipse.jetty.io.ManagedSelector; | ||
import org.eclipse.jetty.io.SelectorManager; | ||
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory; | ||
import org.eclipse.jetty.unixsocket.UnixSocketEndPoint; | ||
import org.eclipse.jetty.util.log.Log; | ||
import org.eclipse.jetty.util.log.Logger; | ||
|
||
import jnr.enxio.channels.NativeSelectorProvider; | ||
import jnr.unixsocket.UnixSocketAddress; | ||
import jnr.unixsocket.UnixSocketChannel; | ||
|
||
public class HttpClientTransportOverUnixSockets | ||
extends HttpClientTransportOverHTTP | ||
{ | ||
private static final Logger LOG = Log.getLogger( HttpClientTransportOverUnixSockets.class ); | ||
|
||
private String _unixSocket; | ||
private SelectorManager selectorManager; | ||
|
||
private UnixSocketChannel channel; | ||
|
||
public HttpClientTransportOverUnixSockets( String unixSocket ) | ||
{ | ||
if ( unixSocket == null ) | ||
{ | ||
throw new IllegalArgumentException( "Unix socket file cannot be null" ); | ||
} | ||
this._unixSocket = unixSocket; | ||
} | ||
|
||
@Override | ||
protected SelectorManager newSelectorManager(HttpClient client) | ||
{ | ||
return selectorManager = new UnixSocketSelectorManager(client,getSelectors()); | ||
} | ||
|
||
@Override | ||
public void connect( InetSocketAddress address, Map<String, Object> context ) | ||
{ | ||
|
||
try | ||
{ | ||
InetAddress inet = address.getAddress(); | ||
if (!inet.isLoopbackAddress() && !inet.isLinkLocalAddress() && !inet.isSiteLocalAddress()) | ||
throw new IOException("UnixSocket cannot connect to "+address.getHostString()); | ||
|
||
// Open a unix socket | ||
UnixSocketAddress unixAddress = new UnixSocketAddress( this._unixSocket ); | ||
channel = UnixSocketChannel.open( unixAddress ); | ||
|
||
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY); | ||
HttpClient client = destination.getHttpClient(); | ||
|
||
configure(client, channel); | ||
|
||
channel.configureBlocking(false); | ||
selectorManager.accept(channel, context); | ||
} | ||
// Must catch all exceptions, since some like | ||
// UnresolvedAddressException are not IOExceptions. | ||
catch (Throwable x) | ||
{ | ||
// If IPv6 is not deployed, a generic SocketException "Network is unreachable" | ||
// exception is being thrown, so we attempt to provide a better error message. | ||
if (x.getClass() == SocketException.class) | ||
x = new SocketException("Could not connect to " + address).initCause(x); | ||
|
||
try | ||
{ | ||
if (channel != null) | ||
channel.close(); | ||
} | ||
catch (IOException xx) | ||
{ | ||
LOG.ignore(xx); | ||
} | ||
finally | ||
{ | ||
connectFailed(context, x); | ||
} | ||
} | ||
} | ||
|
||
public class UnixSocketSelectorManager extends ClientSelectorManager | ||
{ | ||
protected UnixSocketSelectorManager(HttpClient client, int selectors) | ||
{ | ||
super(client,selectors); | ||
} | ||
|
||
@Override | ||
protected Selector newSelector() throws IOException | ||
{ | ||
return NativeSelectorProvider.getInstance().openSelector(); | ||
} | ||
|
||
@Override | ||
protected EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey key) | ||
{ | ||
UnixSocketEndPoint endp = new UnixSocketEndPoint((UnixSocketChannel)channel, selector, key, getScheduler()); | ||
endp.setIdleTimeout(getHttpClient().getIdleTimeout()); | ||
return endp; | ||
} | ||
} | ||
|
||
@Override | ||
protected void doStop() | ||
throws Exception | ||
{ | ||
super.doStop(); | ||
try | ||
{ | ||
if (channel != null) | ||
channel.close(); | ||
} | ||
catch (IOException xx) | ||
{ | ||
LOG.ignore(xx); | ||
} | ||
} | ||
} |
Oops, something went wrong.