Sub Zero Wins

Sunday, January 10, 2010

pl sql debug

CREATE OR REPLACE PACKAGE xxpeug_jdebug IS

PROCEDURE pr_set_message(pi_pipe IN VARCHAR2, pi_message IN VARCHAR2);
FUNCTION f_get_message(pi_pipe IN VARCHAR2) Return VARCHAR2;

END xxpeug_jdebug;
/
CREATE OR REPLACE PACKAGE BODY xxpeug_jdebug AS

PROCEDURE pr_set_message(pi_pipe IN VARCHAR2, pi_message IN VARCHAR2) IS
pragma autonomous_transaction;
va_n_s INTEGER;
BEGIN
dbms_pipe.pack_message(pi_message);
va_n_s := dbms_pipe.send_message(pi_pipe, 1 /* maxwait = 1 sec */);
if va_n_s = 1 then
-- Timeout because buffer is full, so purge
dbms_pipe.purge(pi_pipe);
elsif va_n_s <> 0 then
raise_application_error(-20000, 'Error:' || to_char(va_n_s) || ' sending pipe');
end if;
END;

FUNCTION f_get_message(pi_pipe IN VARCHAR2) Return VARCHAR2 IS
va_n_s INTEGER;
va_v_message VARCHAR2(4096);
BEGIN
va_n_s := dbms_pipe.receive_message(pi_pipe);
if va_n_s <> 0 then
raise_application_error(-20000, 'Error:' || to_char(va_n_s) || ' reading pipe');
end if;

dbms_pipe.unpack_message(va_v_message);
Return(va_v_message);
END;

END xxpeug_jdebug;
/


Java

// FrontEnd Plus GUI for JAD
// DeCompiled : jdebug.class

import java.io.InputStream;
import java.io.PrintStream;
import java.sql.*;
import java.util.Calendar;

public class JDebug extends Thread
{

static Connection conn = null;
static String pipe = null;
static String stopmsg = "JDebug - Stop";

public JDebug()
{
}

public void run()
{
CallableStatement call = null;
String value = null;
Calendar now = null;
try
{
call = conn.prepareCall("begin ? := xxpeug_jdebug.f_get_message(?); end;");
call.registerOutParameter(1, 12);
call.setString(2, pipe);
do
{
call.execute();
value = call.getString(1);
if(value.equals(stopmsg))
break;
now = Calendar.getInstance();
System.out.println(now.get(11) + ":" + now.get(12) + ":" + now.get(13) + "." + now.get(14) + " " + value);
} while(true);
}
catch(SQLException se)
{
System.out.println("SQL Error : " + se);
}
finally
{
try
{
if(call != null)
call.close();
}
catch(SQLException sqlexception) { }
}
}

public static void main(String args[])
{
CallableStatement call = null;
Connection conn2 = null;
if(args.length != 4)
{
System.out.println("usage: JDebug ");
System.exit(-1);
}
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(args[0], args[1], args[2]);
pipe = args[3];
System.out.println("Reading pipe : " + pipe + ". Press to exit");
Thread jDebug = new JDebug();
jDebug.start();
System.in.read();
conn2 = DriverManager.getConnection(args[0], args[1], args[2]);
call = conn2.prepareCall("begin xxpeug_jdebug.pr_set_message(?, ?); end;");
call.setString(1, pipe);
call.setString(2, stopmsg);
call.execute();
call = conn2.prepareCall("begin ? := dbms_pipe.remove_pipe(?); end;");
call.registerOutParameter(1, 4);
call.setString(2, pipe);
call.execute();
call.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
if(!conn.isClosed())
conn.close();
if(!conn2.isClosed())
conn2.close();
}
catch(Exception exception1) { }
}
}

}

cmd line
========
SET JAVA_HOME = C:\jdevR12\jdevbin\jdk
java -Xms128m -Xmx128m -classpath C:\Oracle\product\10.1.0\Client_1\jdbc\lib\classes12.zip;. JDebug jdbc:oracle:thin:@dendbd2:1552:DERP3DEV apps apps PRA
PAUSE

Tuesday, October 06, 2009

