Re: Cannot connect to URL via Java stored procedure

From: Sergey M <msu_at_pronto.msk.ru>
Date: Thu, 15 Nov 2001 11:03:08 +0300
Message-ID: <9svss7$d05$1_at_serv2.vsi.ru>


[Quoted] 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 - 09:03:08 CET

Original text of this message