You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Steffen Pingel (JIRA)" <ji...@apache.org> on 2007/05/14 20:27:16 UTC

[jira] Created: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Add notification to NHttpServiceHandler when response has been sent
-------------------------------------------------------------------

                 Key: HTTPCORE-73
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
             Project: HttpComponents Core
          Issue Type: Improvement
          Components: HttpCore NIO
    Affects Versions: 4.0-alpha5
            Reporter: Steffen Pingel


Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent:

 void responseSubmitted(NHttpServerConnection conn);

The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers.

Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Steffen Pingel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496122 ] 

Steffen Pingel commented on HTTPCORE-73:
----------------------------------------

Oleg, thanks a lot for your comments! Managing the response in the service handler and using the responseReady() event makes perfect sense. I'll implement it as suggested and let you know how that turned out tomorrow.

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Steffen Pingel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496109 ] 

Steffen Pingel commented on HTTPCORE-73:
----------------------------------------

I need access to the HttpResponse object in order to map the event correctly. 

The event is useful to get feedback when a response has actually been sent to the channel. In my case I use it to mark the transfer in the UI as complete, to switch throttling and to measure bandwidth.

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496104 ] 

Oleg Kalnichevski commented on HTTPCORE-73:
-------------------------------------------

Steffen

I am still not convinced such an additional event is really needed. Why can't you just use NHttpServiceHandler.responseReady() for that end?  

Oleg

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496152 ] 

Oleg Kalnichevski commented on HTTPCORE-73:
-------------------------------------------

Steffen

Please pull the latest changes from the SVN. I made a few tweaks to the NHttp*Connections that may be relevant for your work. Most importantly I made sure #responseReady() / #requestReady() events do not fire until the content of the session output buffer has been fully flushed, so it would be safe to call #suspendOutput() on the connection that triggered the event.

Oleg 

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Resolved: (HTTPCORE-73) NHttpServiceHandler#responseReady and NHttpClientHandler#requestReady events fail to fire if the HTTP message has no content body

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCORE-73.
---------------------------------------

    Resolution: Fixed

Superb! The patch also makes code quite a bit cleaner.

Patch checked in. Many thanks, Steffen!

Oleg

> NHttpServiceHandler#responseReady and NHttpClientHandler#requestReady events fail to fire if the HTTP message has no content body
> ---------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-nio-request-ready.patch
>
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Steffen Pingel (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steffen Pingel updated HTTPCORE-73:
-----------------------------------

    Attachment: httpcore-nio-request-ready.patch

Oleg, I changed my implementation to use the responseReady() event but some of my test cases failed because the event was not always fired. When a response has no body DefaultNHttpServerConnection.produceOutput() will flush outbuf and then clear write events causing it to not get called again. Please see the attached patch for a fix.

Thanks again for all your efforts! With the latest changes I have been able to integrate an unmodified version (except for this patch) of httpcore in my application for handling of HTTP requests which clearly demonstrates the flexibility and versatility of the API.

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>         Attachments: httpcore-nio-request-ready.patch
>
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12495890 ] 

Oleg Kalnichevski commented on HTTPCORE-73:
-------------------------------------------

Steffen
At what point do you want this event to fire?
(1) response head has been submitted and copied to the session buffer
(2) response head has been written from the session buffer to the underlying channel
(3) response head and response body have been fully written to the underlying channel

Oleg

PS: My guts tell me this one is going to be ugly

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent:
>  void responseSubmitted(NHttpServerConnection conn);
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers.
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-73) NHttpServiceHandler#responseReady and NHttpClientHandler#requestReady events fail to fire if the HTTP message has no content body

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCORE-73:
--------------------------------------

    Fix Version/s: 4.0-alpha5
          Summary: NHttpServiceHandler#responseReady and NHttpClientHandler#requestReady events fail to fire if the HTTP message has no content body  (was: Add notification to NHttpServiceHandler when response has been sent)

> NHttpServiceHandler#responseReady and NHttpClientHandler#requestReady events fail to fire if the HTTP message has no content body
> ---------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>             Fix For: 4.0-alpha5
>
>         Attachments: httpcore-nio-request-ready.patch
>
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Updated: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Steffen Pingel (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steffen Pingel updated HTTPCORE-73:
-----------------------------------

    Description: 
Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 

void responseSubmitted(NHttpServerConnection conn); 

The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 

Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

  was:
Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent:

 void responseSubmitted(NHttpServerConnection conn);

The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers.

Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.





> (1) response head has been submitted and copied to the session buffer

I think that is internal to the implementation of the connection (and the case when DefaultNHttpServerConnection.submitResponse() returns), so I don't think an event is needed here.

My current approach fires the event when the encoder has completed and the session buffer in DefaultNHttpServerConnection has been written to the channel. 

> (2) response head has been written from the session buffer to the underlying
> channel

An explicit event would be nice but I currently assume that when NHttpServiceHandler.outputReady() is invoked that the head has been written and the body is now being processed. 

For HEAD requests an event is fired since NHttpServiceHandler.outputReady() is not invoked.

> (3) response head and response body have been fully written to the underlying
> channel

An event is fired here (in order to switch throttling and to update the UI).

> PS: My guts tell me this one is going to be ugly

In order to get it working cleanly I modified DefaultNHttpServerConnection to process responses sequentially. I have to agree that it would get ugly when it came to keeping track which part of the session buffer maps to which response to fire events accordingly.


> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


[jira] Commented: (HTTPCORE-73) Add notification to NHttpServiceHandler when response has been sent

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12496117 ] 

Oleg Kalnichevski commented on HTTPCORE-73:
-------------------------------------------

Steffen

I suspect it may not be possible to introduce this functionality without losing ability to pipeline HTTP messages. 

And I still do not see why exiting API is not sufficient for this use case. Consider the following sequence of events:

NHttpServiceHandler#outputReady contentCodec#completed -> false   
NHttpServiceHandler#outputReady contentCodec#completed -> false
NHttpServiceHandler#outputReady contentCodec#completed -> true // end of the last response body
NHttpServiceHandler#responseReady response == null // ready to submit new response

If you are not pipelining messages, just keep the last response in the connection context. The event handler can detect the end of the message when NHttpServiceHandler#outputReady event is fired and update the context accordingly. Once NHttpServiceHandler#responseReady has been fired you can obtain the last response from the context

Am I still missing something?

Oleg

> Add notification to NHttpServiceHandler when response has been sent
> -------------------------------------------------------------------
>
>                 Key: HTTPCORE-73
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-73
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha5
>            Reporter: Steffen Pingel
>
> Add a new method to NHttpServiceHandler that notifies the service handler that a response has been sent: 
> void responseSubmitted(NHttpServerConnection conn); 
> The sent response can be retrieved through conn.getHttpResponse() when the method is invoked. The use case here is that I need to enable and disable throttling per response (which is handled by the underlying NIO layer) and need to know at what point the output buffer for a response has been flushed. The throttling is controlled in the application layer so I need to propagate the event through the layers. 
> Such an event notification could also replace NHttpServerConnection.isResponseSubmitted() which currently has an implementation in DefaultNHttpServerConnection that does not match the JavaDoc specification.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org