1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Error 404 file not found when calling java from oracle

Discussion in 'SQL PL/SQL' started by gala, Dec 4, 2015.

  1. gala

    gala Starter

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    France
    Hi,
    I have a java application which uploads a file to web server. It works fine as java.
    After loading it to oracle and calling from oracle I get 404 file not found error.
    The URL contans a query string.
    Here is the code: (responseCode return 404)

    HttpURLConnection webReq = (HttpURLConnection)(url).openConnection();
    webReq.setRequestMethod("POST");
    webReq.setRequestProperty("Content-Type", "application/json");
    webReq.setRequestProperty("Connection", "Close");
    webReq.setDoInput(true);
    webReq.setDoOutput(true);
    webReq.setRequestProperty("Content-Length", String.valueOf(jsonDataBytes.length));
    OutputStream theStream = webReq.getOutputStream();
    theStream.write(jsonDataBytes);
    theStream.close();
    InputStream response;
    int responseCode = webReq.getResponseCode();
     
  2. ocprep

    ocprep Forum Advisor

    Messages:
    277
    Likes Received:
    76
    Trophy Points:
    410
    Location:
    Orlando, Florida
    I can't tell from your description of the 404 is a result of the code not locating the file to be uploaded or the webserver the file is being uploaded TO. If it's not finding the file, my immediate assumption would be that it's a permissions issue. When called from the Oracle database, the code is most likely using the Linux account 'oracle' to locate the files. If the file permissions do not allow access by the oracle user, then the Java would generate a 'File not found' error.

    That said, troubleshooting something like this is tough enough when done while you have access to the machine in questions. Doing so virtually like this is essentially impossible.
     
  3. gala

    gala Starter

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    France
    Thanks for your respond.

    In my java application I make 3 HTTP requests to a web server:
    1. Request for identification with returning a ticket -it works fine.
    2. Uploading a file to a web server - it works fine.
    3. Request for moving file to the specified destination and unpacking it. Here I use url with a query string, containing the ticket information (which was generated in step 1). In this last step I got error 404.

    After playing with this I figured out that the error relates to using cookies. I have to use cookies in steps 2 and 3 to maintain the same session for these operations (otherwise it doesn't work). If I don't use cookies in step 3 or use the different session from the step 2 then I no longer get error 404, the response code is 200, but it doesn't resolve the problem since I have to maintain the same session.
    Again, it works fine as java, the problem happens only when calling a java stored procedure. What do you think?
    Thanks!
     
  4. ocprep

    ocprep Forum Advisor

    Messages:
    277
    Likes Received:
    76
    Trophy Points:
    410
    Location:
    Orlando, Florida
    Based on what you're saying, it is definitely the destination webserver generating the error rather than something on the side where the Java app/Java stored procedure side. A webserver does not *care* where an HTTP request originated, it will respond to a given request string the same way no matter the origin. I have to assume then that something is different between the request sent to the server from your Java app vs the request sent by the Java stored procedure.

    If it is feasible, I would suggest creating debug code in both apps such that in the final step, rather than sending the request to the webserver that is generating the error that you print it to screen (or save it to a file). Then compare the two requests character by character to see if there is a difference between what the Java app sends vs what the Java stored procedure sends.
     
  5. gala

    gala Starter

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    France
    Thanks for your suggestion.
    Actually, I have already done this and the header information is identical. Maybe there is some other important information which I didn't include?
    This is what I have now:
    JAVA:
    [JSESSIONID=F0B4EADA980EBAA2D6B9873D87143872], Host=[srvged:8081], POST /alfresco/s/knowings/pgec/document?alf_ticket=TICKET_0efc13534a72219c500b36586480e5da9eca81d8 HTTP/1.1=[null], Content-Length=[157], User-Agent=[Java/1.6.0_43], Accept=[text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2], Connection=[Close], Content-Type=[application/json]
    Code de response 200

    JAVA stored procedure:
    [JSESSIONID=C49F64994399191A44341ADC564BDE25], Host=[srvged:8081], POST /alfresco/s/knowings/pgec/document?alf_ticket=TICKET_09679ad37d43590d59613ae89a41cc53ab0737e9
    HTTP/1.1=[null], Content-Length=[157], User-Agent=[Java/1.6.0_43], Accept=[text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2], Connection=[Close], Content-Type=[application/json]
    Code de response 404