Decode a base64 encoded string stored in XML string element
544143May 10 2012 — edited May 10 2012Hi,
I have a AQ of RAW type receiving an XML message (3 elements, out of which two are base64 encoded string). I'm able to convert the raw to varchar2, read the xml and retrieve the base64 encoded string. But when I try to decode, I get the ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error.
The data stored in base64encoded string is also XML.
Appreciate your inputs.
Thanks,
Gayathri
Dequeue PLSQL:
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
dequeue_options dbms_aq.dequeue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
msg_in raw(2000);
msg_out RAW(2000);
temp_raw RAW(2000);
msg_varchar VARCHAR2(32767);
v_message_header VARCHAR2(32767);
v_decrypted_msg varchar2(32767);
xml xmltype;
BEGIN
dequeue_options.wait:=180;
DBMS_AQ.DEQUEUE(
queue_name => 'REJ_APRVD_CLAIM_Q',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => msg_out,
msgid => message_handle);
msg_varchar := utl_raw.cast_to_varchar2((msg_out));
xml := XMLTYPE.createxml(msg_varchar);
v_message_header := xml.EXTRACT('//tns:RejectedMessage/tns:MessagePayload/text()','xmlns:tns="http://xmlns.oracle.com/pcbpel/errorHandling"').getstringval();
v_decrypted_msg := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_varchar2(v_message_header)));
dbms_output.put_line('Payload = ' || msg_varchar );
dbms_output.put_line('v_message_header = ' || v_message_header );
dbms_output.put_line('v_decrypted_msg = "' || v_decrypted_msg || '"');
END;
/
The error occurs in the utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_varchar2(v_message_header))) statement.
A sample Input message:
<?xml version='1.0' encoding='UTF-8'?>
<tns:RejectedMessage RejectionId="50018"
xmlns:tns="http://xmlns.oracle.com/pcbpel/errorHandling">
<tns:MessageHeader>
e2pjYS5hcS5NZXNzYWdlSWQ9QkY4MDczNEZEQUFBMDA0Q0UwNDMwQTE0OTY3MTAwNEMsIGpjYS5h
cS5Qcmlvcml0eT0wLCBqY2EuYXEuRW5xdWV1ZVRpbWU9MjAxMi0wNS0xMFQxMjoyNDo1Ny4wMDAr
MTA6MDAsIGpjYS5hcS5BdHRlbXB0cz0xfQ==
</tns:MessageHeader>
<tns:MessagePayload>
PFZDTV9BUFBST1ZFRF9DTEFJTV9NU0dfVFlQRSB4bWxucz0iaHR0cDovL3htbG5zLm9yYWNsZS5j
b20veGRiL0hDVkNNIj4KICAgPENMQUlNX0lEIHhtbG5zPSIiPjc0MTU0MjUxPC9DTEFJTV9JRD4K
PC9WQ01fQVBQUk9WRURfQ0xBSU1fTVNHX1RZUEU+Cg==
</tns:MessagePayload>
<tns:RejectionReason>
Resource adapter invoked onReject() without an associated exception
</tns:RejectionReason>
</tns:RejectedMessage>