Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:46:24+00:00 2026-06-10T19:46:24+00:00

I am getting a HttpservletRequest from client, i am trying to parse the request

  • 0

I am getting a HttpservletRequest from client, i am trying to parse the request (Using JAXB, DOM). For that i am using the following code

String str_request = IOUtils.toString(request.getInputStream());
System.out.println("String is " + str_request);
requestStream = new ByteArrayInputStream(str_request.getBytes());

My problem is, when i pass the requestStream to my parser methods, one method is working fine, but another fails. I guess there is problem with inputStream, but i could not solve this. Can any one suggest a solution for this problem.

Dom Parser Method:

public String parseMethodName(InputStream request) throws SAXException,
                                                          IOException,
                                                          ParserConfigurationException {

    System.out.println("in parseMethodName");
    DocumentBuilderFactory dbFactory =
        DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    System.out.println("bfor parse");
    Document doc = dBuilder.parse(request);
    System.out.println("After parse");
    methodName =
            doc.getElementsByTagName("methodName").item(0).getTextContent();
}

JAXB parser Method:

System.out.println("in parse ******");
JAXBContext context = JAXBContext.newInstance(MethodCall.class);
System.out.println("bfor unmarshall ****");
Unmarshaller um = context.createUnmarshaller();
System.out.println("After unmarshall ****");
mc = (MethodCall) um.unmarshal(is);

I am getting the following Exception:

javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: Premature end of file.]
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:481)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:199)
        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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:46:25+00:00Added an answer on June 10, 2026 at 7:46 pm

    You shouldn’t be converting the input stream to a String and then back to a byte array. That’s just asking to lose data, especially as you use the platform default encoding when converting a string to a byte array.

    See if whichever IOUtils class you’re using contains a method to just completely read an InputStream to a byte[], and use that as the basis for your ByteArrayInputStream.

    Note that if you want to read the data multiple times, you’ll either need to reset the stream, or create a new stream around the same byte array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following Java code for getting data from MySQL table as CSV file.
I am trying to make a Http POST request using apache HTTP client. I
I am getting the following error from my code: Attempt to split long or
I have the following code that's trying to establish a connection to a remote
Getting red warning message that expected identifier for this statement CALayer = ImageView.layer; Using
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
Getting a strange error when trying to insert data into an Access database using
I tried uploading an audio file from android client to server but I'm getting
Possible Duplicate: Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application Short version:
Getting an NumberFormat exception from a form submission that passes a phone number. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.