Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java.net.SocketException: Invalid argument: create In mapped drive

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?

like image 274
kfir Avatar asked Sep 03 '25 14:09

kfir


2 Answers

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.

like image 136
Samuel Marchant Avatar answered Sep 05 '25 02:09

Samuel Marchant


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.

like image 30
Mr. GT Avatar answered Sep 05 '25 02:09

Mr. GT