ulquiorra
ulquiorra

Reputation: 945

delaying the reception of a HttpResponse

I have a client that communicates with a server that returns a response(by a servlet) after waiting four seconds and then continue processing.

The problem is that the server response (200 OK) is returned at the end of all treatment and not after the 4-second pause. I don t understand why

Here is a snippet of my code

try {
        mimeTraitement.getMime(client);
        mimeTraitement.analyseMime(xmlDir);

        if (mimeTraitement.checkMime()) {

                System.out.println("Acquittement de la requete dans " + BeanParametrageTimers.getTimeWaitResponseOkToRequest()/1000+ " secondes");
                synchronized(response)
                {
                try {
                    response.wait(BeanParametrageTimers.getTimeWaitResponseOkToRequest());
                } catch (InterruptedException e1) {

                    e1.printStackTrace();
                }
            }

            writer.write("200 OK (MimeMultipart valide)");// this line is displayed after the processing of postXml.sendXml() on my java console 
            PostXml postXml = new PostXml(xmlDir,mimeTraitement.getGetUrl());
            System.out.println("Envoi du fichier xml dans " + BeanParametrageTimers.getTimeWaitSendXmlToRequest()/1000 + " secondes");
            Thread.sleep(BeanParametrageTimers.getTimeWaitSendXmlToRequest());
            postXml.sendXml();

        } else
            writer.write("400 POK (MimeMultipart non valide)");
    } catch (MessagingException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

Thank you very much

Upvotes: 0

Views: 149

Answers (2)

jontro
jontro

Reputation: 10628

Use writer.flush() to make sure the output will not be buffered.

Upvotes: 1

Ramesh PVK
Ramesh PVK

Reputation: 15446

I think the response is getting committed because the buffer size has reached.

Find here Reasons for response getting committed

Upvotes: 0

Related Questions