How can I convert an HttpServletRequest
to String
? I need to unmarshall the HttpServletRequest
but when I try to, my program throws an exception.
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)
I tried the following code to unmarshall the HttpServletRequest
.
InputStreamReader is = new InputStreamReader(request.getInputStream()); InputStream isr = request.getInputStream(); ServletInputStream req = request.getInputStream();
My parser method:
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; }