This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Services and the fly likes What is the cause of this error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "What is the cause of this error?" Watch "What is the cause of this error?" New topic
Author

What is the cause of this error?

emma smith
Ranch Hand

Joined: Nov 29, 2012
Posts: 48
hi friends,
i'm new to RESTful services,i want to call a service from my java cms but i receive a http internal error, what is it's cause?how can i accept the output from server?
this is the service:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \
http://localhost:8080/contenthub/contenthub/store
link

this is my code:


francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
port 8081 indeed 8080?
emma smith
Ranch Hand

Joined: Nov 29, 2012
Posts: 48
francesco umani wrote:port 8081 indeed 8080?

port 8081 is for apache stanbol online demo
francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
using



?
emma smith
Ranch Hand

Joined: Nov 29, 2012
Posts: 48
do you get output by using this? can you show the complete code?
thanks
francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
String input = "title=about me&content=I live in Paris.";
emma smith
Ranch Hand

Joined: Nov 29, 2012
Posts: 48
thank you Francesco but i didn't understand the cause of my code's error and the difference between my code and yours?
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

DataOutputStream used to format data in platform independent way, OutputStream sends just a raw binary data.
francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
The difference is only the parameter "title=about me&content=I live in Paris."
in the curl example you provided:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \

But In the code you used

String input = "i live in Paris";

so the request is not well formed.





surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

francesco umani wrote:
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" \
-d "title=about me&content=I live in Paris." \

So this is a URL-encoded values, which goes to POST-request body, and the service looks like a basic servlet, which accepts the attributes. Is that what OP have?
francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
yes, in fact:

application/x-www-form-urlencoded

This is the default content type. Forms submitted with this content type must be encoded as follows:

Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
The control names/values are listed in the order they appear in the document. The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

Thank you for a descriptive answer, francesco.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the cause of this error?