RE: Re: Re: Transparent reverse proxying using org.restlet.routing.Redirector

2014-04-18 Thread Primož Kokol
Hi again,

My next try was to remove all original headers (like default implementation do) 
and then preserver only Authentication header.

So I replaced this line:

https://github.com/restlet/restlet-framework-java/blob/2.2/modules/org.restlet/src/org/restlet/routing/Redirector.java#L407

with call to this method:

private void preserveHeaders(Request request)
{
SeriesHeader headers = (SeriesHeader) 
request.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
SeriesHeader newHeaders = new SeriesHeader(Header.class);

for (String headerName : headersToPreserve) {
Header headerToPreserve = headers.getFirst(headerName);
if (headerToPreserve != null) {
newHeaders.add(headerToPreserve);
}
}
request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, 
newHeaders);
}

where 

headersToPreserve = Arrays.asList(HeaderConstants.HEADER_AUTHORIZATION)

After this change, the response from proxy is always:

HTTP/1.1 1002 Internal Connector Error
Date: Fri, 18 Apr 2014 08:01:10 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.1.4
Content-Length: 484
Content-Type: text/html; charset=UTF-8

I am somehow abandoning the idea of using Restlet as a transparent reverse 
proxy, but anyway, I've attached a small example of test implementation if 
someone will have time and willpower to look at it.

Tim, thank you for your support!

Any advices on how could I achieve Digest/Basic authentication to work on 
backend server when in front of it is a proxy are still welcome.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3076691

RestletReverseProxyTest.rar
Description: Binary data


Re: Re: Re: Transparent reverse proxying using org.restlet.routing.Redirector

2014-04-18 Thread Tim Peierls
I don't have time to look at this, unfortunately.

I have Basic auth working with outbound redirection. I *don't *change the
way the headers are removed, but I do remove the challenge response.

// From my Redirector subclass:
@Override
protected void outboundServerRedirect(
Reference targetRef, Request request, Response response) {

// Unset challenge response that authentication puts in.
request.setChallengeResponse(null);
 super.outboundServerRedirect(targetRef, request, response);
}

Before I did this, I believe I had internal connector errors similar to
what you describe.

--tim


On Fri, Apr 18, 2014 at 4:14 AM, Primož Kokol primoz.ko...@gmail.comwrote:

 Hi again,

 My next try was to remove all original headers (like default
 implementation do) and then preserver only Authentication header.

 So I replaced this line:


 https://github.com/restlet/restlet-framework-java/blob/2.2/modules/org.restlet/src/org/restlet/routing/Redirector.java#L407

 with call to this method:

 private void preserveHeaders(Request request)
 {
 SeriesHeader headers = (SeriesHeader)
 request.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
 SeriesHeader newHeaders = new
 SeriesHeader(Header.class);

 for (String headerName : headersToPreserve) {
 Header headerToPreserve =
 headers.getFirst(headerName);
 if (headerToPreserve != null) {
 newHeaders.add(headerToPreserve);
 }
 }

 request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, newHeaders);
 }

 where

 headersToPreserve =
 Arrays.asList(HeaderConstants.HEADER_AUTHORIZATION)

 After this change, the response from proxy is always:

 HTTP/1.1 1002 Internal Connector Error
 Date: Fri, 18 Apr 2014 08:01:10 GMT
 Accept-Ranges: bytes
 Server: Restlet-Framework/2.1.4
 Content-Length: 484
 Content-Type: text/html; charset=UTF-8

 I am somehow abandoning the idea of using Restlet as a transparent reverse
 proxy, but anyway, I've attached a small example of test implementation if
 someone will have time and willpower to look at it.

 Tim, thank you for your support!

 Any advices on how could I achieve Digest/Basic authentication to work on
 backend server when in front of it is a proxy are still welcome.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3076691

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3076698

Re: Transparent reverse proxying using org.restlet.routing.Redirector

2014-04-18 Thread Arjohn Kampman
I've debugged the problem to an infinite loop when trying to set the Via 
header on the request that the proxy sends to the back-end server. This 
infinite loop is not triggered when Redirector removes the headers 
becuase HttpInboundRequest.getRecipientsInfo() has a getHeaders() != 
null check.

I've captured the stack trace below when when the loop has gone through 
three cycles between setRecipientsInfo and getRecipientsInfo using 
restlet 2.1.4. Is this a bug in HttpInboundRequest or are we doing 
something wrong?

Daemon Thread [Restlet-21015178] (Suspended)
* loop break point *
 HttpInboundRequest.getRecipientsInfo() line: 579
