Reputation: 39
I am trying to upload a multipart file to a server. However, the post request works fine when tried with Postman but returns a java exception when called using cURL
Service below returns java exception.
Code Section :
curl -X POST \
http://localhost:49901/capital/rest/v1/projects/UID4d99e5-1669f58e3f2-e6726ae9eef110442b36e368eca820c9/harnessdesigns/UID56a429-1669a3c70b3-e6726ae9eef110442b36e368eca820c9/attacheddata \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Cookie: JSESSIONID=node0rhpkec0q1a521nz49bq6c0dy93.node0' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F attachment=@/C:/Users/cabpq1/Desktop/CapitalData/ImportSpliceBundleInfoFile.json \
-F 'customdata={"attributes":{"name":"AttachedData4","type":"type1","key":"key"}}'
Response Section :
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 Server Error</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /capital/rest/v1/projects/UID4d99e5-1669f58e3f2-e6726ae9eef110442b36e368eca820c9/harnessdesigns/UID56a429-1669a3c70b3-e6726ae9eef110442b36e368eca820c9/attacheddata. Reason:
<pre> Server Error</pre></p><h3>Caused by:</h3><pre>javax.servlet.ServletException: javax.ws.rs.ProcessingException: java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30000/30000 ms
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)`enter code here`
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
Upvotes: 1
Views: 3088
Reputation: 58004
First you've used curl's -F
option that performs a multi-part form-post and yet you set a Content-Type: application/x-www-form-urlencoded
. That seems highly unlikely to be right.
Then you've set content-type:
again and this time to "multipart/form-data;" (which is default for -F
already).
Are you sure you need to fiddle with the boundary string like that? It is unusual.
You're passing on hard-coded cookie contents, which rarely is what the server side expects.
(-X POST
should not be used if you want a POST and use -d or -F)
It's a 500 response code, that's a server error that the client really shouldn't be able to trigger...
Add --trace-ascii logfile.txt
to the curl command line and you'll get to see exactly what curl sends (and receives) and then you can compare that with the working version and adjust accordingly.
Upvotes: 1
Reputation: 751
Your response clearly says timeout.
java.util.concurrent.TimeoutException: Idle timeout expired: 30000/30000 ms
In Postman check the config
Request Timeout in ms (0 for infinity): Set how long the app should wait for a response before saying that the server isn’t responding. A value of 0 indicates infinity - Postman will wait for a response forever.
Same thing can be achieved with curl , curl has two options: --connect-timeout and --max-time
From the curl man page
--connect-timeout Maximum time in seconds that you allow the connection to the server to take.
-m, --max-time Maximum time in seconds that you allow the whole operation to take.
Upvotes: 0