struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "aditya shrivastava (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (WW-4944) Struts 2 REST Tiles integration issue
Date Tue, 10 Jul 2018 11:46:00 GMT

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

aditya shrivastava edited comment on WW-4944 at 7/10/18 11:45 AM:
------------------------------------------------------------------

Hi Lukasz,

Actually We have intergrated Struts 2 Convention & Struts 2 Rest Plugin. Configuration
for the same goes like this.

struts.xml
{code:java}
// <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

 
<struts>
   
   <constant name="struts.devMode" value="false" />
   <constant name="struts.action.excludePattern" value="/services.*,/rest.*"/>
   <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
   <constant name="struts.enable.SlashesInActionNames" value="true" />    
   <constant name="struts.ognl.allowStaticMethodAccess" value="true" />
   <constant name="struts.enable.DynamicMethodInvocation" value="true" />
   <constant name="struts.mapper.action.prefix.enabled" value="true"/>
   <constant name="struts.multipart.maxSize" value="100000000" />

   <constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
   <constant name="struts.convention.action.mapAllMatches" value="true"/>
   <constant name="struts.mapper.class" value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"/>
   <constant name="struts.mapper.prefixMapping" value="/sm:rest,/pd:rest:struts"/>

   <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="customProxyFactory" class="com.elitecore.nvsmx.system.CustomActionProxyFactory"
/>
    <constant name="struts.actionProxyFactory" value="customProxyFactory"/>

   <constant name="struts.convention.action.suffix" value="CTRL"/>
   <include file="struts-rest-config.xml" />
</struts>
{code}
 Struts-rest.xml

 
{code:java}
// <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

        <!-- the package that is used for handling rest request flow -->
        <constant name="struts.convention.default.parent.package" value="sm"/>



        <!-- A package from which the rest plugin will search the action classes -->
        <constant name="struts.convention.package.locators" value="controller"/>

        <!--added for jackson in order to remove cyclic dependency of Bi-directional relation
on pojo.
        It allows include or exclude properties from the json response -->
        <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="jackson"
class="org.apache.struts2.rest.handler.JacksonLibHandler"/>
        <constant name="struts.rest.handlerOverride.json" value="jackson"/>

        <constant name="struts.rest.content.restrictToGET" value="false" />
        <!-- struts encoding type -->
        <constant name="struts.i18n.encoding" value="UTF-8"/>

        <!-- supported actions -->
        <constant name="struts.action.extension" value="xhtml,,xml,json,action"/>

        <!-- include jars -->
        <constant name="struts.convention.action.includeJars" value=".*?/nvsmx.*?jar(!/)?"/>
        <!--conventional property -->

    <package name="sm" namespace="/sm/*" extends="rest-default">

        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"
/>
        </result-types>
        <interceptors>
            <interceptor name="transaction"
                         class="com.elitecore.nvsmx.system.interceptor.TransactionInterceptor"></interceptor>
            <interceptor name="validConfiguration" class="com.elitecore.nvsmx.system.interceptor.VerifyValidConfigurationInterceptor"/>

            <interceptor-stack name="restStack">

                <interceptor-ref name="transaction">
                    <param name="excludeMethods">deleteConfirm,cacheServerGroups,validateRuleset</param>
                </interceptor-ref>
                <interceptor-ref name="validConfiguration">
                    <param name="excludeMethods">initLogin,login,logout,edit</param>
                </interceptor-ref>
                <interceptor-ref name="restDefaultStack"></interceptor-ref>
            </interceptor-stack>

        </interceptors>
        <global-results>
            <result name="redirectAction" type="redirect">${actionChainUrl}</result>
            <result name="exception"   type="tiles">commons/general/UnhandledException</result>
            <result name="error"      type="tiles">commons/general/Error</result>
            <result name="serverManagerWelcome"    type="tiles">ServerManagerWelcome</result>
            <result name="redirectURL" type="tiles">${actionChainUrl}</result>
            <result name="genericPartnerSearch" type="tiles">_${actionChainUrl}</result>
            <result name="redirectUploadReport" type="tiles">${actionChainUrl}</result>
            <result name="dispatchView" type="tiles">${actionChainUrl}</result>
            <result name="subtableurl">${actionChainUrl}</result>

        </global-results>

        <global-exception-mappings>
            <exception-mapping result="exception" exception="java.lang.Throwable"></exception-mapping>
            <exception-mapping result="exception" exception="java.lang.RuntimeException"></exception-mapping>
        </global-exception-mappings>


    </package>
  
    <package name="pd" namespace="/pd/*" extends="sm"/>
</struts>
{code}
tiles.xml located at WEB-INF folder

 

 
{code:java}
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

<definition name="ServerManagerWelcome" template="/view/sm/BaseSidebarSM.jsp">
<put-attribute name="title" value="Server Manager"/>
<put-attribute name="header" value="/view/commons/general/ServerManagerHeader.jsp"/>
<put-attribute name="leftSide" value="/view/commons/general/SideMenu.jsp"/>
<put-attribute name="rightSide" value="/view/commons/general/ServerManagerWelcome.jsp"/>
<put-attribute name="footer" value="/view/commons/general/Footer.jsp" />
</definition>

