Search code examples
struts2cxml-commercexml

Problem cxml PunchoutSetupRequest in Struts2... while receiving request


I am using servlet to receive request 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 receive 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.......!


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());