• Welcome to KonaKart Community Forum. Please login or sign up.
 
May 28, 2024, 04:24:52 pm

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - kv

1

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
2
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.
3
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.
4
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.
5
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.