matthiasblaesing commented on code in PR #9597:
URL: https://github.com/apache/netbeans/pull/9597#discussion_r3940152399
##########
ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java:
##########
@@ -1269,10 +1269,8 @@ private Endpoint createEndpoint() throws IOException {
s.connect(new InetSocketAddress(realUrl.getHost(), port));
return Endpoint.forSocket(s);
} else if ("file".equals(realUrl.getProtocol())) {
- AFUNIXSocket s = AFUNIXSocket.newInstance();
- AFUNIXSocketAddress sockAdd = AFUNIXSocketAddress.of(new
File(realUrl.getFile()));
- s.connect(sockAdd);
- return Endpoint.forSocket(s);
+ SocketChannel channel =
SocketChannel.open(UnixDomainSocketAddress.of(Path.of(realUrl.getFile())));
+ return Endpoint.forSocket(channel.socket());
Review Comment:
This does not work. You can only query the socket of the "normal" protocols.
Unix domain sockets are not supported.
The resulting exception:
```
java.lang.UnsupportedOperationException: Not supported
at
java.base/sun.nio.ch.SocketChannelImpl.socket(SocketChannelImpl.java:235)
at
org.netbeans.modules.docker.api.DockerAction.createEndpoint(DockerAction.java:1273)
at
org.netbeans.modules.docker.api.DockerAction.pingWithExceptions(DockerAction.java:1012)
[catch] at
org.netbeans.modules.docker.ui.wizard.DockerConnectionPanel.validate(DockerConnectionPanel.java:264)
at
org.netbeans.modules.docker.ui.wizard.DockerConnectionPanel$1.run(DockerConnectionPanel.java:362)
at
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1370)
at
org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1981)
```
I tested this:
```diff
--- a/ide/docker.api/src/org/netbeans/modules/docker/Endpoint.java
+++ b/ide/docker.api/src/org/netbeans/modules/docker/Endpoint.java
@@ -23,6 +23,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.channels.Channels;
+import java.nio.channels.SocketChannel;
/**
*
@@ -53,4 +55,22 @@
};
}
+ public static Endpoint forSocketChannel(final SocketChannel channel) {
+ return new Endpoint() {
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return Channels.newInputStream(channel);
}
+
+ @Override
+ public OutputStream getOutputStream() throws IOException {
+ return Channels.newOutputStream(channel);
+ }
+
+ @Override
+ public void close() throws IOException {
+ channel.close();
+ }
+ };
+ }
+}
--- a/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java
+++ b/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java
@@ -1270,7 +1270,7 @@
return Endpoint.forSocket(s);
} else if ("file".equals(realUrl.getProtocol())) {
SocketChannel channel =
SocketChannel.open(UnixDomainSocketAddress.of(Path.of(realUrl.getFile())));
- return Endpoint.forSocket(channel.socket());
+ return Endpoint.forSocketChannel(channel);
} else {
throw new IOException("Unknown protocol: " +
realUrl.getProtocol());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists