Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Cannot connect to URL via Java stored procedure

Re: Cannot connect to URL via Java stored procedure

From: Terri I. <teresni_at_ucia.gov>
Date: 15 Nov 2001 13:03:32 -0800
Message-ID: <b1f8b3bc.0111151303.2e824dca@posting.google.com>


Initially, I didn't know what error was being generated because I didn't know where system output from Java was written within Oracle. Once I learned where to find that, I discovered I needed to grant permission to java.net.SocketPermission. Once I did that, the program worked fine....

"Sergey M" <msu_at_pronto.msk.ru> wrote in message news:<9svss7$d05$1_at_serv2.vsi.ru>...
> What have you error when tried connect ?
>
> Sergey M.
>
> "Terri I." <teresni_at_ucia.gov> wrote in message
> news:b1f8b3bc.0111141428.423b8027_at_posting.google.com...
> > Does anybody have any idea why my Java class stored procedure will not
> > connect to a specified URL when running from within the Oracle
> > database, even though it works fine from command prompt using java
> > command?
> >
> > Here is my source code:
> >
> > import oracle.sql.CLOB;
> > import oracle.sql.*;
> > import java.net.*;
> > import java.net.*.URL;
> > import java.io.*;
> > import java.sql.*;
> >
> > public class ManageSSLConnection {
> > // POST an XML document to a Service's URL, returning response
> > public static String sendXMLoverSSL(oracle.sql.CLOB xmlToPost,
> > String target)
> > throws IOException, SQLException {
> > String response = "Nothing Posted Yet";
> >
> > try {
> > // Open an HTTP connection to the target URL
> > HttpURLConnection conn = null;
> > URL vistarget = new URL(target);
> > conn = (HttpURLConnection)vistarget.openConnection();
> > if (conn == null) return "ERROR";
> >
> > // Use HTTP POST
> > conn.setRequestMethod("POST");
> >
> > // Indicate that the content type is XML with appropriate MIME
> > type
> > conn.setRequestProperty("Content-type","text/xml");
> >
> > // Set up for writing and reading from the connection
> > conn.setDoOutput(true);
> > conn.setDoInput(true);
> > conn.connect();
> >
> > // Read from the CLOB stream and write to a string
> > String xml_string = xmlToPost.getSubString(1L,
> > (int)xmlToPost.length());
> >
> > // Write the XML document into the connection's output stream
> > DataOutputStream out = new
> > DataOutputStream(conn.getOutputStream());
> > out.writeBytes(xml_string);
> > out.flush();
> > out.close();
> >
> > // Get header response from the server.
> >
> > // Need to call getHeaderFieldKey method so that
> > // getResponseCode and getResponseMessage methods will
> > // not return FileNotFoundException when return code > 400.
> > // This is a known Java bug that is expected to be fixed in v.
> > 1.4
> >
> > int i=1;
> > String key;
> > while(true) {
> > key = conn.getHeaderFieldKey(i);
> > if (key==null)
> > break;
> > i++;
> > }
> >
> > int resp_code = conn.getResponseCode();
> > String resp_msg = conn.getResponseMessage();
> > response = resp_code + " " + resp_msg;
> >
> > conn.disconnect();
> > return response;
> > }
> >
> > catch (FileNotFoundException e1) {
> > return("ERROR");
> > }
> >
> > catch (Exception e2) {
> > e2.printStackTrace();
> > return("ERROR");
> > }
> > }
> > }
Received on Thu Nov 15 2001 - 15:03:32 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US