• Welcome to KonaKart Community Forum. Please login or sign up.
 

Absolute Image URLs - How to?

Started by kv, June 06, 2008, 12:29:42 pm

Previous topic - Next topic

kv

Hi,

Is there a way to force Konakart to look for product, subcategory, manufacturer, etc. images at a location other than its own context/images?

Let's say that I want to upload all my images independently, and perhaps to a different virtual/actual host. Or maybe I already have an image repository and I would like to point Konakart to that location.

I am guessing that 'Image Base URL' configuration option available in Konakartadmin applies only to the admin app itself and not to how Konakart resolves image URLs.

Of course, I can mount some form of a proxy servlet in Konakart at '/images/myapp' to fetch the images, but is there a configuration solution?

Thanks,
kv.

pete

Hi,

The Image Base URL of the admin app is set so that the images can be viewed from the admin app, because they normally reside in a different webapp (i.e. the application webapp).

The location of each image is specified in the JSP when displayed <img  src="images/table_background_cart.gif" etc. . For the language dependent images the code looks something like this <input type="image" src="images/<bean:message key="language.dir"/>/buttons/button_checkout.gif" since the images are stored within different language directories. All image paths are relative to the context and aren't configurable at the moment.

The proxy servlet sounds like an interesting solution.

-Pete

kv

Hi Pete,

Thought as much.

I already mounted a servlet to do a cross-context dispatch for my images, but it would have been nice to avoid that round trip.

Thanks,
kv.

nickgk

Hello,

I was about to post asking about this very same issue. KV, could you please elaborate a little on your 'crosss-context dispatch' solution?

Many Thanks,
Nick

kv

Hi,

Sorry, I thought this thread was closed so I stopped watching it.

Yes, certainly.

First let me explain that the cross-context dispatch was a suitable solution for my requirements, because my image repository was deployed on another webapp running on the same servlet container instance. This quick solution would not have worked if my images had been on another container instance. In such a situation, you really would have to use/create some sort of http proxy servlet.

If your images are also on another web context in the same servlet container, then this is one way to get to your images.

Create a servlet something like this:

public class MountServlet extends HttpServlet {
    private String imageAppContext = "/myImageContext";  //the webapp context of your images

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        RequestDispatcher dispatcher = context.getContext(imageAppContext )
                    .getRequestDispatcher(request.getPathInfo());
        dispatcher.forward(request, response);
    }
}


Obviously you'll need to package your servlet in a jar and put the jar in konakart/WEB-INF/lib
You then need to deploy your servlet.
Add the servlet declaration and mapping to konakart/WEB-INF/web.xml, where elements of the same type appear.


  <servlet>
      <servlet-name>Mount Servlet</servlet-name>
      <servlet-class>
          com.domain.MountServlet
      </servlet-class>
  </servlet>


  <servlet-mapping>
      <servlet-name>Mount Servlet</servlet-name>
      <url-pattern>/images/*</url-pattern>
  </servlet-mapping>



You may also need to configure your servlet container to allow cross-context lookups. In tomcat you can do this by adding the attribute 'crossContext=true' to the default context element in tomcat/conf/context.xml
Note: this will affect all webapps on this tomcat instance.

<Context crossContext="true">
    .....
</Context>


Hope it helps.

kv.

kv

Just for accuracies' sake, the servlet code was missing a line:


public class MountServlet extends HttpServlet {
    private String imageAppContext = "/myImageContext";  //the webapp context of your images

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletContext();
        RequestDispatcher dispatcher = context.getContext(imageAppContext )
                    .getRequestDispatcher(request.getPathInfo());
        dispatcher.forward(request, response);
    }
}


Also, bare in mind that you can adapt this code to prefix a configured sub-path to pathInfo before acquiring the dispatcher. This would allow you to mount a subdirectory of your external webapp within the host webapp (Konakart, in this case).



public class MountServlet extends HttpServlet {
    private String imageAppContext = "/myImageContext";  //the webapp context of your images
    private String mountPoint = "/resources/images/products";  //the subdirectory of the webapp to mount

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletContext();
        RequestDispatcher dispatcher = context.getContext(imageAppContext )
                    .getRequestDispatcher(mountPoint + request.getPathInfo());
        dispatcher.forward(request, response);
    }
}



kv.

kv


One other point is that, in my deployment, all of Konakart's images are also in my content repository (so that they can be changed via the CMS).

If you only want to access your own images from another webapp, then you would need to change your servlet mapping a little:

  <servlet-mapping>
      <servlet-name>Mount Servlet</servlet-name>
      <url-pattern>/images/myimages/*</url-pattern>
  </servlet-mapping>


So now, to configure the image in Konakartadmin, you would use: myimages/path/to/image.gif

ReneA