Open a local file from a web Service

Hello!
Likely this is a trivial question, but I need to open a local file from a Web Service and i don't know how to get the file path. I mean that I have a WS source code placed in a proper package (my.ws.package) with an additional configuration XML file placed in the same directory. I need to read it, but if I use merely
File conf = new File("Conf.xml");it can't find it. I've tryed with:
MyWS.class.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()in order to get the file path, but a
java.security.AccessControlException access denied (java.lang.RuntimePermission getProtectionDomain)arises...
I don't know...
Suggestions?
Thanks.
Anhur

Hello!
Likely this is a trivial question, but I need to open a local file from a Web Service and i don't know how to get the file path. I mean that I have a WS source code placed in a proper package (my.ws.package) with an additional configuration XML file placed in the same directory. I need to read it, but if I use merely
File conf = new File("Conf.xml");it can't find it. I've tryed with:
MyWS.class.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()in order to get the file path, but a
java.security.AccessControlException access denied (java.lang.RuntimePermission getProtectionDomain)arises...
I don't know...
Suggestions?
Thanks.
Anhur

Similar Messages

  • Opening a PPT file from a Web Application

    Hi,
    I want to open a PPT file from my web application.
    I have provided an hyperlink of the complete path of the file. Once the user clicks on this hyperlink the PPT shall open.
    Kindly help me out with this.
    Thanks.

    Sounds like you're done. What happens when the user clicks the link?

  • How to open a local file from javascript in a jsp-page

    Hi
    I have created an iview from a PAR file. In the par file I have a jsp-page with some javascript code. From the javascript coe I want to open a new window with an Excel file.
    I have tried window.open("c:
    test.xls", "test_window"), but it doesn't seem to work. I have created a small HTML page locally with the same command and there a new window opens with the Excel file.
    If I change the local file path with an URL it also works.
    Any idea how to open a local file ?
    Thanks
    /Jakob

    Jacob,
    I'm not 100% (but 99,9%) and it has to do with security ristrictions of the browser not allowing to have local workstation interation from the web. This is ofcourse very dangerous if the browser would allow it... So therfore it is blocked. What if somone would point to a file/executable that formats your drive so for that reason it is not allowed to have web interaction with a local file. Only with Java Applets this is possible but still with many limitations, and what I remember Google Gears and Adobe Air do have some limited web 2 local file interaction... So best and most simple solution you are left with is pointing to a url instead of a file on a c:\ drive.
    PS The reason why it works when you start the html from your local PC has todo with the fact that the browser detects that the html is not running in the web at that moment therefor allowing the access.
    Cheers,
    Benjamin Houttuin

  • Open a Local file from JSP

    Hi All,
    I want to access a local file from a JSP. On click of the link the local file should open. The location of the local file is
    O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
    and the hyper link on the JSP shows
    file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
    somehow the file does not open from the JSP page but it opens from the browser if I type
    'file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc' in the address bar.
    Can anybody please help.
    regards,
    Shardul.

    if you'd like to show the real path to the user, use simply an ftp server !
    however, if you prefer a secure solution, so use a servlet:
    example:
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class SendWord extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
        //get the 'file' parameter
        String fileName = (String) request.getParameter("file");
        if (fileName == null || fileName.equals(""))
          throw new ServletException(
              "Invalid or non-existent file parameter in SendWord servlet.");
        // add the .doc suffix if it doesn't already exist
        if (fileName.indexOf(".doc") == -1)
          fileName = fileName + ".doc";
        String wordDir = getServletContext().getInitParameter("word-dir");
        if (wordDir == null || wordDir.equals(""))
          throw new ServletException(
              "Invalid or non-existent wordDir context-param.");
        ServletOutputStream stream = null;
        BufferedInputStream buf = null;
        try {
          stream = response.getOutputStream();
          File doc = new File(wordDir + "/" + fileName);
          response.setContentType("application/msword");
          response.addHeader("Content-Disposition", "attachment; filename="
              + fileName);
          response.setContentLength((int) doc.length());
          FileInputStream input = new FileInputStream(doc);
          buf = new BufferedInputStream(input);
          int readBytes = 0;
          while ((readBytes = buf.read()) != -1)
            stream.write(readBytes);
        } catch (IOException ioe) {
          throw new ServletException(ioe.getMessage());
        } finally {
          if (stream != null)
            stream.close();
          if (buf != null)
            buf.close();
      public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
        doGet(request, response);
    }hope that helps

  • Reading XML file from java web service

    Hi
    I am developing web service using Netbeans and the application server is glassfish.
    but I am facing a problem
    I have folder called "config" which will include the xml files. What I need to do setting path into that folder
    but it will read from another location when I am deploying it
    How to set our own path ?
    Error
    DPL5306:Servlet Web Service Endpoint [NewWebService] listening at address [http://kapila.epic.lk:8080/WebApplication2/NewWebServiceService]
    deployed with moduleid = WebApplication2
    java.io.FileNotFoundException: /root/MyWorks/glassfish-v2/domains/domain1/config/OSconfig/MConfig.xml (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    My "conifg" folder, i have put in to working directory but it will read from "/root/MyWorks/glassfish-v2/domains/domain1/config/OSconfig/MConfig.xm"
    below method is used for getting its contain value
    public String getMainCofig() {
                String v ="";
            try{
              DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
                        .newInstance();
              DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
              Document doc = docBuilder.parse(new File("OSconfig/MConfig.xml"));
              doc.getDocumentElement().normalize();
              NodeList listOfSPRMs = doc.getElementsByTagName("MainConfig");
              Node firstSPRMNode = listOfSPRMs.item(0);
              if (firstSPRMNode.getNodeType() == Node.ELEMENT_NODE) {
                   Element firstSPRAMElement = (Element) firstSPRMNode;
                   // Getting platform
                   NodeList server_port = firstSPRAMElement
                             .getElementsByTagName("RunningPlatform");
                   Element server_port_el = (Element) server_port.item(0);
                   NodeList server_port_List = server_port_el.getChildNodes();
                    v= ((Node) server_port_List.item(0))
                             .getNodeValue().trim();
            }catch (Exception e){
            e.printStackTrace();
                    return v;
    Regards
       

    I didn't quite get what the problem is but if the the desired file is in custom directory why don't you just use absolute path to reference it?
    Like: "/home/my/OSconfig/MConfig.xml"

  • Accessing a configuration file from a Web Service

    I have a business logic class that loads in a file of records and then has various searching methods provided. The way that it is currently used is via a servlet that has one parameter in the web.xml file that is the location of the properties file. This servlet creates a Configuration singleton by passing the location from the web.xml. The Configuration singleton reads in the properties file. The business logic class gets the location of the record file from the Configuration singleton to then read it in. I am trying to wrap this business logic class with a web service now and am not sure how to go about initializing the Configuration singleton without hardcoding the location of the properties file.
    Can anyone tell me what the best method of reading in configuration items from within a web service (i.e. an equivalent to the servlet web.xml method)? Where in the EAR or WAR should this properties file be located and then how do you get to it? I am using WebLogic 8.1 and creating the web service with the WebLogic Ant tasks (servicegen, wspackage, clientgen, etc.).
    Thanks,
    Adam

    okay, so actually, was attributing my problem to the wrong thing. in fact, another coding error (the way i was reading lines from the buffered reader) is to blame. turns out you CAN read from a file in the init or the doGet...
    bear with me, i'm just learning but anybody able to tell me why i can't trigger a FileNotFoundException here, even if i pass the FileReader a file that doesn't exist:
    try {
    BufferedReader r = new
    BufferedReader(new FileReader("???"));
    String s = r.readLine();
    int i=1, j=0;
    while (s != null) {
    if (i%2==0) {
    mailInfo[j] = s;
    j++;
    s = r.readLine();
    i++;
    catch (FileNotFoundException e) {
    e.printStackTrace();
    catch (IOException e) {
    e.printStackTrace();
    }

  • Is there a way to open a local file not a web file with actionscript 3.0?

    Reason for asking is because I am making a media player in Adobe Flash CS6, and was wondering if there was anyway to make a button to open a local .fla file in a directory with ActionScript 3.0 or if there are any other ways I can achieve this?
    Thanks Casey

    with an air app, check the file class.  otherwise, check the filereference class.

  • Use installshield to create setup file from mvc web service

    I need help from gurus :)
    I have an mvc web service and I need to create a setup package with installshield but I don't know how to do it.
    I want create setup to install at another machine (under IIS)
    Can someone help me please?
    Thanks in advance.

    Hello,
    Welcome to MSDN forum.
    Your issue is out of support range of VS General Question forum which mainly discusses
    the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    Because you want to use InstallShield which we don't provide support, I suggest you to consult your issue on InstallShield forums for better support.
    Thanks,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I cannot view PDF in Firefox at the first time but once I manually open the PDF file from my local computer, I can view other PDF files via Firefox webbrowser

    I install Adobe Acrobat 9 in my laptop which runs on windows 7. I use Firefox 3.6.8 and have the problem with the PDF file. The problem is I cannot open the PDF file in Firefox web browser at the first time I launch firefox. It shows a warning box without any message. Only OK button is shown so I can close it. However, if I manage to open the PDF file from my local computer by just using adobe acrobat itself then the PDF can be opened in the Firefox web browser. I followed the instruction on the mozilla help but nothing works for me. The problem still exists. I wonder if anyone have the same problem like me and know how to solve this. Thank you so much

    Hi there!
    I cannot help you, but I think we have a common problem: We got a system here running Vista SP1 with Acrobat 9 standard on it. When we open a pdf file it works normally, but when we open another pdf file, we see the first one in that second window.
    Think that missing option to watch several files within a single window-thing messed up more than meets the eye ... but as we just purchased the 15 licenses, we have to use version 9.
    I didn't find any clues on this problem, but I will post any new hints I get.

  • With OSX10.7.5 and Adobe Reader 11.0.02 when I try to open a PDF downloaded from the web I get 'There was an error opening this document. This file is damaged and could not be repaired. Preview will not open either. Older PDFs OK.

    I am running OS X 10.7.5 and Adobe Reader 11.0.02. In the last few days I have been unable to open PDF's downloaded from the web. Reader gives the error message 'There was an error opening this document. The file is damaged and could not be repaired'. Removing Reader and trying to use Preview to open these files give the error 'Preview cannot open this file. It may be damaged or use a file format that Preview doesn't recognise' (or something like that). Downloading the same files with Reader removed from my Mac Preview opens the files OK.
    I was recently prompted to update Adobe software but did not note exactly what the update was nor when it was done.
    Reader and Preview will both open PDFs I downloaded a week ago. Reader will also open files downloaded on another Mac running OS X 10.0.0 and copied to my Mac. Any ideas?

    Back up all data.
    Triple-click the line of text below to select it, the copy the selected text to the Clipboard (command-C):
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari, and test.
    The "Silverlight" web plugin distributed by Microsoft can also interfere with PDF display in Safari, so you may need to remove it as well, if it's present.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • Why does Acrobat suddenly not work on my Mac (won't open pdf files from a web page), yet I can open them from my iPhone? Everything worked fine yesteray.

    Hello:
    I have a Mac running OS 10.8.5 and I use Acrobat Pro and Acrobat Reader. Today for some reason, any time I try and access a pdf file from a web page, it won't open. I get a blank window. PDF files already on my computer open fine and I can create PDF files from Word docs, but I can't download or view any pdf file from any web page. Strangely, PDF files on web pages open just fine on my iPhone.
    I checked that both my copy of Acrobat Pro and Acrobat Reader are up-to-date. They are.
    I checked that my copy of Firefox is up-to-date. It is. And nothing changed with Firefox within the last 24 hours.
    I am a humble computer end-user. I am baffled as to why this would suddenly not work. I have not changed any settings, etc. Any help or suggestions would be greatly appreciated.

    Thank you.
    I checked your instructions you sent and as far as I can tell all of my settings, etc for Firefox (plugin updates and preferences) are correct but I am having the same problem.
    However, everything works in Safari. I don't have time to attempt to diagnose why Firefox no longer works. I will just switch to Safari.
    Many thanks.
    Charles
    Charles Deister
    (503) 949-5762
    [email protected]<applewebdata://81CB4171-226F-49DF-BD59-A38A7360B3FB/[email protected]>
            PO Box 5032
         Salem, OR 97304
    http://www.pilotstrat.com<http://www.pilotstrat.com/>
    This transmission (including any attachments) may contain confidential information, privileged material, or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

  • Plug-in PDF, Internet Explorer, unable to open a pdf file from web site. Question mark

    Hello,
    A computer where Acrobat 9 Standard and Acrobat Reader 9 have been installed.
    When I try to read a pdf file from a web site and read it in IE, I get a popup whith a question mark and no text.
    The pdf file is not open.
    I have try to reinstall the last reader but the problem is not solved.
    Thanks for your help.
    fabrice

    Any ideas how to solve this issue?
    Try using Protected Mode Off.  Then you will be at the same level of security that those other programs are running at.  You could also try elevating the iexplore.exe task.  That would turn off Protected Mode in that task automatically but then
    you would be running also with Administrator level authority which might be excessive.
    Robert Aldwinckle

  • Cannot open pdf files from the web

    I have downloaded Adobe REader 10.0.1 twice and restarted my Mac.  Operating syste, Mac OS X 10.6.6.  I cannot open files from the web, but there is no problem with opening previously save files.  Thanks for any suggestions.

    un-installed old version and installed new version of READER and all functions have returned

  • I am not able to open pdf files from any web through Firefox. Internet explorer opens those pdf files

    I am not able to open pdf files from any web when I use FireFox.
    I am able to open pdf files when I use internet explorer.

    For the settings to check, see the [[opening PDF files within Firefox]] article.

  • ? Some pdf files from the web will not open, some will.

    Some pdf files from the web will not open, some will. I am using Adobe Reader 10.0.1 on an 8-year old puter I have just upgraded to 2G of RAM. It worked fine before with 256K. When a file won't open I get error message "There is a problem with Adobe Acrobat/Reader. If it is running, please exit and try again (103:103). Have uninstalled and reinstalled all Adobe products several times. Ideas?

    Good luck with that. Adobe10.0.1 is a bug infested BAD program. Look at the posts relating to this issue for the last 3 days. Many, many problems. Support is no help.

Maybe you are looking for

  • Multi gesture for browsers different from safari

    Multi gesture for browsers different from safari, for example right to left scroll to previous page. How to set it like in Snow Leopard?

  • Call controller with javascript

    Hi, I have a short question: If I called this function several times in my program, will always the same controller be called or will for each call an instance of the controller be created? : child = window.open("controller_data.do","Test","width=183

  • Importing from iPhoto into Elements 11 Organizer

    When I click Import in Elements 11 Organizer and choose the iPhoto option I do not get the "Import from iPhoto" dialog box that allows you choices of what you would like to import. Instead, the program immediately begins importing all the photos that

  • End-User Agreement before opening a pdf file

    Hi, is it possible to have an end-user agreement type thing come up when a user opens a pdf file which will only open the document if they accept the agreement? How would i do that?

  • WHAT UP? iWeb password required on every page??

    I've been building a password protected iweb site for 2 months. I've been able to publish then check my pages by only entering my password for the welcome page. As of tonight I'm being asked to enter my name and password for every page I open (using