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 3612362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:59:23+00:00 2026-05-18T21:59:23+00:00

I’m trying to read XML that is being pushed to my java app. I

  • 0

I’m trying to read XML that is being pushed to my java app. I originally had this in my glassfish server working. The working code in glassfish is as follows:

public class XMLPush implements Serializable
{    
public void processXML()
{
    StringBuilder sb = new StringBuilder();
    BufferedReader br = null;
    try
    {
        br = ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getReader ();
        String s = null;
        while((s = br.readLine ()) != null)
        {
            sb.append ( s );
        }
          //other code to process xml
        ...........
.............................

    }catch(Exception ex)
    {
        XMLCreator.exceptionOutput ( "processXML","Exception",ex);
    }
....
.....
}//processXML
}//class

It works perfect, but my client is unable to have glassfish on their server. I tried grabbing the raw xml from php, but I couldn’t get it to work. I decided to open up a socket and listen for the xml push manually. Here is my code for receiving the push:

public class ListenerService extends Thread
{
private BufferedReader reader = null;
private String line;
public ListenerService ( Socket connection  )thows Exception
{
        this.reader = new BufferedReader ( new InputStreamReader ( connection.getInputStream () ) );
        this.line = null;

}//ListenerService
@Override
public void run ()
{
    try
    {
        while ( (this.line = this.reader.readLine ()) != null)
        {
            System.out.println ( this.line );
                 ........

        }//while
    }      System.out.println ( ex.toString () );
        }
    } catch ( Exception ex )
    {
        ...
    }//catch
}//run

I haven’t done much socket programing, but from what I read for the past week is that passing the xml into a string is bad. What am I doing wrong and why is it that in glassfish server it works, and when I just open a socket myself it doesn’t?

this is all that I receive from the push:

PUT /?XML_EXPORT_REASON=ResponseLoop&TIMESTAMP=1292559547 HTTP/1.1
Host: ************************
Accept: */*
Content-Length: 470346
Expect: 100-continue

<?xml version="1.0" encoding="UTF-8" ?>

Where did the xml go? Is it because I am placing it in a string? I just need to grab the xml and save it into a file and then process it. Everything else works, but this.Any help would be greatly appreciated.

  • 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-18T21:59:23+00:00Added an answer on May 18, 2026 at 9:59 pm

    The first line of the XML had a line terminator (\r\n), but the rest of the XML did not. This is the reason why my threads would get stuck. I used

    BufferedReader reader;
    int i;
    while((i = reader.read()) != -1)
    

    and casted it into char:

    StringBuilder sb = new StringBuilder();
    sb.append((char)i);
    

    and stuck all the data into an xml file I created and was able to do everything correctly.

    The only thing is I had a similar problem at the end, so I had to check to see if I reached the end of the XML document. I just put the last 9 characters of the stream into an arraylist and checking it against the last part of what the XML file is supposed to end with. Works fine now, and the client (and I as well) is very happy. 🙂 Hope this helps.

    Oh one final note. I read that JDOM can actual use the input stream directly. I haven’t tested it yet, but that would be more efficient to use, if the line termination will not be a problem either. Maybe someone else has used JDOM with inputstream and has had a line termination issue?

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

Sidebar

Related Questions

No related questions found

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.