You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Nishant Gupta <ni...@alabot.com> on 2008/05/31 13:46:48 UTC

mailing list

hi,

I am Facing issues regarding posting the soap xml as a string (it was 
working fine till i was using file) in setting post.requestEntity();


PostMethod post = new PostMethod(strURL);
        // Get target URL
      
        // Request content will be retrieved directly
        // from the input stream
        String xm = "<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><AuthenticationToken
xmlns=\"http://user.mynamesspace.com\">..................................</soap:Body></soap:Envelope>";  
                             // String to be passed

        RequestEntity entity1 =  new 
StringRequestEntity(xm,"SOAPREQUEST",""); //*my error is here.* I have 
tried passing         
                                                                        
                                                                
//StringRequestEntity(content) and
                                                                        
                                                                
//StringRequestEntity(content, contenttype, charset);
       
        //RequestEntity entity = new FileRequestEntity(input, "text/xml; 
charset=ISO-8859-1");           //file was working fine earlier
        post.setRequestEntity(entity1);
         post.setRequestHeader("SOAPAction", strSoapAction);
        // Get HTTP client
        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();
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Problem POSTing soap Request as String or Stream and not as file

Posted by Oleg Kalnichevski <ol...@apache.org>.
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: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Problem POSTing soap Request as String or Stream and not as file

Posted by Nishant Gupta <ni...@alabot.com>.
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.*


sebb wrote:
> On 04/06/2008, Nishant Gupta <ni...@alabot.com> wrote:
>   
>>     
>>> hi,
>>>
>>> I am Facing issues regarding posting the soap xml as a string (it was
>>>       
>> working fine till i was using file) in setting post.requestEntity();
>>     
>>> PostMethod post = new PostMethod(strURL);
>>>       // Get target URL
>>>            // Request content will be retrieved directly
>>>       // from the input stream
>>>       String xm = "<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><AuthenticationToken
>>     
>> xmlns=\"http://user.mynamesspace.com\">..................................</soap:Body></soap:Envelope>";
>>                              // String to be passed
>>     
>>>       RequestEntity entity1 =  new
>>>       
>> StringRequestEntity(xm,"SOAPREQUEST",""); //*my error is
>> here.* I have tried passing
>>     
>
> And the error is?
>
>   
>>               //StringRequestEntity(content) and
>>     
>> //StringRequestEntity(content, contenttype, charset);
>>     
>>>             //RequestEntity entity = new FileRequestEntity(input,
>>>       
>> "text/xml; charset=ISO-8859-1");           //file was working fine earlier
>>     
>>>       post.setRequestEntity(entity1);
>>>        post.setRequestHeader("SOAPAction",
>>>       
>> strSoapAction);
>>     
>>>       // Get HTTP client
>>>       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();
>>>       }
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>>  To unsubscribe, e-mail:
>> httpclient-users-unsubscribe@hc.apache.org
>>  For additional commands, e-mail:
>> httpclient-users-help@hc.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Problem POSTing soap Request as String or Stream and not as file

Posted by sebb <se...@gmail.com>.
On 04/06/2008, Nishant Gupta <ni...@alabot.com> wrote:
>
>
> >
> > hi,
> >
> > I am Facing issues regarding posting the soap xml as a string (it was
> working fine till i was using file) in setting post.requestEntity();
> >
> >
> > PostMethod post = new PostMethod(strURL);
> >       // Get target URL
> >            // Request content will be retrieved directly
> >       // from the input stream
> >       String xm = "<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><AuthenticationToken
> >
> xmlns=\"http://user.mynamesspace.com\">..................................</soap:Body></soap:Envelope>";
>                              // String to be passed
> >
> >       RequestEntity entity1 =  new
> StringRequestEntity(xm,"SOAPREQUEST",""); //*my error is
> here.* I have tried passing

And the error is?

>               //StringRequestEntity(content) and
> >
>
> //StringRequestEntity(content, contenttype, charset);
> >             //RequestEntity entity = new FileRequestEntity(input,
> "text/xml; charset=ISO-8859-1");           //file was working fine earlier
> >       post.setRequestEntity(entity1);
> >        post.setRequestHeader("SOAPAction",
> strSoapAction);
> >       // Get HTTP client
> >       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();
> >       }
> >
> >
> >
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
>  For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Problem POSTing soap Request as String or Stream and not as file

Posted by Nishant Gupta <ni...@alabot.com>.
>
> hi,
>
> I am Facing issues regarding posting the soap xml as a string (it was 
> working fine till i was using file) in setting post.requestEntity();
>
>
> PostMethod post = new PostMethod(strURL);
>        // Get target URL
>             // Request content will be retrieved directly
>        // from the input stream
>        String xm = "<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><AuthenticationToken 
>
> xmlns=\"http://user.mynamesspace.com\">..................................</soap:Body></soap:Envelope>";  
>                             // String to be passed
>
>        RequestEntity entity1 =  new 
> StringRequestEntity(xm,"SOAPREQUEST",""); //*my error is here.* I have 
> tried passing         
>                                                                        
>                                                                
> //StringRequestEntity(content) and
>                                                                        
>                                                                
> //StringRequestEntity(content, contenttype, charset);
>              //RequestEntity entity = new FileRequestEntity(input, 
> "text/xml; charset=ISO-8859-1");           //file was working fine 
> earlier
>        post.setRequestEntity(entity1);
>         post.setRequestHeader("SOAPAction", strSoapAction);
>        // Get HTTP client
>        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();
>        }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org