HttpInboundRequest(Message).setRecipientsInfo(ListRecipientInfo) line: 
426
 HttpInboundRequest.setRecipientsInfo(ListRecipientInfo) line: 804
 HttpInboundRequest.getRecipientsInfo() line: 579
HttpInboundRequest(Message).setRecipientsInfo(ListRecipientInfo) line: 
426
 HttpInboundRequest.setRecipientsInfo(ListRecipientInfo) line: 804
 HttpInboundRequest.getRecipientsInfo() line: 579
HttpInboundRequest(Message).setRecipientsInfo(ListRecipientInfo) line: 
426
 HttpInboundRequest.setRecipientsInfo(ListRecipientInfo) line: 804
 HttpInboundRequest.getRecipientsInfo() line: 579
* loop start **
 HeaderUtils.addGeneralHeaders(Message, SeriesHeader) line: 264
 ClientAdapter.toSpecific(HttpClientHelper, Request) line: 163
 HttpClientHelper(HttpClientHelper).handle(Request, Response) line: 111
 Client.handle(Request, Response) line: 180
 ClientRoute(Filter).doHandle(Request, Response) line: 159
 ClientRoute(Filter).handle(Request, Response) line: 206
 ClientRouter(Router).doHandle(Restlet, Request, Response) line: 431
 ClientRouter(Router).handle(Request, Response) line: 648
 ComponentClientDispatcher.doHandle(Request, Response) line: 140
 ComponentClientDispatcher(Filter).handle(Request, Response) line: 206
 ChildClientDispatcher.parentHandle(Request, Response) line: 148
 ChildClientDispatcher.doHandle(Request, Response) line: 121
 ChildClientDispatcher(Filter).handle(Request, Response) line: 206
 ChildClientDispatcher.parentHandle(Request, Response) line: 148
 ChildClientDispatcher.doHandle(Request, Response) line: 121
 ChildClientDispatcher(Filter).handle(Request, Response) line: 206
 Decoder(Filter).doHandle(Request, Response) line: 159
 Decoder(Filter).handle(Request, Response) line: 206
 CustomRedirector.serverRedirect(Restlet, Reference, Request, 
Response) line: 53
 CustomRedirector(Redirector).outboundServerRedirect(Reference, 
Request, Response) line: 352
 CustomRedirector(Redirector).handle(Request, Response) line: 295
 TemplateRoute(Filter).doHandle(Request, Response) line: 159
 TemplateRoute(Filter).handle(Request, Response) line: 206
 Router.doHandle(Restlet, Request, Response) line: 431
 Router.handle(Request, Response) line: 648
 RangeFilter(Filter).doHandle(Request, Response) line: 159
 RangeFilter(Filter).handle(Request, Response) line: 206
 Decoder(Filter).doHandle(Request, Response) line: 159
 Decoder(Filter).handle(Request, Response) line: 206
 StatusFilter(Filter).doHandle(Request, Response) line: 159
 StatusFilter.doHandle(Request, Response) line: 155
 StatusFilter(Filter).handle(Request, Response) line: 206
 TunnelFilter(Filter).doHandle(Request, Response) line: 159
 TunnelFilter(Filter).handle(Request, Response) line: 206
 ApplicationHelper(CompositeHelperT).handle(Request, Response) 
line: 211
 ApplicationHelper.handle(Request, Response) line: 84
 TransparentReverseProxyApp(Application).handle(Request, Response) 
line: 381
 VirtualHost$1(Filter).doHandle(Request, Response) line: 159
 VirtualHost$1(Filter).handle(Request, Response) line: 206
 VirtualHost(Router).doHandle(Restlet, Request, Response) line: 431
 VirtualHost(Router).handle(Request, Response) line: 648
 HostRoute(Filter).doHandle(Request, Response) line: 159
 HostRoute(Filter).handle(Request, Response) line: 206
 ServerRouter(Router).doHandle(Restlet, Request, Response) line: 431
 ServerRouter(Router).handle(Request, Response) line: 648
 StatusFilter(Filter).doHandle(Request, Response) line: 159
 StatusFilter.doHandle(Request, Response) line: 155
 StatusFilter(Filter).handle(Request, Response) line: 206
 LogFilter(Filter).doHandle(Request, Response) line: 159
 LogFilter(Filter).handle(Request, Response) line: 206
 ComponentHelper(CompositeHelperT).handle(Request, Response) line: 
211
 Component.handle(Request, Response) line: 392
 Server.handle(Request, Response) line: 516
 HttpServerHelper(ServerConnectionHelper).handle(Request, Response) 
line: 257
HttpServerHelper(ServerConnectionHelper).doHandleInbound(Response) line: 
186
 BaseHelper$2.run() line: 593
 ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1145