Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Problems retrieving a file uploaded through a web service

I have a web service that uploads a few files to the server.   The service uses Glassfish V3.  The folder and files it creates can be found in my domain folder in the Netbeans config/GF3 folder.  When I try to read that file afterwards from my web application (which contains the web service), or from any other web application using the same server and domain, I get a "resource not available" message.  What am I doing wrong?

For example, my web service operates from this url :
http://localhost:8080/WS/resources/errorRetriever

and is told to write to errors/

Say my file is test.txt, none of these paths gets me to the file that was written:
http://localhost:8080/WS/resources/errorRetriever/errors/text.txt
http://localhost:8080/WS/resources/errors/text.txt
http://localhost:8080/WS/errors/text.txt
http://localhost:8080/errors/text.txt

I am using Netbeans 6.9.1 and J2EE to develop this application.
0
Emilie
Asked:
Emilie
  • 2
  • 2
1 Solution
 
Sathish David Kumar NCommented:
you want mention apsolutae path not relative path ??

can you post the code
0
 
EmilieAuthor Commented:
The code below shows the steps I take to save the file from the web service.  I also save a copy of the path to each file to my database.

The second part is in a different application (running with the same server, and associated to the same domain).  I only included the method that tries to retrieve the path.

The method getPath() returns the path stored in my database.  In this case for instance, it will return :
C:\Users\...\.netbeans\6.9\config\GF3\domain1\errors\dev341557169\dev341557169.jpg

If I put that directly in my browser, the file will open correctly.  But the image won't show in my page.  Any anchor tag pointing to it will also not prompt any action from the browser.

I have also tried storing the relative path, in which case I get something like:
errors\dev341557169\dev341557169.jpg

This also doesn't work.

Right now I'm testing on a pc, with a local server.  I don't know if I would encounter the same problem once it's deployed to an actual server. (I don't have access to a staging environment yet).
@Path("errorRetriever")
public class ErmResource {
public static final String ERROR_RESPOSITORY = "errorReports\\";
[...]

@POST
@Produces("text/plain")
public String loadFile(@Context HttpServletRequest request) {
[...]
     try {
       RESTwsEJBRemote wsEJB = (RESTwsEJBRemote) new InitialContext().lookup("ejb/wsEJB");
[..]
       zipFile = new File(fileRepository + fileName);
[..]

try {
   if (zipFile.getPath().lastIndexOf("\\") != -1 && !zipFile.exists()) {
        new File(zipFile.getPath().substring(0, zipFile.getPath().lastIndexOf("\\"))).mkdirs();
     }
     item.write(zipFile);
            return true;
} catch (Exception e) {
     return false;
}

}

***************

public class RetrieveDetailedError extends AJAXAction {

[...]
public String createAttachments(int appId, String errorUID) throws Exception {
        String html = "";
        try {
            int errorId = searchEJB.getErrorId(errorUID);
            List<Attachment> attchmnts = searchEJB.getAttachments(errorId, " not in ('image')");
            String screenshot = "";
            String logs = "";
            String others = "";

            html += "<div class='trigger'>";
            html += "<div class='sectionTitle' id='mouseover'><img class='expand' src='../images/collapsed.png' align='left'/>";
            html += "<p>Attachments</p></div></div>";
            html += "<div class='toggle_container'>";
            html += "<div class='block'><p>";

            if (!attchmnts.isEmpty()) {
                Iterator itr = attchmnts.iterator();
                while (itr.hasNext()) {
                    Attachment attchmnt = (Attachment) itr.next();
                    int i = 1;
                    String name = findAttachmentName(attchmnt.getpath());
                    if (name.length() < 2) {
                        name = attchmnt.getpath();
                    }

                    if ("log".equalsIgnoreCase(attchmnt.getType())) {
                        logs += "<a class='default' href='" + attchmnt.getpath() + "'>" + name + "</a><br/>";
                    } else if ("image".equalsIgnoreCase(attchmnt.getType())) {
                        screenshot += "<a class='default' href='" + attchmnt.getpath() + "'>Image" + i + "</a><br/>";
                        i++;
                    } else {
                        others += "<a class='default' href='" + attchmnt.getpath() + "'>" + name + "</a><br/>";
                    }

                }

                if (screenshot.length() > 1) {
                    html += "<p><b>Screenshot</b><br/><br/>" + screenshot + "</p>";
                }

                if (logs.length() > 1) {
                    html += "<p><b>Logs</b><br/><br/>" + logs + "</p>";
                }

                if (others.length() > 1) {
                    html += "<p><b>Other Attachments</b><br/><br/>" + others + "</p>";
                }

                html += "</p></div>";
                html += "<img class='bottom' src='../images/tabBoxBottom.png'/></div>";
                html += "<img class='bottomShadow' src='../images/tabShadowBottom.png' />";
            }

        } catch (Exception e) {
            throw e;
        }
        return html;
    }
[...]
}



}

Open in new window

0
 
EmilieAuthor Commented:
Thanks, these links were pretty useful.  Ended up solving my problem by saving the file using the Servlet Context but recording its location in the database using the URI context.  I was thus able to retrieve the files from another web app.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now