Re: [Resteasy-users] ClientResponse.overrideUri()
Sorry it took a while, added to JIRA now # RESTEASY-613 Thank you, Sandeep. -Original Message- From: Bill Burke [mailto:bbu...@redhat.com] Sent: Tuesday, October 04, 2011 11:03 AM To: resteasy-users@lists.sourceforge.net Cc: Ron Sigal Subject: Re: [Resteasy-users] ClientResponse.overrideUri() Log a jira please. On 10/3/11 10:24 AM, Sandeep Tikoo wrote: Hi, I am using RestEasy on the client side (version 2.2.1.GA) . I have a requirement to try a secondary endpoint (host) if the request to the primary endpoint fails (in case it is down). I thought about implementing a org.jboss.resteasy.spi.interception.ClientExecutionInterceptor which checks for unsuccessful call to the primary endpoint, changes the URI of the request to the secondary endpoint using ClientResponse.overrideUri() and then reissue the request. It did not work, it seems that calling ClientResponse.overrideUri() is in effect a NOP. Even though ClientResponse.overrideURI() changes the internal URIBuilder, internally ClientResponse caches the URI in a protected field 'finalURI' and when ClientResponse.getURI() is invoked by RestEasy, to make the Http call, it reuses the old value of the URI. In eclipse debugger, after calling overrideURI, if I set finalURI to null, everything works as expected for me - the exact same REST call is issued but now against the secondary endpoint that I specified using ClientResponse.overrideURI() I am not sure if ClientResponse.overrideUri() is working as designed (there is no javadoc and I have not been able to find any information in JIRA or the forums) or if this is a bug which can be fixed by setting this.finalURI to null in ClientResponse.overrideUri(). Also providing snippet of the code I am trying, just in case it helps clarify my question. Thanks for your help. Sandeep. *public**class*RetryOnErrorInterceptor *implements*ClientExecutionInterceptor { ... ... @Override *public*ClientResponse? execute(*final*ClientExecutionContext context) *throws*Exception { ClientResponse? response = *null*; *try* { response = context.proceed(); } *catch*(UnknownHostException uhe) { response = executeAgain(context, response); } *catch*(SocketTimeoutException ste) { response = executeAgain(context, response); } *catch*(Exception ex) { *throw**new*RestClientException( This seemed like an unrecoverable exception so no retry to a different endpoint is going to be attempted., ex); } *if*(*this*.isErrorResponseReceived(response.getStatus())) { response = executeAgain(context, response); } *return*response; } *private*ClientResponse? executeAgain(*final*ClientExecutionContext context, *final*ClientResponse? response) *throws*Exception { *if*(response != *null*) { response.releaseConnection(); } ClientRequest request = context.getRequest(); String uriStr = request.getUri(); URI uri = *new*URI(uriStr); URI endPointURI = *new*URI(*this*.config.getEndPoint1()); URI retryURI = *new*URI( endPointURI.getScheme(), endPointURI.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()); request.overrideUri(retryURI); *return*context.proceed(); } ... ... } -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2d-oct ___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users
Re: [Resteasy-users] ClientResponse.overrideUri()
Log a jira please. On 10/3/11 10:24 AM, Sandeep Tikoo wrote: Hi, I am using RestEasy on the client side (version 2.2.1.GA) . I have a requirement to try a secondary endpoint (host) if the request to the primary endpoint fails (in case it is down). I thought about implementing a org.jboss.resteasy.spi.interception.ClientExecutionInterceptor which checks for unsuccessful call to the primary endpoint, changes the URI of the request to the secondary endpoint using ClientResponse.overrideUri() and then reissue the request. It did not work, it seems that calling ClientResponse.overrideUri() is in effect a NOP. Even though ClientResponse.overrideURI() changes the internal URIBuilder, internally ClientResponse caches the URI in a protected field ‘finalURI’ and when ClientResponse.getURI() is invoked by RestEasy, to make the Http call, it reuses the old value of the URI. In eclipse debugger, after calling overrideURI, if I set finalURI to null, everything works as expected for me – the exact same REST call is issued but now against the secondary endpoint that I specified using ClientResponse.overrideURI() I am not sure if ClientResponse.overrideUri() is working as designed (there is no javadoc and I have not been able to find any information in JIRA or the forums) or if this is a bug which can be fixed by setting this.finalURI to null in ClientResponse.overrideUri(). Also providing snippet of the code I am trying, just in case it helps clarify my question. Thanks for your help. Sandeep. *public**class*RetryOnErrorInterceptor *implements*ClientExecutionInterceptor { … … @Override *public*ClientResponse? execute(*final*ClientExecutionContext context) *throws*Exception { ClientResponse? response = *null*; *try* { response = context.proceed(); } *catch*(UnknownHostException uhe) { response = executeAgain(context, response); } *catch*(SocketTimeoutException ste) { response = executeAgain(context, response); } *catch*(Exception ex) { *throw**new*RestClientException( This seemed like an unrecoverable exception so no retry to a different endpoint is going to be attempted., ex); } *if*(*this*.isErrorResponseReceived(response.getStatus())) { response = executeAgain(context, response); } *return*response; } *private*ClientResponse? executeAgain(*final*ClientExecutionContext context, *final*ClientResponse? response) *throws*Exception { *if*(response != *null*) { response.releaseConnection(); } ClientRequest request = context.getRequest(); String uriStr = request.getUri(); URI uri = *new*URI(uriStr); URI endPointURI = *new*URI(*this*.config.getEndPoint1()); URI retryURI = *new*URI( endPointURI.getScheme(), endPointURI.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()); request.overrideUri(retryURI); *return*context.proceed(); } … … } -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users
[Resteasy-users] ClientResponse.overrideUri()
Hi, I am using RestEasy on the client side (version 2.2.1.GA) . I have a requirement to try a secondary endpoint (host) if the request to the primary endpoint fails (in case it is down). I thought about implementing a org.jboss.resteasy.spi.interception.ClientExecutionInterceptor which checks for unsuccessful call to the primary endpoint, changes the URI of the request to the secondary endpoint using ClientResponse.overrideUri() and then reissue the request. It did not work, it seems that calling ClientResponse.overrideUri() is in effect a NOP. Even though ClientResponse.overrideURI() changes the internal URIBuilder, internally ClientResponse caches the URI in a protected field 'finalURI' and when ClientResponse.getURI() is invoked by RestEasy, to make the Http call, it reuses the old value of the URI. In eclipse debugger, after calling overrideURI, if I set finalURI to null, everything works as expected for me - the exact same REST call is issued but now against the secondary endpoint that I specified using ClientResponse.overrideURI() I am not sure if ClientResponse.overrideUri() is working as designed (there is no javadoc and I have not been able to find any information in JIRA or the forums) or if this is a bug which can be fixed by setting this.finalURI to null in ClientResponse.overrideUri(). Also providing snippet of the code I am trying, just in case it helps clarify my question. Thanks for your help. Sandeep. public class RetryOnErrorInterceptor implements ClientExecutionInterceptor { ... ... @Override public ClientResponse? execute(final ClientExecutionContext context) throws Exception { ClientResponse? response = null; try { response = context.proceed(); } catch (UnknownHostException uhe) { response = executeAgain(context, response); } catch (SocketTimeoutException ste) { response = executeAgain(context, response); } catch (Exception ex) { throw new RestClientException( This seemed like an unrecoverable exception so no retry to a different endpoint is going to be attempted., ex); } if (this.isErrorResponseReceived(response.getStatus())) { response = executeAgain(context, response); } return response; } private ClientResponse? executeAgain(final ClientExecutionContext context, final ClientResponse? response) throws Exception { if (response != null) { response.releaseConnection(); } ClientRequest request = context.getRequest(); String uriStr = request.getUri(); URI uri = new URI(uriStr); URI endPointURI = new URI(this.config.getEndPoint1()); URI retryURI = new URI( endPointURI.getScheme(), endPointURI.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()); request.overrideUri(retryURI); return context.proceed(); } ... ... } -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1___ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users