Java.net.SocketException: Invalid argument: create In mapped drive
Asked Answered
A

4

29

I created a Java application that sends an HTTP POST request to another server.

  • The firewall in the server is off.
  • The firewall in the PC is off.

The application works perfectly on the PC in the C drive.

The application works perfectly on the PC with a local mapping drive.

But, when I put my application in a network mapping drive, I get an error:

java.net.SocketException: Invalid argument: create in mapped drive

This is my code:

HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(getUrl());
postRequest.setHeader(AUTHERIZTION, getAuthString());

HttpResponse response = httpClient.execute(postRequest);

This is the full error:

java.net.SocketException: Invalid argument: create
    at java.net.Socket.createImpl(Unknown Source)
    at java.net.Socket.getImpl(Unknown Source)
    at java.net.Socket.setSoTimeout(Unknown Source)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:119)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at rest.RestClient.postGetQuery(RestClient.java:105)
    at frame.ScanJFrame.initProperty(ScanJFrame.java:195)
    at Main.runAction(Main.java:63)
    at Main.main(Main.java:21)

I tried this:

setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

But, nothing changed.

What can I do?

Aluminothermy answered 20/11, 2018 at 8:59 Comment(7)
There is an open bug related to your question: Socket Exception from bind to localhost if JVM installed on a shareDuhon
this may be related to network issue you can use packet tracer to identify where your error occursIseult
There appears to be a workaround for the bug that Vusal mentioned. You could test the workaround to see if the bug is related to your issue.Subsistent
Could you please write your ALL command Line to run this APPLICATION ?Schaal
//computername is a thought , file:// is also. Other subtleties with http networking include port number of the server you are calling 8080 or 80 if it is an http server, if not then it is file protocol.Haehaecceity
Lene get this straight! The "app" is the one on another drive!? If so then its original conf file probably contains "local settings" not "mapped drive settings" inside for paths! Or is there something reciprocal in how it gains it's configuration across machines?Haehaecceity
Can you share your command to run it from network drive/mapped drive?Jacksmelt
H
0

Hazard a guess, the server has no binding to a port to listen for network external machine connections in either it's own configuration files or to its machine port in its OS configuration "network settings" the external calling PC is using, that and with http it should simply be a domain http url called.

I best also point that the jdk or jre have a "jconsole" program in their /bin directories can be used to set up network connections for the binaries running the caller JVM. This appears To be the problem, your java client program needs a binding to a port to the other machine to connect to it.

If you are calling a file from another machine , use mapped drive syntax of "file://"+"//servername/afolder/file.txt" This scheme is for url's that are mapped drives.

Haehaecceity answered 25/9, 2022 at 13:2 Comment(0)
T
0

I had one Socket Exception when using Apache CXF, when it calls ClientImpl but somehow because of Proxy, it couldn't pass the value to authenticate. I started to read it directly from applicattion.properties using:

ConfigProvider.getConfig().getValue('foo.foo', string.class);
Tenth answered 8/11, 2023 at 17:3 Comment(0)
Q
0

This issue might be due to the Java not being able to create a socket on the mapped network drive.

Try running the application from a local path or using the UNC path instead of the mapped drive. Also, you can consider disabling antivirus/firewall temporarily. Not sure, if that would make any difference.

Quita answered 9/4 at 11:37 Comment(0)
J
0

There is some possibilities here:

  1. you didn't have write/delete/full access in the mapped drive: Then you can run your code for local drive and address the jar/class file in the mapped drive.

  2. You are using windows: Then you can set this item in the windows registry [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "EnableLinkedConnections"=dword:00000001

Or maybe you can simply run command from your local drive and put the complete path of class/jar file and not using mapped drive

Jacksmelt answered 10/7 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.