implement support for HEAD request
-igor
On Sat, May 31, 2008 at 3:54 AM, Mathias P.W Nilsson
<[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I have this servlet that is called from wicket only using a url
> /Files/thefile.jpg
> The servlet is url-mapped on /Files/*. But it is very slow and I was just
> wondering could this be done in a better way
>
> package se.edgesoft.hairless.web.resource;
>
> import java.io.DataInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
>
> import javax.servlet.ServletConfig;
> import javax.servlet.ServletContext;
> import javax.servlet.ServletException;
> import javax.servlet.ServletOutputStream;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> import org.springframework.web.context.support.WebApplicationContextUtils;
>
> import se.edgesoft.hairless.application.HairlessApplicationSettings;
>
> /**
> * Resource servlet for getting images and flash movies
> * @author Mathias Nilsson
> *
> */
> public class FileResourceServlet extends HttpServlet {
> private static final long serialVersionUID = 1L;
> private static ServletConfig config;
>
>
> protected Object getBean(String name) {
> Object obj =
> WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()).getBean(name);
> return obj;
> }
> public void destroy() {
> config = null;
> }
>
> public ServletConfig getServletConfig() {
> return config;
> }
>
> public String getServletInfo() {
> return "Resource servlet for Hairless";
> }
>
> public void init(ServletConfig servletConfig ) throws ServletException {
> config = servletConfig;
>
> }
>
> public HairlessApplicationSettings getHairlessApplicationSettings(){
> return (HairlessApplicationSettings)getBean(
> "hairlessApplicationSettings" );
> }
>
> @Override
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> try {
> File file = new File(
> getHairlessApplicationSettings().getFileResourcePath() ,
> request.getRequestURI().replace( request.getContextPath(), "" ) );
> int length = 0;
> ServletOutputStream op = response.getOutputStream();
> ServletContext context =
> getServletConfig().getServletContext();
> String mimetype = context.getMimeType(
> file.getAbsolutePath() );
> response.setContentType( (mimetype != null) ? mimetype :
> "application/octet-stream" );
> response.setContentLength( (int)file.length() );
>
> byte[] bbuf = new byte[1024];
> DataInputStream in = new DataInputStream(new
> FileInputStream(file));
>
> while ((in != null) && ((length = in.read(bbuf)) != -1))
> {
> op.write(bbuf,0,length);
> }
>
> in.close();
> op.flush();
> op.close();
>
> } catch (Exception e) {
> }
> }
>
>
> }
>
> --
> View this message in context:
> http://www.nabble.com/Resource-servlet-from-wicket-tp17574070p17574070.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]