Hi,

        Note: An exploded war is a web application deployed as a directory
in the file system instead of as anarchive file.

        Note: As this involves passing data between different web
applications, we can not pass the data directly as java objects of
application classes. Presumably because the classes are loaded by different
class loaders, this resultsin a ClassCastException. Passing core java
classes like String etc seems to work. What I have done below is to
serialize the object to a byte[] and pass this in the request object.

    In my project, the image manager app is created as follows:

    In the JBOSS installation directory,
        1. create a <context>.war directory under
<JBOSS>/server/<config>/deploy, say "imageManager.war"
        2. create a WEB-INF directory under the above directory
        3. create a web.xml in this directory to specify a single servlet,
e.g.

        <web-app>
                <servlet>
                        <servlet-name>upload</servlet-name>
        
<servlet-class>com.acme.servlets.ImageManager</servlet-class>
                        <load-on-startup>2</load-on-startup>
                </servlet>
                <servlet-mapping>
                        <servlet-name>upload</servlet-name>
                        <url-pattern>/upload</url-pattern>
                </servlet-mapping>
        </web-app>

        4. create a servlet named as above. Some sample code shown below
        
                ...
                byte[] imageCommandAsBytes = (byte[])
request.getAttribute(ApplicationConstants.IMAGE_COMMAND);
                ByteArrayInputStream baIS = new
ByteArrayInputStream(imageCommandAsBytes);
                ObjectInputStream oIS = new ObjectInputStream(baIS);
                ImageCommand imageCommand = (ImageCommand) oIS.readObject();
                String realPath =
getServletContext().getRealPath(imageCommand.getRelativePath());
              if (imageCommand.getActionToDo() ==
ImageCommand.ACTION_CREATE_REPLACE)
        {
                String directoryPath = realPath.substring(0,
realPath.lastIndexOf(File.separatorChar));
                File directory = new File(directoryPath);
                directory.mkdirs();
                FileOutputStream fOS = new FileOutputStream(realPath);
                fOS.write(imageCommand.getImageData());
                fOS.close();
                }
              else
        {
                File file = new File(realPath);
                file.delete();
              }
                ...

        5. In your main application, when you need to store the file, use
RequestDispatcher to invoke the above servlet, after saving the relevant
information in the request object.

                ...
                request.setAttribute(ApplicationConstants.IMAGE_COMMAND,
imageCommandAsBytes);
              Context context = new InitialContext();
              String directoryContext = null;

        try
              {
          directoryContext = (String)
context.lookup("java:/comp/env/directoryContext");

                if (directoryContext == null)
            directoryContext = "/directory";
              }
              catch (NameNotFoundException ex)
        {
                directoryContext = "/directory";
        }

        
request.getSession().getServletContext().getContext(directoryContext)
               .getRequestDispatcher("/upload").include(request, response);
                ...             

        6. Reference the images in the web pages for the main application
from the imageManager context

                ...
                <IMG SRC="/imageManager/blahblah/blahblah.gif" />
                ...
  

Cheers,
Krishna 

-----Original Message-----
From: Niket Anand [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 02, 2003 5:46 PM
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Deploying images dynamically


Hello Krishnakumar,
Thanks for replying back..
I need more help regarding the same.
I am using Cocoon with Tomcat and integrated with JBoss. I think the same
concept should be applied here also as you have done it for JBoss-Jetty.
May be I need more clarification regarding ur mail.
I have one application running at server side with following contents:-
ear file:- npi.ear(containing application.xml, npi.jar(for EJB),
npi.war(containing Cocoon servlet and XSP,XSL, images,js,css etc)
content of application.xml is
<?xml version="1.0" encoding="ISO-8859-1"?>
<application>
<display-name>My application</display-name>
<module>
<web>
<web-uri>npi.war</web-uri>
<context-root>/npi</context-root>
</web> 
</module>
<module>
<ejb>npi.jar</ejb>
</module>
</application>
You are talking about making another war file that contain servlet to manage
images. I am using only Cocoon servlet for whole application and I am
generating images using this servlet only. 
So How can I configure new war file? what should it contain? and It manages
the new generated images.
Can you send me an example for configuring this with ear /war and
application.xml?
Thanks, waiting for ur reply..
Niket 

----- Original Message ----- 
From: Krishnakumar N 
To: [EMAIL PROTECTED] 
Sent: Thursday, January 02, 2003 5:08 PM
Subject: RE: [JBoss-user] Deploying images dynamically


Hi,

I use JBOSS-Jetty and I have done this by having an ear file for the
packaged web application(s) and another web application deployed as a
'exploded' war. This second web aplication is there purely to manage
additions and deletions of images, it has just one servlet to manage these
operations. The pages in the primary web application reference the images
thru document root relative path, rather than context relative path. 

The way 'exploded' wars are created is by creating a directory
"<context>.war" under the ../server/<config>/deploy directory of
JBOSS-Jetty. I am not sure if this works the same way in JBOSS-Tomcat.

Cheers,
Krishna
-----Original Message-----
From: Niket Anand [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 02, 2003 4:14 PM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] Deploying images dynamically


Hello All,
I made war and jar files in a combined ear file and deployed that ear file
in deploy folder(JBoss-2.4.7_Tomcat-4.0.4).
I have some scenario where some of the images are made dynamically. so How
can I integrate that new generated images with ear file so that server can
understand that images?
Please help me and reply asap.
Thanks,
Niket


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to