portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sascha Arndt (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (APA-72) No cookie rewriting
Date Tue, 22 Dec 2015 12:53:46 GMT

    [ https://issues.apache.org/jira/browse/APA-72?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15068070#comment-15068070
] 

Sascha Arndt edited comment on APA-72 at 12/22/15 12:52 PM:
------------------------------------------------------------

Ah yes, I missed that.

But I think the current implementation of the Servlet will be the wrong place to do that.

I think - if I got the code right - the best place for this would be in the ExecuteHttpClientCommand
as follows:

{code:title=ExecuteHttpClientCommand.java|borderStyle=solid}
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException,
IOException {
  HttpRequestBase httpRequest = context.getHttpRequest();

  HttpClient httpClient = context.getHttpClient();
  HttpResponse httpResponse = null;

  if (getHttpClientContextBuilder() == null) {
    httpResponse = httpClient.execute(httpRequest);
  } else {
    HttpClientContext httpClientContext = getHttpClientContextBuilder().build();

    // ThreadLocal<ProxyContext> is currently set
    // ProxyContext has its own instance of CookieStore (no sharing across multiple users)
    ProxyContext proxyContext = ProxyContext.getCurrentProxyContext();
    CookieStore cookieStore = proxyContext.getCookieStore();
    if (cookieStore != null) {
      httpClientContext.setCookieStore(cookieStore);
    }
    httpResponse = httpClient.execute(httpRequest, httpClientContext);
  }

  context.setHttpResponse(httpResponse);

  return false;
}
{code}

Or do I still miss something?

Regards, Sascha


was (Author: saschaa1982):
Ah yes, I missed that.

But I think the current implementation of the Servlet will be the wrong place to do that.

I think - if I got the code right - the best place for this would be in the ExecuteHttpClientCommand
as follows:

{code:title=ExecuteHttpClientCommand.java|borderStyle=solid}
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException,
IOException {
  HttpRequestBase httpRequest = context.getHttpRequest();

  HttpClient httpClient = context.getHttpClient();
  HttpResponse httpResponse = null;

  if (getHttpClientContextBuilder() == null) {
    httpResponse = httpClient.execute(httpRequest);
  } else {
    HttpClientContext httpClientContext = getHttpClientContextBuilder().build();
    ProxyContext proxyContext = ProxyContext.getCurrentProxyContext();
    CookieStore cookieStore = proxyContext.getCookieStore();
    if (cookieStore != null) {
      httpClientContext.setCookieStore(cookieStore);
    }
    httpResponse = httpClient.execute(httpRequest, httpClientContext);
  }

  context.setHttpResponse(httpResponse);

  return false;
}
{code}

Or do I still miss something?

Regards, Sascha

> No cookie rewriting
> -------------------
>
>                 Key: APA-72
>                 URL: https://issues.apache.org/jira/browse/APA-72
>             Project: Portals Apps
>          Issue Type: Bug
>          Components: apa-webcontent
>    Affects Versions: apa-webcontent-2.0
>            Reporter: Sascha Arndt
>            Assignee: Woonsan Ko
>
> I have a problem using this maven dependency:
> {code:xml}
> <dependency>
>   <groupId>org.apache.portals.applications</groupId>
>   <artifactId>apa-webcontent2-reverse-proxy</artifactId>
>   <version>2.0</version>
> </dependency>
> {code}
> Using this version of apa-webcontent2-reverse-proxy none of my cookies got rewrited or
send back to the client. After some debugging session I found out, that the CloseableHttpClient
and the ProxyContext were using different CookieStore objects.
> I "patched" it locally replacing "InitHttpClientCommand"s executeInternal-method like
this:
> {code:title=InitHttpClientCommand.java|borderStyle=solid}
> @Override
> protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException,
IOException {
>   CookieStore cookieStore = new BasicCookieStore();
>   CloseableHttpClient httpClient = httpClientBuilder.setDefaultCookieStore(cookieStore).build();
>   context.setCookieStore(cookieStore);
>   context.setHttpClient(httpClient);
>   return false;
> }
> {code}
> Is this a bug, or am I using it wrong?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message