Solved

Problems retrieving a file uploaded through a web service

Posted on 2011-03-25
4
256 Views
Last Modified: 2012-06-27
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
Comment
Question by:Emilie
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
you want mention apsolutae path not relative path ??

can you post the code
0
 

Author Comment

by:Emilie
Comment Utility
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
 
LVL 20

Accepted Solution

by:
Sathish David  Kumar N earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:Emilie
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
userCompare  challenge 3 61
noX challenge 17 76
strCopies  challenge 17 73
Which is the latest version of Apache Tomcatl 3 35
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now