Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Cannot connect to URL via Java stored procedure
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 - 02:03:08 CST
![]() |
![]() |