简体   繁体   中英

Problem cxml PunchoutSetupRequest in Struts2… while receiving request

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.......!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM