Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Read serwer response after 500, 400, ...  RSS feed

 
Ka Erol
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to connect to web service (REST) using Java.
Sometimes I get
Server returned HTTP response code: 500
Server returned HTTP response code: 400

When I send the same request using Chrome addon "Advanced Rest Client".

I get nice written reason:
<errors>
<error>
<code>
<![CDATA[
46
]]>
</code>
<message>
<![CDATA[
Unable to save resource
]]>
</message>
</error>
</errors>

When I try to access to the same data using Java I get an exception:

Cannot write output after reading input.

How to get access to this serwer data using Java?
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will be difficult to help if you do not post what exactly are you trying to do for example,

1) your server code
2) your client code
3) the request you are sending from Advanced Rest Client

etc

-P
 
Ka Erol
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

sure

1.
Opensource e-shop Prestashop

2.


3.
Locally installed

http://192.168.72.150/prestashop/api/currencies

======= java output ==========
java.io.IOException: Server returned HTTP response code: 500 for URL: http://192.168.72.150/prestashop/api/currencies
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1615)
at pl.com.stream.webService.PrestaService.addBase(PrestaService.java:74)
at pl.com.stream.webService.PrestaService.addBase(PrestaService.java:57)
at pl.com.stream.webService.PrestaService.putIntoShop(PrestaService.java:391)
at pl.com.stream.Run.main(Run.java:54)

======= Advanced Rest Client output ==========

Status
500 Internal Server Error

Loading time:
143
Request headers
Accept: application/xml
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22
Authorization: Basic QUQ5U1Y4OVE2UjhPNlAzTThST1JWWE5NMFFQUVBQSUw6
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.3
Cookie: 3f99a2f33f7744ef0eca694ec6b1a644=2HOS9vBgrvDyXhZ4Pl7wxqyqP0fB8K0aW2jHtf0HNrM4hQS%2FYrTiIgFz8%2Bh10UHPeDs1fjEFuQC%2BluS2kzU7%2Fg%3D%3D000059
Response headers
Date: Mon, 04 Mar 2013 07:54:07 GMT
Server: Apache/2.2.16 (Debian)
Vary: Authorization,Host,Accept-Encoding
X-Powered-By: PrestaShop Webservice
Access-Time: 1362383647
PSWS-Version: 1.5.3.1
Execution-Time: 0.013
Content-Encoding: gzip
Content-Length: 183
Connection: close
Content-Type: text/xml;charset=utf-8

Response
Copy to clipboard Save as file
<?xml version="1.0" encoding="UTF-8" ?>
<prestashop>
<errors>
<error>
<code>
<![CDATA[
46
]]>
</code>
<message>
<![CDATA[
Unable to save resource
]]>
</message>
</error>
</errors>
</prestashop>
 
Praful Thakare
Ranch Hand
Posts: 643
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well if the server is returning 500 then you should be reading from error stream and not input stream, try this code.



Also you have closed printout twice, once after writing and 2nd time after reading, remove the last close.

And always use formatter while putting code on javaranch.

-P
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!