struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Zepernick <Paul.Zepern...@healthsmart.com.INVALID>
Subject RE: NPE when running unit test with struts rest plugin
Date Mon, 09 Nov 2020 13:38:02 GMT
Thank you very much, this has resolved the issue!  I have created a ticket in Jira.

https://issues.apache.org/jira/browse/WW-5095

Paul R Zepernick | Sr Programmer Analyst
HealthSmart
paul.zepernick@healthsmart.com | www.HealthSmart.com

-----Original Message-----
From: Lukasz Lenart <lukaszlenart@apache.org>
Sent: Saturday, November 7, 2020 8:51 AM
To: Struts Users Mailing List <user@struts.apache.org>
Subject: Re: NPE when running unit test with struts rest plugin

NOTICE: This email originated from outside of the organization. Do not click links or open
attachments unless you recognize the sender and know the content is safe.

śr., 4 lis 2020 o 17:29 Paul Zepernick
<Paul.Zepernick@healthsmart.com.invalid> napisał(a):
> I have posted an example project that reproduces the error in the
> junit test
>
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> ub.com%2Fzepernick%2Fstruts25-rest-junit&amp;data=04%7C01%7CPaul.Zeper
> nick%40healthsmart.com%7C51b18c36edb9455e56dc08d8832422d3%7C2ce547c5e8
> 0a40628a56f25adceefb52%7C0%7C0%7C637403538520826158%7CUnknown%7CTWFpbG
> Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%
> 3D%7C1000&amp;sdata=R67dd6goXC0LKd7SiGGclmYcU0rsUDn1i53CyzjLmVw%3D&amp
> ;reserved=0

I think I have found the problem, mapping is not set in getActionProxy(), you can fix it by
overriding it like this:

    protected ActionProxy getActionProxy(String uri) {
        request.setRequestURI(uri);
        ActionMapping mapping = getActionMapping(request);
        String namespace = mapping.getNamespace();
        String name = mapping.getName();
        String method = mapping.getMethod();

        Configuration config = configurationManager.getConfiguration();
        ActionProxy proxy =
config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
                namespace, name, method, new HashMap<String,
Object>(), true, false);

        initActionContext(proxy.getInvocation().getInvocationContext());

        // this is normally done in onSetUp(), but we are using Struts internal
        // objects (proxy and action invocation)
        // so we have to hack around so it works
        ServletActionContext.setServletContext(servletContext);
        ServletActionContext.setRequest(request);
        ServletActionContext.setResponse(response);

        ServletActionContext.getContext().put(ServletActionContext.ACTION_MAPPING,
mapping);

        return proxy;
    }

Fee free to open a JIRA ticket and as I'm going to prepare yet another 2.5.x release I can
address this issue


Regards
--
Łukasz
+ 48 606 323 122
+ https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.l
+ enart.org.pl%2F&amp;data=04%7C01%7CPaul.Zepernick%40healthsmart.com%7C
+ 51b18c36edb9455e56dc08d8832422d3%7C2ce547c5e80a40628a56f25adceefb52%7C
+ 0%7C0%7C637403538520826158%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDA
+ iLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=jWn%2
+ B4tFUL53LvuprGz8l6bNEMWrX8d1FMLqlR1m5tJI%3D&amp;reserved=0

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

Disclaimer: This communication and any files transmitted with it may contain information that
is privileged, confidential and/or exempt from disclosure under applicable law. If you are
not the intended recipient, you are hereby notified that any disclosure, copying, distribution,
or use of the information contained herein (including any reliance thereon) is strictly prohibited.
If you received this communication in error, please immediately contact the sender and destroy
the material in its entirety, whether in electronic or hard copy format. Thank you.
Mime
View raw message