File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes XML Request using HttpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "XML Request using HttpClient" Watch "XML Request using HttpClient" New topic
Author

XML Request using HttpClient

Yellapa Adepu
Ranch Hand

Joined: Jan 17, 2006
Posts: 34
Hi Friends,
I am trying to communicate with another application from our application based on XML request and response scenario.

Initially, I sent a XML request using HttpConnection (open connection, write a stream and flush it) and go successfull response back.. But when I tried to send the same request using HttpClient ( post method) am getting XML Malformed error message. I am guessing, will HttpClient (common's) implementation may add some kind of HTTP enevlope the XML request.
1. Is my guess correct?
2. Please explain what is happening there?? (it is working with HttpConnection but not with HttpClient)

Thanks,


Yellapa Adepu<br />SCEA
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
There's no such thing as an HTTP envelope, just an HTTP header (which may differ slightly between HTTP libraries). But that should have no impact on the HTTP body.

Is the request being received by the other side the same in both cases? It sounds like it is not, and investigating how it differs would be an important first step in tracking this down. You could write the full request stream to a file in both cases and compare them.


Ping & DNS - updated with new look and Ping home screen widget
Yellapa Adepu
Ranch Hand

Joined: Jan 17, 2006
Posts: 34
Incase of HttpClient, it is adding some escape characters in the request. That is causing the problem. Please help how to avoid this.. here is the request info..

with HttpConnection:
<?xml version="1.0" encoding="UTF-8"?> <binderRequest> <source>MyApp</source> <requestID>5555555551177436669446</requestID> <agencyAgent>5442-015</agencyAgent> <demographic> <ssn>555555555</ssn> <dob>1972-05-04</dob> <firstName>aa</firstName> <lastName>bb</lastName> <address1>asdf</address1> <address2>sdf</address2> <city>sdf</city>
</demographic> </binderRequest>.

with HttpClient:
SWEExtData=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3CbinderRequest
%3E%3Csource%3EISS%3C%2Fsource%3E%3CrequestID%3E5555555551177436670087%3C%2FrequestID%3E%3C
agencyAgent%3E5442-015%3C%2FagencyAgent%3E%3Cdemographic%3E%3Cssn%3E555555555%3C%2Fssn%3E%3C
dob%3E1972-05-04%3C%2Fdob%3E%3CfirstName%3Eaa%3C%2FfirstName%3E%3ClastName%3Ebb%3C%2FlastName%3E%3C
address1%3Easdf%3C%2Faddress1%3E%3Caddress2%3Esdf%3C%2Faddress2%3E%3Ccity%3Esdf%3C
%2Fcity%3E%2Fdemographic%3E%2FbinderRequest%3E&S WEExtSource=ProcessCBPPPayment&SWEExtCmd=Execute

It is adding %3E (something) in place of < and >

Thanks,
[ April 24, 2007: Message edited by: Ulf Dittmer ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
It looks like URL-encoding is applied to the HTTP body, which doesn't make sense. How are you using HttpClient? Can you show us the pertinent code section?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Request using HttpClient
 
Similar Threads
Can't get rid of http connection
JAXB and TCP/IP
http client + thread save conn manager + execute get request time problems
Error occured while trying to read the data from the HTTPResponse
how to submit and receive the responce of XML through java