Transformation code in java

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class XMLTransform {

public static void main(String args[]) {

// if (args.length != 1) {
// System.err.println("Usage: java XMLTransform xmlfile.xml");
// System.exit(-1);
// }

try {
StreamSource source = new StreamSource(args[0]);
StreamSource stylesource = new StreamSource("t1.xsl");

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(stylesource);

StreamResult result = new StreamResult(System.out);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Calling a web service in java

package test;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPFault;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPFaultException;

public class SendMsg
{

private String serviceName;
private String portName;
private String targetNamespace;

public SendMsg()
{
}

public String doit(String args[])
throws Exception
{
String wsdlURL;
String file;
String resultString;
wsdlURL = args[0];
file = args[1];
Dispatch serviceDispatch = null;
Source result = null;
resultString = null;
FileWriter fw;
Exception exception;
init(wsdlURL);
URL url = null;
try
{
url = new URL(null, wsdlURL);
}
catch(MalformedURLException e)
{
System.out.println((new StringBuilder()).append("Failed to create URL for the wsdl Location: '").append(wsdlURL).append("'.").toString());
System.out.println(e.getMessage());
}
URL serviceURL = url;
QName serviceQName = new QName(targetNamespace, serviceName);
QName portQName = new QName(targetNamespace, portName);
Service service = Service.create(serviceURL, serviceQName);
Dispatch serviceDispatch = service.createDispatch(portQName, javax/xml/transform/Source, javax.xml.ws.Service.Mode.PAYLOAD);
Source result = (Source)serviceDispatch.invoke(new StreamSource(new FileInputStream(file)));
resultString = sourceToXMLString(result);
if(args.length == 3)
{
String outfile = args[2];
fw = null;
try
{
fw = new FileWriter(outfile);
fw.write(resultString);
}
catch(IOException e)
{
throw new Exception((new StringBuilder()).append("Results could not be written to file ").append(outfile).toString());
}
finally
{
if(fw == null) goto _L0; else goto _L0
}
if(fw != null)
{
try
{
fw.close();
}
catch(Exception ignore) { }
}
}
break MISSING_BLOCK_LABEL_398;
try
{
fw.close();
}
catch(Exception ignore) { }
throw exception;
SOAPFaultException e;
e;
String faultCode = e.getFault().getFaultCode().toLowerCase();
String faultDetails = e.getFault().getFaultString();
if(faultCode.contains("server"))
{
System.err.println("The Web Service is not in a valid state.");
System.err.println("Details:\n\n");
System.err.println(faultDetails);
} else
if(faultCode.contains("client"))
{
System.err.println("The XML request is invalid. Fix the request and resend.");
System.err.println("Details:\n\n");
System.err.println(faultDetails);
}
break MISSING_BLOCK_LABEL_398;
e;
System.err.println(e.getMessage());
return resultString;
}

public static void main(String args[])
{
if(args.length < 2)
{
printUsage();
} else
{
try
{
System.out.println((new StringBuilder()).append("##### START TIME : ").append(Calendar.getInstance().getTime().toString()).toString());
String res = (new SendMsg()).doit(args);
System.out.println(res);
System.out.println((new StringBuilder()).append("##### FINISH TIME : ").append(Calendar.getInstance().getTime().toString()).toString());
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

private static void printUsage()
{
System.out.println((new StringBuilder()).append("\nUsage: {weberviceurl} inputfile[").append(File.pathSeparator).append("inputfile]* [outputfile").toString());
}

public String sourceToXMLString(Source result)
{
String xmlResult = null;
try
{
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty("indent", "yes");
transformer.setOutputProperty("method", "xml");
java.io.OutputStream out = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult();
streamResult.setOutputStream(out);
transformer.transform(result, streamResult);
Utf8Encoder encoder = new Utf8Encoder();
xmlResult = encoder.decode(streamResult.getOutputStream().toString());
}
catch(TransformerException e)
{
e.printStackTrace();
}
return xmlResult;
}

private void init(String wsdlURL)
{
String testIt = wsdlURL.toLowerCase();
if(testIt.contains("calculate"))
{
serviceName = "CalculateTaxWSService50";
portName = "CalculateTax50";
targetNamespace = "http://www.vertexinc.com/oseries/services/CalculateTax50";
} else
if(testIt.contains("echo"))
{
serviceName = "EchoWSService";
portName = "Echo";
targetNamespace = "http://www.vertexinc.com/oseries/services/EchoDoc";
} else
if(testIt.contains("lookup"))
{
serviceName = "LookupTaxAreasWSService50";
portName = "LookupTaxAreas50";
targetNamespace = "http://www.vertexinc.com/oseries/services/LookupTaxAreas50";
} else
if(testIt.contains("version"))
{
serviceName = "VertexVersionWSService50";
portName = "VertexVersion50";
targetNamespace = "http://www.vertexinc.com/oseries/services/VertexVersion50";
}
}
}

Passing parameters to xsl in bpel

Picked this up from some blog. A very useful feature of passing parameters to xsl

http://blogs.oracle.com/rammenon/2007/05/passing_bpel_variable_contents.html

http://blogs.oracle.com/ramkumarMenon/gems/TestXSLParams.zip

Monday, September 14, 2009

Examples of parsing/creating xml and calling a webservice in plsql

Parsing an xml
=================

begin

-- soapresp is an xmltype

if soapResp is not null then
l_doc := xmldom.newDOMDocument(soapResp); end if;

--get all the elements
l_n_list := xmldom.getElementsByTagName(l_doc, '*');

--Initialize tables
l_taxtype := taxtype(null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
l_taxtbl := new taxtbl();
LineTaxesTbl := new taxtbl();

--dbms_output.put_line(xmldom.getlength(l_n_list));
for i in 0 .. xmldom.getlength(l_n_list) - 1 loop
l_node := xmldom.item(l_n_list, i);
--dbms_output.put_line(xmldom.getNodeName(l_node));
l_nodeName := xmldom.getNodeName(l_node);

if l_NodeName = 'LineItem' then

l_taxtbl.extend(1);
l_taxtype.Lineid := xmldom.getattribute(xmldom.MakeElement(l_node),
'lineItemId');
l_line_list := xmldom.getChildNodes(l_node);
for k in 0 .. xmldom.getlength(l_line_list) - 1 loop
l_lineNode := xmldom.item(l_line_list, k);
.
.
.
.
.
.
.
.



============================================================================

Calling a webservice from plsql
================================
create or replace procedure getTax(web_service IN VARCHAR2,
web_service_param IN VARCHAR2) IS
-- req demo_soap.request;
-- resp demo_soap.response;
a varchar2(32000);

http_req utl_http.req;
http_resp utl_http.resp;
doc xmltype;
x dbms_xmldom.DomDocument;

env varchar2(32767) := '' ||
chr(10) || ' ' ||
' ' ||
' admin vertex 1041 Old Cassatt Road Berwyn PA Chester 19312 USA product code value 1.0 0 1000 1000
' ||
'
';

-- ' admin vertex 1041 Old Cassatt Road Berwyn PA Chester 19312 USA product code value 1.0 0 1000 1000 ';
/* req.body := '' ||
chr(10) || ' ' || chr(10) ||
' ' || chr(10) ||
' admin vertex 1041 Old Cassatt Road Berwyn PA Chester 19312 USA product code value 1.0 0 1000 1000
' ||
chr(10) || '
';
*/
BEGIN

-- req.method := 'calculateTax50';
-- req.namespace := 'http://www.vertexinc.com/oseries/services/CalculateTax50';
-- req.body := ' admin vertex 1041 Old Cassatt Road Berwyn PA Chester 19312 USA product code value 1.0 0 1000 1000 ';

http_req := utl_http.begin_request('http://denwlsq1:8911/vertex-ws/services/CalculateTax50',
'POST',
'HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(env));
utl_http.set_header(http_req, 'SOAPAction', '');
utl_http.write_text(http_req, env);
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, a);
utl_http.end_response(http_resp);
doc := xmltype.createxml(a);
--dbms_output.put_line(doc.getStringVal);
insert into tmp values (doc);
commit;
dbms_output.put_line(doc.getstringval());

END;
/




=========================================
declare
-- xmlparser
p xmlparser.parser;
-- Document
doc xmldom.DOMDocument;
-- Elements
el xmldom.DOMElement;
-- Nodes
buffyNode xmldom.DOMNode;
docNode xmldom.DOMNode;
vampire_node xmldom.DOMNode;
demon_node xmldom.DOMNode;
enemy_node xmldom.DOMNode;
friend_node xmldom.DOMNode;
node xmldom.DOMNode;
t dbms_xmldom.DOMText;

--Attributes
attr xmldom.DOMAttr;
-- Varchar2
temp1 varchar2(10000);
temp2 varchar2(255);

BEGIN
p := xmlparser.newParser;
xmlparser.parseBuffer(p,'');
doc := xmlparser.getDocument(p);
xmldom.setVersion(doc, '1.0');
docNode := xmldom.makeNode(doc);
buffyNode := xmldom.getLastChild(docNode); --The last child is the quickbuy node
-- ok

el := xmldom.createElement(doc, 'Friend');
friend_node := xmldom.appendChild(buffyNode, xmldom.makeNode(el));
el := xmldom.createElement(doc, 'Enemy');
enemy_node := xmldom.appendChild(buffyNode, xmldom.makeNode(el));

--test

el := xmldom.createElement(doc , 'Pratest');
node := xmldom.MakeNode(el);
node := xmldom.appendChild(buffyNode,node);

t := xmldom.createTextNode(doc,'ttt');

node := xmldom.appendChild(node,xmldom.MakeNode(t));


--test


el := xmldom.createElement(doc, 'Vampire');
xmldom.setAttribute(el, 'name','Spike');
xmldom.setAttribute(el, 'danger','zero');
vampire_node := xmldom.appendChild(friend_node, xmldom.makeNode(el));

el := xmldom.createElement(doc, 'Vampire');
xmldom.setAttribute(el, 'name','Harmony Kendal');
xmldom.setAttribute(el, 'danger','high');
vampire_node := xmldom.appendChild(enemy_node, xmldom.makeNode(el));

el := xmldom.createElement(doc, 'Demon');
xmldom.setAttribute(el, 'name','Ovu Mobani');
xmldom.setAttribute(el, 'danger','high');
demon_node := xmldom.appendChild(enemy_node, xmldom.makeNode(el));

el := xmldom.createElement(doc, 'Human');
xmldom.setAttribute(el, 'name','Lunch Lady');
xmldom.setAttribute(el, 'danger','extreme');
demon_node := xmldom.appendChild(enemy_node, xmldom.makeNode(el));


xmldom.writeToBuffer(doc, temp1);
temp2 := substr(temp1,1,250);
DBMS_OUTPUT.PUT_LINE(temp2);

temp2 := substr(temp1,251,250);
DBMS_OUTPUT.PUT_LINE(temp2);


-- deal with exceptions
exception

when xmldom.INDEX_SIZE_ERR then
-- raise_application_error(--20120, 'Index Size error');
DBMS_OUTPUT.PUT_LINE('Index Size error');
when xmldom.DOMSTRING_SIZE_ERR then
-- raise_application_error(--20120, 'String Size error');
DBMS_OUTPUT.PUT_LINE('String Size error');
when xmldom.HIERARCHY_REQUEST_ERR then
-- raise_application_error(--20120, 'Hierarchy request error');
DBMS_OUTPUT.PUT_LINE('Hierarchy request error');
when xmldom.WRONG_DOCUMENT_ERR then
-- raise_application_error(--20120, 'Wrong doc error');
DBMS_OUTPUT.PUT_LINE('Wrong doc error');
when xmldom.INVALID_CHARACTER_ERR then
-- raise_application_error(--20120, 'Invalid Char error');
DBMS_OUTPUT.PUT_LINE('Invalid char error');
when xmldom.NO_DATA_ALLOWED_ERR then
-- raise_application_error(--20120, 'Nod data allowed error');
DBMS_OUTPUT.PUT_LINE('No data allowed error');
when xmldom.NO_MODIFICATION_ALLOWED_ERR then
-- raise_application_error(--20120, 'No mod allowed error');
DBMS_OUTPUT.PUT_LINE('No mode allowed error');
when xmldom.NOT_FOUND_ERR then
-- raise_application_error(--20120, 'Not found error');
DBMS_OUTPUT.PUT_LINE('Not found error');
when xmldom.NOT_SUPPORTED_ERR then
-- raise_application_error(--20120, 'Not supported error');
DBMS_OUTPUT.PUT_LINE('Not supported error');
when xmldom.INUSE_ATTRIBUTE_ERR then
-- raise_application_error(--20120, 'In use attr error');
DBMS_OUTPUT.PUT_LINE('In use attr error');
END;




==========================================

DECLARE
dom_doc dbms_xmldom.DOMDocument;
n_doc dbms_xmldom.DOMNode;
e dbms_xmldom.DOMElement;
n dbms_xmldom.DOMNode;
n_directory dbms_xmldom.DOMNode;
n_temp dbms_xmldom.DOMNode;
t dbms_xmldom.DOMText;
buf VARCHAR2(2000);
BEGIN
-- New Document
dom_doc := dbms_xmldom.newDOMDocument;
dbms_xmldom.setVersion( dom_doc, '1.0' );
n_doc := dbms_xmldom.makeNode( dom_doc );
--
-- Create Root Element.
e := dbms_xmldom.createElement( dom_doc, 'description' );
dbms_xmldom.setAttribute( e, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance' );
n := dbms_xmldom.makeNode( e );
n_directory := dbms_xmldom.appendChild( n_doc, n );
--
-- Create description_id element.
e := dbms_xmldom.createElement( dom_doc, 'description_id' );
n := dbms_xmldom.makeNode( e );
n := dbms_xmldom.appendChild( n_directory, n );
t := dbms_xmldom.createTextNode( dom_doc, '456' );
n := dbms_xmldom.appendChild( n, dbms_xmldom.makeNode( t ) );
--
-- Create anatomical_notes element
e := dbms_xmldom.createElement( dom_doc, 'anatomical_notes' );
n := dbms_xmldom.makeNode( e );
n := dbms_xmldom.appendChild( n_directory, n );
t := dbms_xmldom.createTextNode( dom_doc, 'anatomical notes & works' );
n := dbms_xmldom.appendChild( n, dbms_xmldom.makeNode( t ) );
--
-- make node.
--DBMS_OUTPUT.PUT_LINE( dbms_xmldom.getNodeName( n_d ) );
--DBMS_OUTPUT.PUT_LINE( dbms_xmldom.getNodeValue( n_d ) );
--DBMS_OUTPUT.PUT_LINE( dbms_xmldom.getNodeType( n_d ) );
--e := dbms_xmldom.getDocumentElement( d );
--n := dbms_xmldom.makenode( e );
--DBMS_OUTPUT.PUT_LINE( dbms_xmldom.ELEMENT_NODE );
dbms_xmldom.writetobuffer( n_doc, buf );
--DBMS_OUTPUT.PUT_LINE( dbms_xmldom.getDoctype( d ) );
DBMS_OUTPUT.PUT_LINE(buf);
EXCEPTION
--
WHEN xmldom.INDEX_SIZE_ERR THEN
-- raise_application_error(--20120, 'Index Size error');
DBMS_OUTPUT.PUT_LINE('Index Size error');
WHEN xmldom.DOMSTRING_SIZE_ERR THEN
-- raise_application_error(--20120, 'String Size error');
DBMS_OUTPUT.PUT_LINE('String Size error');
WHEN xmldom.HIERARCHY_REQUEST_ERR THEN
-- raise_application_error(--20120, 'Hierarchy request error');
DBMS_OUTPUT.PUT_LINE('Hierarchy request error');
WHEN xmldom.WRONG_DOCUMENT_ERR THEN
-- raise_application_error(--20120, 'Wrong doc error');
DBMS_OUTPUT.PUT_LINE('Wrong doc error');
WHEN xmldom.INVALID_CHARACTER_ERR THEN
-- raise_application_error(--20120, 'Invalid Char error');
DBMS_OUTPUT.PUT_LINE('Invalid char error');
WHEN xmldom.NO_DATA_ALLOWED_ERR THEN
-- raise_application_error(--20120, 'Nod data allowed error');
DBMS_OUTPUT.PUT_LINE('No data allowed error');
WHEN xmldom.NO_MODIFICATION_ALLOWED_ERR THEN
-- raise_application_error(--20120, 'No mod allowed error');
DBMS_OUTPUT.PUT_LINE('No mode allowed error');
WHEN xmldom.NOT_FOUND_ERR THEN
-- raise_application_error(--20120, 'Not found error');
DBMS_OUTPUT.PUT_LINE('Not found error');
WHEN xmldom.NOT_SUPPORTED_ERR THEN
-- raise_application_error(--20120, 'Not supported error');
DBMS_OUTPUT.PUT_LINE('Not supported error');
WHEN xmldom.INUSE_ATTRIBUTE_ERR THEN
-- raise_application_error(--20120, 'In use attr error');
DBMS_OUTPUT.PUT_LINE('In use attr error');
END;
/

Saturday, October 18, 2008

Downloading the entire website for offline viewing

Sunday, July 27, 2008

how to remove the beep sound in the computer

To remove the annoying beeping sound from the computer..

To get rid of the annoying beep sound your computer makes

1. Right click my computer and Select Manage
2. Select Device Manager
3. Select View
4. Select Show hidden devices
5. Click Non-Plug and Play Drivers
6. Right Click Beep and select properties
7. On device usage select Do not use this device(disable)

Thursday, October 11, 2007

Answers to looking back


I had posted a few questions to myself , with out konwing the answers . Seems people have thought over this as one of the quote says the following

Sunday, July 02, 2006

Looking back

In time when you look back on things ..
would you regret that thought of you not doing the things that you could have and you didnt ?? OR

WOuld you regret the thought of you doing the things that you shouldnt have???

I am yet to find the answer perfeectly but i have a feeling i would regret the first more than the second...