Question

i am using servlet to recive rquest in Struts2 for cxml punchout module, the xml document will be sent with request in stream and i had used request.getInputStream() and request.getReader() to recive but when the request hits my servlet from remote client system inputSteram.read() returns -1 , but req.getContentLength() returns length of the xml string from request object....

How can i get over from this issue...? is there any other way to carry out this process..?

note: the same servlet works in non-struts environment.......!

Was it helpful?

Solution

Solved : If you are using inputStream in srvlet to read value stream, you are not suppose to use Request.getParameter().... before getting Stream value to InputStream through req.getInputStream()...

Ex:

Correct-- method

InputStream in=req.getInputStream();
  StringBuffer xmlStr=new StringBuffer();
    int d;
    while((d=in.read()) != -1){
              xmlStr.append((char)d);
    }
    System.out.println("xmlStr1--"+xmlStr.toString());

Below method will cause ISSUE:

String str = req.getParameter("SOMETEXT");

InputStream in=req.getInputStream();
  StringBuffer xmlStr=new StringBuffer();
    int d;
    while((d=in.read()) != -1){
              xmlStr.append((char)d);
    }
    System.out.println("xmlStr1--"+xmlStr.toString());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top