Re: Issue adding filter to struts2-archetype-starter project

2020-05-09 Thread James Chaplin
Hello Jonathan.

 As the other replies have pointed out, your code is using/extending 
"import java.nio.file.DirectoryStream.Filter;".  That is an import for a file 
directory filter, and not a servlet filter.

 You will want to replace the old import statement with "import 
javax.servlet.Filter;" instead.

 Some general background on Java Servlets can be found at 
https://docs.oracle.com/javaee/7/tutorial/servlets006.htm#BNAGB or
https://www.oracle.com/java/technologies/filters.html , which might be of 
interest.

 If you type "java tutorial servlet filter" into your favourite search 
engine you should find some results that can help you out with writing a 
servlet filter.

 Hope that helps.

Regards,

 James.

On 2020/05/05 16:13:47, M Huzaifah  wrote: 
> Eyou should use interface Filter in servlet package. Not from nio package
> 
> On Tue, May 5, 2020, 22:40 Dave Newton  wrote:
> 
> > `import java.nio.file.DirectoryStream.Filter` is not a servlet filter.
> >
> > Dave
> >
> 

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



Re: Issue adding filter to struts2-archetype-starter project

2020-05-05 Thread M Huzaifah
Eyou should use interface Filter in servlet package. Not from nio package

On Tue, May 5, 2020, 22:40 Dave Newton  wrote:

> `import java.nio.file.DirectoryStream.Filter` is not a servlet filter.
>
> Dave
>


Re: Issue adding filter to struts2-archetype-starter project

2020-05-05 Thread Dave Newton
`import java.nio.file.DirectoryStream.Filter` is not a servlet filter.

Dave


Re: Issue adding filter to struts2-archetype-starter project

2020-05-04 Thread Lukasz Lenart
Do you see any errors while you starting Tomcat?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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



Issue adding filter to struts2-archetype-starter project

2020-05-04 Thread Jonathan Hill

Hello,

In order to study/practice using struts 2, I am using a the 
struts2-archetype-starter maven archetype.


I've come across a problem trying to add my own filter, and was hoping 
someone could point me in the right direction.


I'm using eclipse with maven for my build process, and Tomcat 8.5 as a 
localhost server.



I have been able to set up some basic actions. I am now trying to add a 
filter to set the encoding of requests, so that I can handle Japanese 
input. To do this, I referenced this resource about filters, to create 
my own custom filter, which I reference in the web.xml file of my project


Filters reference source: 
https://www.oracle.com/java/technologies/filters.html


However, when I try to access my project's url, I get a 404 error.

I've tried adding breakpoints to my filter and debugging the project on 
the server, but the breakpoint is never hit. (I am able to debug and use 
breakpoints otherwise)


To my web.xml file I have added the filter declaration:

    
        MyEncoder
jono_group.mav_arch_2.filters.MyChaEnFilter
        
            encoding
            Shift_JIS
        
    


and this filter mapping

    
        MyEncoder
        /*
    

They are positioned infront of all the other filters and filter-mappings 
respectively, with the intention that it will executed at the front of 
the filter chain.


With the above filter and filter-mapping, the maven build (clean package 
runs successfully, reporting no errors. But I get the 404. As soon as I 
remove both of them, the 404 error goes away and my actions work as 
expected.


Any help would be greatly appreciated.

My filter class is as follows:

package jono_group.mav_arch_2.filters;

import java.io.IOException;
import java.nio.file.DirectoryStream.Filter;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyChaEnFilter implements Filter
{

    private FilterConfig filterConfig = null;
    private String encoding;

    public void doFilter(ServletRequest request,
    ServletResponse response, FilterChain chain) throws
    IOException, ServletException {
        String encoding = selectEncoding(request);
        if (encoding != null)
        request.setCharacterEncoding(encoding);
        chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws
    ServletException {
        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
    }

    protected String selectEncoding(ServletRequest request) {
        return (this.encoding);
    }

    public void destroy() {
        this.filterConfig = null;
    }

    @Override
    public boolean accept(Object entry) throws IOException {
        // TODO Auto-generated method stub
        return false;
    }
}

Regards,

Jonathan



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