On Thu, 2008-06-05 at 12:08 +0530, Nishant Gupta wrote:
> Hi sebbaz,
>
> I have been working on my error and i was quite successful in doing it
> now my code is working, *but now i want to make my own string soap
> request and passing it on in the ResponseBody() as a String or stream
> and not as a file*, The new code Snippet is as follows:
>
> static Logger log = Logger.getLogger("alabotTester.AlaMsg");
>
> public void SOAPreq()
> {
> try {
> String inp = "<soap:Envelope
> xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soap:Header><AuthenticationTokenxmlns=\"http://user.mynamesspace.com\">.................
> ...........................</soap:Body></soap:Envelope>"; *//This is My
> String SOAP Request*
>
> try {
> BufferedWriter out = new BufferedWriter(new FileWriter("name.xml"));
> out.write(inp);
> out.close();
> } catch (IOException e) {
> }
> getResp("name.xml");*// Above String is passed as a File to be
> posted, where as i want this to be posted as a string and not as
> file. *
> }
> *////Function return Response of posted XML.*
> public String getResp(String strXMLFilename) throws Exception {
> String strURL = "http://xyz.com/a/b/WebServices";
> String response ="";
>
> // Get SOAP action
> String strSoapAction = "Post";
> // Get file to be posted
> File input = new File(strXMLFilename);
> // Prepare HTTP post
> PostMethod post = new PostMethod(strURL);
> // Get target URL
> // Request content will be retrieved directly
> // from the input stream
> RequestEntity entity = new FileRequestEntity(input, "text/xml;
> charset=ISO-8859-1"); *//* *File is being posted in Request entity i
> want it
> to be
> stream or string.*
> post.setRequestEntity(entity);
> post.setRequestHeader("SOAPAction", strSoapAction);
> // Get HTTP client
> System.out.println("httpclient>>>>>>");
> HttpClient httpclient = new HttpClient();
> // Execute request
> try {
> int result = httpclient.executeMethod(post);
> response = post.getResponseBodyAsString();
> System.out.println("String
> Response"+post.getResponseBodyAsString());
> }
> finally {
> // Release current connection to the connection pool once
> you are done
> post.releaseConnection();
> }
> return response;
> }
>
> *I Basically want to know how i can pass the Soap String in post body as
> a string or stream without using file so that i can give as many users
> access as i want currently through file its not possible.*
>
Even a cursory look at the javadocs would have sufficed
http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/StringRequestEntity.html
http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/InputStreamRequestEntity.html
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]