Two weeks ago, i have assigned to call a middleware application via HTTP. The middleware app, accepts XML commands as a webservice manner. I got help from a java developer to write down java codes to establish the work. Finally a java application is created. I put java into Oracle:
create or replace and compile java source named java_notify as
public class MW
{
public static String ExecuteCommand( String _inputXML, String _MWUrl )
{
String ReturnMessage = "";
try
{
String Line;
java.net.URL MWUrl = new java.net.URL(_MWUrl);
java.net.URLConnection MWConnection = MWUrl.openConnection();
java.io.PrintWriter RequestWriter = null ;
java.io.BufferedReader RequestReader = null ;
MWConnection.setRequestProperty("Content-Type", "text/xml");
MWConnection.setDoOutput(true);
RequestWriter = new java.io.PrintWriter( MWConnection.getOutputStream() );
RequestWriter.println( _inputXML );
RequestWriter.close();
RequestReader = new java.io.BufferedReader( new java.io.InputStreamReader( MWConnection.getInputStream() ) );
Line = RequestReader.readLine() ;
while ( Line != null )
{
ReturnMessage += Line;
Line = RequestReader.readLine();
}
RequestReader.close();
}
catch ( Exception e)
{
ReturnMessage = "ERROR";
ReturnMessage += e.toString();
e.printStackTrace();
}
return ReturnMessage;
}
}
/
I wrap the java source with a function:
CREATE OR REPLACE FUNCTION fnc_Not
(
pis_InputXML IN VARCHAR2,
pis_MWUrl IN VARCHAR2
) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'MW.ExecuteCommand( java.lang.String, java.lang.String ) return java.lang.String';
/
Then call this function, from packages. The process logic was loading a java source into Oracle. I start to write pure oracle codes to accomplish this task. I write some Oracle codes:
--create request : set meta data of request object
--POST method and HTTP 1.0 protocol
vt_HttpRequest := utl_http.begin_request(vs_MWUrl,'POST','HTTP/1.0');
--XML text and capable for turkish chars
utl_http.set_header(vt_HttpRequest,'Content-Type', 'text/xml;charset=UTF-8');
--set content length
utl_http.set_header(vt_HttpRequest,'Content-Length', length(pis_Request));
--assign input XML to request object
utl_http.write_text(vt_HttpRequest, pis_Request);
--execute command
vt_HttpResponse := utl_http.get_response(vt_HttpRequest);
--get response object from request.
utl_http.read_text(vt_HttpResponse, vs_Response);
--close response
utl_http.end_response(vt_HttpResponse);
These two approach does the same work. So, being a java programmer for oracle programmers is not important. For instance, i am not a java developer; but i can do all my work with Oracle.
No comments:
Post a Comment