You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by sdutry <gi...@git.apache.org> on 2017/03/27 21:46:05 UTC

[GitHub] struts-extras pull request #3: added module for extra result types

GitHub user sdutry opened a pull request:

    https://github.com/apache/struts-extras/pull/3

    added module for extra result types

    This is still work in progress.
    
    The reason i'm already having it as pull request is because any input is welcome.
    
    related to WW-4774
    
    ## So far
    - `HttpsOffloadAwareServletRedirectResult`
      - checks `X-Forwarded-Proto` header
    
    ## TODO
    - support official `Forwarded` header 
    - `HttpsOffloadAwareServletActionRedirectResult`
    - add `struts-plugin.xml` file with result type definitions
    - add `README.md`

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sdutry/struts-extras httpsfix

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/struts-extras/pull/3.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #3
    
----
commit 1a64217f87566831864371622673951d29dca79a
Author: Stefaan Dutry <st...@gmail.com>
Date:   2017-03-27T21:20:48Z

    added HttpsOffloadAwareServletRedirectResult

commit 7879bafe58fd7d82d8e31f34dd88736e337f0a12
Author: Stefaan Dutry <st...@gmail.com>
Date:   2017-03-27T21:25:40Z

    used spaces for indentation

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108515221
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    --- End diff --
    
    made optional


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108515374
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    +        </dependency>
    +
    +        <dependency>
    +            <groupId>org.apache.logging.log4j</groupId>
    +            <artifactId>log4j-api</artifactId>
    +            <version>2.8</version>
    +        </dependency>
    +        
    +        <dependency>
    +            <groupId>javax.servlet</groupId>
    +            <artifactId>servlet-api</artifactId>
    +            <version>2.4</version>
    +            <scope>provided</scope>
    +        </dependency>
    +
    +    </dependencies>
    +
    +    <build>
    +        <plugins>
    +            <plugin>
    +                <groupId>org.apache.maven.plugins</groupId>
    +                <artifactId>maven-compiler-plugin</artifactId>
    +                <configuration>
    +                    <source>1.6</source>
    +                    <target>1.6</target>
    --- End diff --
    
    changed to 1.7


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108515260
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    +        </dependency>
    +
    +        <dependency>
    +            <groupId>org.apache.logging.log4j</groupId>
    +            <artifactId>log4j-api</artifactId>
    +            <version>2.8</version>
    +        </dependency>
    --- End diff --
    
    made optional


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108343998
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    --- End diff --
    
    modifier changed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras issue #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on the issue:

    https://github.com/apache/struts-extras/pull/3
  
    You can merge it :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108499635
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    +        </dependency>
    +
    +        <dependency>
    +            <groupId>org.apache.logging.log4j</groupId>
    +            <artifactId>log4j-api</artifactId>
    +            <version>2.8</version>
    +        </dependency>
    --- End diff --
    
    Same here, you rather won't use this plugin out of the Struts2 Core, so it can be optional.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras issue #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on the issue:

    https://github.com/apache/struts-extras/pull/3
  
    This is great, osm work!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108500278
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,188 @@
    +/*
    + * $Id$
    --- End diff --
    
    The same here, please remove this tag


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108516053
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,188 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.Enumeration;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.regex.Pattern;
    +import java.util.regex.Matcher;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class SslOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(SslOffloadAwareServletRedirectResult.class);
    +    private static final Pattern FORWARDED_PROTO_PARAM_HTTPS = Pattern.compile("[^;]proto=https[$;]");
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult() {
    +        super();
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult(String location) {
    +        this(location, null);
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult(String location, String anchor) {
    +        super(location, anchor);
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if (shouldFixScheme(request)) {
    +            LOG.debug("https offloading happened, fixing redirectlocation");
    +            StringBuilder fixedLocation = new StringBuilder();
    +            fixedLocation.append("https");
    +            fixedLocation.append("://");
    +            fixedLocation.append(request.getServerName());
    +            if (request.getServerPort() != 80) {
    +                fixedLocation.append(':');
    +                fixedLocation.append(request.getServerPort());
    +            }
    +            fixedLocation.append(location);
    +
    +            return fixedLocation.toString();
    +        } else {
    +            return location;
    +        }
    +    }
    +
    +    protected boolean shouldFixScheme(HttpServletRequest request) {
    +        return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
    --- End diff --
    
    - extracted logic into protected method `hasXForwardedProtoHttps`
    - changed `hasForwardedHeaderWithProtoParamHttps` to protected


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108499081
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    --- End diff --
    
    What do you think about making this an optional dependency?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108344434
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
    --- End diff --
    
    Yes


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108499879
  
    --- Diff: struts2-custom-results-plugin/pom.xml ---
    @@ -0,0 +1,104 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    + Licensed to the Apache Software Foundation (ASF) under one
    + or more contributor license agreements.  See the NOTICE file
    + distributed with this work for additional information
    + regarding copyright ownership.  The ASF licenses this file
    + to you under the Apache License, Version 2.0 (the
    + "License"); you may not use this file except in compliance
    + with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    + Unless required by applicable law or agreed to in writing,
    + software distributed under the License is distributed on an
    + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + KIND, either express or implied.  See the License for the
    + specific language governing permissions and limitations
    + under the License.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <parent>
    +        <groupId>org.apache.struts</groupId>
    +        <artifactId>struts-master</artifactId>
    +        <version>10</version>
    +    </parent>
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <artifactId>struts2-custom-results-plugin</artifactId>
    +    <version>1.2-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>struts2 custom results plugin</name>
    +
    +    <description>
    +        This plugin defines some additional result types
    +    </description>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +    </properties>
    +
    +    <scm>
    +        <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
    +        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
    +        <url>http://git.apache.org/struts-extras.git</url>
    +        <tag>HEAD</tag>
    +    </scm>
    +
    +    <issueManagement>
    +        <system>JIRA</system>
    +        <url>https://issues.apache.org/jira/browse/WW</url>
    +    </issueManagement>
    +
    +    <ciManagement>
    +        <system>Jenkins</system>
    +        <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
    +        <notifiers>
    +            <notifier>
    +                <type>mail</type>
    +                <configuration>
    +                    <address>dev@struts.apache.org</address>
    +                </configuration>
    +            </notifier>
    +        </notifiers>
    +    </ciManagement>
    +
    +    <dependencies>
    +
    +        <dependency>
    +            <groupId>org.apache.struts</groupId>
    +            <artifactId>struts2-core</artifactId>
    +            <version>2.5.10.1</version>
    +        </dependency>
    +
    +        <dependency>
    +            <groupId>org.apache.logging.log4j</groupId>
    +            <artifactId>log4j-api</artifactId>
    +            <version>2.8</version>
    +        </dependency>
    +        
    +        <dependency>
    +            <groupId>javax.servlet</groupId>
    +            <artifactId>servlet-api</artifactId>
    +            <version>2.4</version>
    +            <scope>provided</scope>
    +        </dependency>
    +
    +    </dependencies>
    +
    +    <build>
    +        <plugins>
    +            <plugin>
    +                <groupId>org.apache.maven.plugins</groupId>
    +                <artifactId>maven-compiler-plugin</artifactId>
    +                <configuration>
    +                    <source>1.6</source>
    +                    <target>1.6</target>
    --- End diff --
    
    If this plugin targets Struts 2.5.x it supposed to be `1.7` - the same as we have in the Core.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108343533
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
    --- End diff --
    
    I would extract this into another `protected` method, then users can override the method and apply some other rules when to fix schema.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/struts-extras/pull/3


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108343374
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    --- End diff --
    
    It's a good practise to make method `protected` as this allows others to easily extend your class


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108519883
  
    --- Diff: struts2-custom-results-plugin/README.md ---
    @@ -0,0 +1,42 @@
    +# Apache Struts 2 Extras - custom results plugin
    +
    +[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
    +
    +This plugin provides additional result types.
    +
    +## Supported versions
    +
    +This plugin can be used with the Apache Struts versions 2.5.x .
    +
    +## Result Type categories
    +
    +### SSL offloading support
    +
    +These result types are made to support redirecting under the https protocol while being behind a SSL offloading proxy.
    +
    +#### Result Types
    +
    +##### sslOffloadRedirect
    +
    +This Result Type should replace the `redirect` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +##### sslOffloadRedirectAction
    +
    +This Result Type should replace the `redirectAction` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +#### struts packages
    +
    +##### ssl-offload
    +
    +Only thing this package does is defining the result types so that they can be used.
    +
    +##### ssl-offload-default
    +
    +Merely combines the `struts-default` package and the `ssl-offload` package.
    --- End diff --
    
    Added information on how to get the result types available to you.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108344564
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
    --- End diff --
    
    condition extracted in own method


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108500015
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java ---
    @@ -0,0 +1,123 @@
    +/*
    + * $Id$
    --- End diff --
    
    Please remove this tag, it was used with SVN, now is useless.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108511395
  
    --- Diff: struts2-custom-results-plugin/README.md ---
    @@ -0,0 +1,42 @@
    +# Apache Struts 2 Extras - custom results plugin
    +
    +[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
    +
    +This plugin provides additional result types.
    +
    +## Supported versions
    +
    +This plugin can be used with the Apache Struts versions 2.5.x .
    +
    +## Result Type categories
    +
    +### SSL offloading support
    +
    +These result types are made to support redirecting under the https protocol while being behind a SSL offloading proxy.
    +
    +#### Result Types
    +
    +##### sslOffloadRedirect
    +
    +This Result Type should replace the `redirect` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +##### sslOffloadRedirectAction
    +
    +This Result Type should replace the `redirectAction` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +#### struts packages
    +
    +##### ssl-offload
    +
    +Only thing this package does is defining the result types so that they can be used.
    +
    +##### ssl-offload-default
    +
    +Merely combines the `struts-default` package and the `ssl-offload` package.
    --- End diff --
    
    I have no problem with adding this.
    
    But given that the `ssl-offload` package's only purpose is to define those results, i'm kind of not getting the point of it.
    
    I think i'll just add both ways as an example.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108344620
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
    --- End diff --
    
    WoW, you are fast :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras issue #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on the issue:

    https://github.com/apache/struts-extras/pull/3
  
    @lukaszlenart 
    Am i allowed to merge this now?
    Or does this need to be reviewed and approved by someone else first?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108343668
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,145 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
    --- End diff --
    
    Do you mean the condition in the if statement?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras issue #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on the issue:

    https://github.com/apache/struts-extras/pull/3
  
    @lukaszlenart 
    I think i might be about where i would end up without extra input.
    Could you (or anyone else) please do another review. 
    
    Seeing as the issue where this idea originated from has been closed now, should i create an issue in the JIRA issue tracking system?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108591475
  
    --- Diff: struts2-custom-results-plugin/README.md ---
    @@ -0,0 +1,42 @@
    +# Apache Struts 2 Extras - custom results plugin
    +
    +[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
    +
    +This plugin provides additional result types.
    +
    +## Supported versions
    +
    +This plugin can be used with the Apache Struts versions 2.5.x .
    +
    +## Result Type categories
    +
    +### SSL offloading support
    +
    +These result types are made to support redirecting under the https protocol while being behind a SSL offloading proxy.
    +
    +#### Result Types
    +
    +##### sslOffloadRedirect
    +
    +This Result Type should replace the `redirect` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +##### sslOffloadRedirectAction
    +
    +This Result Type should replace the `redirectAction` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +#### struts packages
    +
    +##### ssl-offload
    +
    +Only thing this package does is defining the result types so that they can be used.
    +
    +##### ssl-offload-default
    +
    +Merely combines the `struts-default` package and the `ssl-offload` package.
    --- End diff --
    
    The most of the users don't know that they can extend multiple packages, and some always prepare a dedicated package without extending any. It's just a suggestion how they can use those results without melting too much in packages :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108515624
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java ---
    @@ -0,0 +1,123 @@
    +/*
    + * $Id$
    --- End diff --
    
    `$id$` tag removed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108500937
  
    --- Diff: struts2-custom-results-plugin/src/main/resources/struts-plugin.xml ---
    @@ -0,0 +1,18 @@
    +<?xml version="1.0" encoding="UTF-8" ?>
    +
    +<!DOCTYPE struts PUBLIC
    +	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    +	"http://struts.apache.org/dtds/struts-2.5.dtd">
    +
    +<struts>
    +    <package name="ssl-offload">
    +        <result-types>
    +            <result-type name="sslOffloadRedirect" class="org.apache.struts2.result.SslOffloadAwareServletRedirectResult"/>
    +            <result-type name="sslOffloadRedirectAction" class="org.apache.struts2.result.SslOffloadAwareServletActionRedirectResult"/>
    +        </result-types>
    +    </package>
    +
    +    <package name="ssl-offload-default" extends="struts-default, ssl-offload">
    --- End diff --
    
    \U0001f44d 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by sdutry <gi...@git.apache.org>.
Github user sdutry commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108515681
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,188 @@
    +/*
    + * $Id$
    --- End diff --
    
    `$id` tag removed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108498477
  
    --- Diff: struts2-custom-results-plugin/README.md ---
    @@ -0,0 +1,42 @@
    +# Apache Struts 2 Extras - custom results plugin
    +
    +[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
    +
    +This plugin provides additional result types.
    +
    +## Supported versions
    +
    +This plugin can be used with the Apache Struts versions 2.5.x .
    +
    +## Result Type categories
    +
    +### SSL offloading support
    +
    +These result types are made to support redirecting under the https protocol while being behind a SSL offloading proxy.
    +
    +#### Result Types
    +
    +##### sslOffloadRedirect
    +
    +This Result Type should replace the `redirect` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +##### sslOffloadRedirectAction
    +
    +This Result Type should replace the `redirectAction` Result Type.
    +It takes into account 2 ways of detecting the offloading:
    +- `X-Forwarded-Proto` header (de-facto standard header)
    +- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
    +
    +#### struts packages
    +
    +##### ssl-offload
    +
    +Only thing this package does is defining the result types so that they can be used.
    +
    +##### ssl-offload-default
    +
    +Merely combines the `struts-default` package and the `ssl-offload` package.
    --- End diff --
    
    It would be good to add an example how you can define those results in your own package, without a need extending the `ssl-offload` or `ssl-offload-default` packages.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] struts-extras pull request #3: added module for extra result types

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts-extras/pull/3#discussion_r108500855
  
    --- Diff: struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java ---
    @@ -0,0 +1,188 @@
    +/*
    + * $Id$
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *  http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.struts2.result;
    +
    +import java.util.Collection;
    +import java.util.Enumeration;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.regex.Pattern;
    +import java.util.regex.Matcher;
    +
    +import javax.servlet.http.HttpServletRequest;
    +import javax.servlet.http.HttpServletResponse;
    +
    +import org.apache.logging.log4j.LogManager;
    +import org.apache.logging.log4j.Logger;
    +import org.apache.struts2.ServletActionContext;
    +import org.apache.struts2.dispatcher.mapper.ActionMapping;
    +import org.apache.struts2.dispatcher.Dispatcher;
    +import org.apache.struts2.result.ServletRedirectResult;
    +import org.apache.struts2.views.util.UrlHelper;
    +
    +import com.opensymphony.xwork2.ActionContext;
    +import com.opensymphony.xwork2.ActionInvocation;
    +import com.opensymphony.xwork2.config.entities.ResultConfig;
    +import com.opensymphony.xwork2.inject.Inject;
    +
    +public class SslOffloadAwareServletRedirectResult extends ServletRedirectResult {
    +    private static final long serialVersionUID = -5384946213381645549L;
    +    private static final Logger LOG = LogManager.getLogger(SslOffloadAwareServletRedirectResult.class);
    +    private static final Pattern FORWARDED_PROTO_PARAM_HTTPS = Pattern.compile("[^;]proto=https[$;]");
    +
    +    private UrlHelper urlHelper;
    +
    +    @Inject
    +    public void setUrlHelper(UrlHelper urlHelper) {
    +        this.urlHelper = urlHelper;
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult() {
    +        super();
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult(String location) {
    +        this(location, null);
    +    }
    +
    +    public SslOffloadAwareServletRedirectResult(String location, String anchor) {
    +        super(location, anchor);
    +    }
    +
    +    /**
    +     * Redirects to the location specified by calling
    +     * {@link HttpServletResponse#sendRedirect(String)}.
    +     * 
    +     * @param finalLocation
    +     *            the location to redirect to.
    +     * @param invocation
    +     *            an encapsulation of the action execution state.
    +     * @throws Exception
    +     *             if an error occurs when redirecting.
    +     */
    +    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    +        ActionContext ctx = invocation.getInvocationContext();
    +        HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    +        HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    +
    +        if (isPathUrl(finalLocation)) {
    +            if (!finalLocation.startsWith("/")) {
    +                ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
    +                String namespace = null;
    +                if (mapping != null) {
    +                    namespace = mapping.getNamespace();
    +                }
    +
    +                if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
    +                    finalLocation = namespace + "/" + finalLocation;
    +                } else {
    +                    finalLocation = "/" + finalLocation;
    +                }
    +            }
    +
    +            // if the URL's are relative to the servlet context, append the
    +            // servlet context path
    +            if (prependServletContext && (request.getContextPath() != null)
    +                    && (request.getContextPath().length() > 0)) {
    +                finalLocation = request.getContextPath() + finalLocation;
    +            }
    +
    +            finalLocation = fixSchemeIfNeeded(finalLocation, request);
    +        }
    +        ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
    +        if (resultConfig != null) {
    +            Map<String, String> resultConfigParams = resultConfig.getParams();
    +
    +            List<String> prohibitedResultParams = getProhibitedResultParams();
    +            for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
    +                if (!prohibitedResultParams.contains(e.getKey())) {
    +                    Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
    +                            suppressEmptyParameters);
    +                    if (!suppressEmptyParameters || !values.isEmpty()) {
    +                        requestParameters.put(e.getKey(), values);
    +                    }
    +                }
    +            }
    +        }
    +
    +        StringBuilder tmpLocation = new StringBuilder(finalLocation);
    +        urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
    +
    +        // add the anchor
    +        if (anchor != null) {
    +            tmpLocation.append('#').append(anchor);
    +        }
    +
    +        finalLocation = response.encodeRedirectURL(tmpLocation.toString());
    +
    +        LOG.debug("Redirecting to finalLocation: {}", finalLocation);
    +
    +        sendRedirect(response, finalLocation);
    +    }
    +
    +    protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
    +        if (shouldFixScheme(request)) {
    +            LOG.debug("https offloading happened, fixing redirectlocation");
    +            StringBuilder fixedLocation = new StringBuilder();
    +            fixedLocation.append("https");
    +            fixedLocation.append("://");
    +            fixedLocation.append(request.getServerName());
    +            if (request.getServerPort() != 80) {
    +                fixedLocation.append(':');
    +                fixedLocation.append(request.getServerPort());
    +            }
    +            fixedLocation.append(location);
    +
    +            return fixedLocation.toString();
    +        } else {
    +            return location;
    +        }
    +    }
    +
    +    protected boolean shouldFixScheme(HttpServletRequest request) {
    +        return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
    --- End diff --
    
    Could you extract `"https".equals(request.getHeader("X-Forwarded-Proto"))` into a method? the same as you have done for `hasForwardedHeaderWithProtoParamHttps` and make them `protected`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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