<definition name="REGEXP:sm/(.*)/(.*)/(.*)" extends="ServerManagerWelcome">
<put-attribute name="rightSide" value="/WEB-INF/content/sm/{1}/{2}-{3}.jsp"/>
</definition>

<definition name="REGEXP:(.*)/(.*)/(.*)_(.*)" extends="Welcome">
<put-attribute name="body" value="/view/{1}/{2}/{3}{4}.jsp"/> 
</definition>


<definition name="REGEXP:commons/general/(.*)" extends="Welcome">
<put-attribute name="body" value="/view/commons/general/{1}.jsp"/> 
</definition> 

<definition name="loginLayout" template="/view/commons/login/LoginBase.jsp" >
<put-attribute name="body" value="/view/commons/login/Login.jsp"/>
<put-attribute name="footer" value="/view/commons/general/Footer.jsp" />

</definition>

</tiles-definitions>
{code}
My Group CTRL 

 

 
{code:java}
//package com.elitecore.nvsmx.sm.controller.group;

import com.elitecore.corenetvertex.pkg.constants.ACLModules;
import com.elitecore.corenetvertex.sm.acl.GroupData;
import com.elitecore.nvsmx.sm.controller.DestroyNotSupportedCTRL;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import static com.opensymphony.xwork2.Action.SUCCESS;

/**
 * Created by aditya on 8/2/17.
 */

@ParentPackage(value = "sm")
@Namespace("/sm/group")
@Results({
        @Result(name= SUCCESS, type="redirectAction",params = {"actionName","group"})
})
public class GroupCTRL extends DestroyNotSupportedCTRL<GroupData> {

    @Override
    public ACLModules getModule() {
        return ACLModules.GROUP;
    }

    @Override
    public GroupData createModel() {
        return new GroupData();
    }
public HttpHeaders create() { // create
    if(LogManager.getLogger().isDebugLogLevel()){
        LogManager.getLogger().debug("Creating group");
    }
    return new DefaultHttpHeaders(SUCCESS);
    }
}

    @Override
    public void validate() {
        if(///for any reason this validation goes fail & action error added ){
            addActionError("Invalid User");
        }
        super.validate();
    }
}



{code}
>From create group page when i submit the page & validation goes fail & for action
error added 

then redirected page is not page i.e. page without css.

 

 


was (Author: hiaditya04):
Hi Lokasz,

Actually We have intergrated Struts 2 Convention & Struts 2 Rest Plugin. Configuration
for the same goes like this.

struts.xml
{code:java}
// <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

 
<struts>
   
   <constant name="struts.devMode" value="false" />
   <constant name="struts.action.excludePattern" value="/services.*,/rest.*"/>
   <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
   <constant name="struts.enable.SlashesInActionNames" value="true" />    
   <constant name="struts.ognl.allowStaticMethodAccess" value="true" />
   <constant name="struts.enable.DynamicMethodInvocation" value="true" />
   <constant name="struts.mapper.action.prefix.enabled" value="true"/>
   <constant name="struts.multipart.maxSize" value="100000000" />

   <constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
   <constant name="struts.convention.action.mapAllMatches" value="true"/>
   <constant name="struts.mapper.class" value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"/>
   <constant name="struts.mapper.prefixMapping" value="/sm:rest,/pd:rest:struts"/>

   <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="customProxyFactory" class="com.elitecore.nvsmx.system.CustomActionProxyFactory"
/>
    <constant name="struts.actionProxyFactory" value="customProxyFactory"/>

   <constant name="struts.convention.action.suffix" value="CTRL"/>
   <include file="struts-rest-config.xml" />
</struts>
{code}
 Struts-rest.xml

 
{code:java}
// <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

        <!-- the package that is used for handling rest request flow -->
        <constant name="struts.convention.default.parent.package" value="sm"/>



        <!-- A package from which the rest plugin will search the action classes -->
        <constant name="struts.convention.package.locators" value="controller"/>

        <!--added for jackson in order to remove cyclic dependency of Bi-directional relation
on pojo.
        It allows include or exclude properties from the json response -->
        <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="jackson"
class="org.apache.struts2.rest.handler.JacksonLibHandler"/>
        <constant name="struts.rest.handlerOverride.json" value="jackson"/>

        <constant name="struts.rest.content.restrictToGET" value="false" />
        <!-- struts encoding type -->
        <constant name="struts.i18n.encoding" value="UTF-8"/>

        <!-- supported actions -->
        <constant name="struts.action.extension" value="xhtml,,xml,json,action"/>

        <!-- include jars -->
        <constant name="struts.convention.action.includeJars" value=".*?/nvsmx.*?jar(!/)?"/>
        <!--conventional property -->

    <package name="sm" namespace="/sm/*" extends="rest-default">

        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"
