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

  • SEARCH
  • Home
  • 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 3938944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:14:34+00:00 2026-05-20T00:14:34+00:00

I use jaxb in my REST application. I want to send an XML file

  • 0

I use jaxb in my REST application. I want to send an XML file via a web form. Then the java Class will unmarshal the InputStream.

private void unmarshal(Class<T> docClass, InputStream inputStream)
    throws JAXBException {
    String packageName = docClass.getPackage().getName();
    JAXBContext context = JAXBContext.newInstance(packageName);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    Object marshaledObject = unmarshaller.unmarshal(inputStream);
}

The jsp-File which triggers the unmarshal method has a form which looks like this:

<form action="#" method="POST">
    <label for="id">File</label>
    <input name="file" type="file" />
    <input type="submit" value="Submit" />
</form>

I get the following ParserException :

javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: Content is not allowed in prolog.].

The question was answered in general here, but i am sure that my file is not corrupt. When i call the code from within a java-Classwith the same file no exception is thrown.

// causes no exception
File file = new File("MyFile.xml");
FileInputStream fis = new FileInputStream(file);
ImportFactory importFactory = ImportFactory.getInstance();
importFactory.setMyFile(fis);

// but when i pass the file with a web form
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response create(@FormParam("file") InputStream filestream) {
    Response response;

    // is a BufferedInputStream, btw    
    LOG.debug("file is type: " + filestream.getClass().getName());

    try { 
        ImportFactory importFactory = ImportFactory.getInstance();
        importFactory.setMyFile(filestream);

        Viewable viewable = new Viewable("/sucess", null);
        ResponseBuilder responseBuilder = Response.ok(viewable);
        response = responseBuilder.build();

    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        ErrorBean errorBean = new ErrorBean(e);
        Viewable viewable = new Viewable("/error", errorBean);
        ResponseBuilder responseBuilder = Response.ok(viewable);
        response = responseBuilder.build();
    }
    return response;
}
  • 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-05-20T00:14:34+00:00Added an answer on May 20, 2026 at 12:14 am

    The content of @FormParam(“file”) InputStream filestream was file=MyFile.xml and not it’s content.

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

Sidebar

Related Questions

Is it possible to use JAXB to unmarshall xml to a specific Java class
I can use this maven plugin maven-jaxb-plugin to generate Java Classes from XSD file.
Use case: Wanna insert custom annotation to fields in java class generated by JAXB
I want to generate a xsd file dynamically, I don't want to use jaxb
I use JAXB 2 to parse an XML file against an XSD schema and
i want to pick a perticular node from an XMl file and then parse
I'm trying to use Jaxb in order to unamrshal an xml file. for some
I'm trying to use JAXB to unmarshal this file into Java objects. I know
In my Web service I use eclipse, java 1.5, spring. now I want to
I'm trying to use JAXB to pull some elements from a large XML file

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.