如何转换HttpServletRequest
为String
?我需要解组,HttpServletRequest
但是当我尝试解组时,我的程序会引发异常。
javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.IOException: Stream closed]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:197)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
at com.orange.oapi.parser.XmlParsing.parse(XmlParsing.java:33)
我尝试了以下代码来解组HttpServletRequest
.
InputStreamReader is =
new InputStreamReader(request.getInputStream());
InputStream isr = request.getInputStream();
ServletInputStream req = request.getInputStream();
我的解析器方法:
public root parse(InputStreamReader is) throws Exception {
root mc = null;
try {
JAXBContext context = JAXBContext.newInstance(root.class);
Unmarshaller um = context.createUnmarshaller();
mc = (root) um.unmarshal(is);
} catch (JAXBException je) {
je.printStackTrace();
}
return mc;
}