/>
        </result-types>
        <interceptors>
            <interceptor name="transaction"
                         class="com.elitecore.nvsmx.system.interceptor.TransactionInterceptor"></interceptor>
            <interceptor name="validConfiguration" class="com.elitecore.nvsmx.system.interceptor.VerifyValidConfigurationInterceptor"/>

            <interceptor-stack name="restStack">

                <interceptor-ref name="transaction">
                    <param name="excludeMethods">deleteConfirm,cacheServerGroups,validateRuleset</param>
                </interceptor-ref>
                <interceptor-ref name="validConfiguration">
                    <param name="excludeMethods">initLogin,login,logout,edit</param>
                </interceptor-ref>
                <interceptor-ref name="restDefaultStack"></interceptor-ref>
            </interceptor-stack>

        </interceptors>
        <global-results>
            <result name="redirectAction" type="redirect">${actionChainUrl}</result>
            <result name="exception"   type="tiles">commons/general/UnhandledException</result>
            <result name="error"      type="tiles">commons/general/Error</result>
            <result name="serverManagerWelcome"    type="tiles">ServerManagerWelcome</result>
            <result name="redirectURL" type="tiles">${actionChainUrl}</result>
            <result name="genericPartnerSearch" type="tiles">_${actionChainUrl}</result>
            <result name="redirectUploadReport" type="tiles">${actionChainUrl}</result>
            <result name="dispatchView" type="tiles">${actionChainUrl}</result>
            <result name="subtableurl">${actionChainUrl}</result>

        </global-results>

        <global-exception-mappings>
            <exception-mapping result="exception" exception="java.lang.Throwable"></exception-mapping>
            <exception-mapping result="exception" exception="java.lang.RuntimeException"></exception-mapping>
        </global-exception-mappings>


    </package>
  
    <package name="pd" namespace="/pd/*" extends="sm"/>
</struts>
{code}
tiles.xml located at WEB-INF folder

 

 
{code:java}
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

<definition name="ServerManagerWelcome" template="/view/sm/BaseSidebarSM.jsp">
<put-attribute name="title" value="Server Manager"/>
<put-attribute name="header" value="/view/commons/general/ServerManagerHeader.jsp"/>
<put-attribute name="leftSide" value="/view/commons/general/SideMenu.jsp"/>
<put-attribute name="rightSide" value="/view/commons/general/ServerManagerWelcome.jsp"/>
<put-attribute name="footer" value="/view/commons/general/Footer.jsp" />
</definition>

<definition name="REGEXP:sm/(.*)/(.*)/(.*)" extends="ServerManagerWelcome">
<put-attribute name="rightSide" value="/WEB-INF/content/sm/{1}/{2}-{3}.jsp"/>
</definition>

<definition name="REGEXP:(.*)/(.*)/(.*)_(.*)" extends="Welcome">
<put-attribute name="body" value="/view/{1}/{2}/{3}{4}.jsp"/> 
</definition>


<definition name="REGEXP:commons/general/(.*)" extends="Welcome">
<put-attribute name="body" value="/view/commons/general/{1}.jsp"/> 
</definition> 

<definition name="loginLayout" template="/view/commons/login/LoginBase.jsp" >
<put-attribute name="body" value="/view/commons/login/Login.jsp"/>
<put-attribute name="footer" value="/view/commons/general/Footer.jsp" />

</definition>

</tiles-definitions>
{code}
My Group CTRL 

 

 
{code:java}
//package com.elitecore.nvsmx.sm.controller.group;

import com.elitecore.corenetvertex.pkg.constants.ACLModules;
import com.elitecore.corenetvertex.sm.acl.GroupData;
import com.elitecore.nvsmx.sm.controller.DestroyNotSupportedCTRL;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import static com.opensymphony.xwork2.Action.SUCCESS;

/**
 * Created by aditya on 8/2/17.
 */

@ParentPackage(value = "sm")
@Namespace("/sm/group")
@Results({
        @Result(name= SUCCESS, type="redirectAction",params = {"actionName","group"})
})
public class GroupCTRL extends DestroyNotSupportedCTRL<GroupData> {

    @Override
    public ACLModules getModule() {
        return ACLModules.GROUP;
    }

    @Override
    public GroupData createModel() {
        return new GroupData();
    }
public HttpHeaders create() { // create
    if(LogManager.getLogger().isDebugLogLevel()){
        LogManager.getLogger().debug("Creating group");
    }
    return new DefaultHttpHeaders(SUCCESS);
    }
}

    @Override
    public void validate() {
        if(///for any reason this validation goes fail & action error added ){
            addActionError("Invalid User");
        }
        super.validate();
    }
}



{code}
>From create group page when i submit the page & validation goes fail & for action
error added 

then redirected page is not page i.e. page without css.

 

 

> Struts 2 REST Tiles integration issue
> -------------------------------------
>
>                 Key: WW-4944
>                 URL: https://issues.apache.org/jira/browse/WW-4944
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - REST
>    Affects Versions: 2.3.34
>            Reporter: aditya shrivastava
>            Priority: Major
>              Labels: tiles
>             Fix For: 2.6
>
>         Attachments: After validation.png, before validation create page.png
>
>
> I have integrated Tiles framework with struts 2 REST plugin.
> issue occur when server side validation fails, Whenever any actionError or fieldError
added in validate method. Non Tiles result return i.e. result after validation fails doesn't
come to tiles again.
> Due to this whole look & feel of  UI fails.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message