Character decoding
For character decoding an incoming message , I am retrieving the text string from a bodypart and character-decoding it using the "charset" obtained from body part. Then I am creating a new body part with this decoded string . Then I am removing the old bodypart and adding this new bodypart at that place. I am creating a new ParameterList and setting "charset" as a parameter . Then I set this list to the Content Type of new bodypart. The sample code of the method is as follows:-
mimeBodyPart = (MimeBodyPart) (((BodyPart) multiPart.getBodyPart(i))); //Creating mime Bodypart object from multipart.
String strCharset = (new ContentType(mimeBodyPart.getContentType())).getParameter("charset"); //Retrieving the charset
InputStream is = mimeBodyPart.getInputStream();
is.read(b); //Reading the inputstream into a byte array.
decodedString = new String(b,strCharset); //Creating the decoded string.
MimeBodyPart newBodyPart = new MimeBodyPart(new InternetHeaders(is),decodedString.getBytes()); //Creating the new bodypart here.
ContentType newContentType = new ContentType(newBodyPart[i].getContentType()); //Getting Content Type object of new bodypart.
ParameterList parameterList=new ParameterList(); //Creating a new parameter list.
parameterList.set("charset",strCharset); //Setting 'charset' as a parameter in parameter list.
newContentType.setParameterList(parameterList);
multiPart.removeBodyPart(1); //Removing the old body part at position 1
multiPart.addBodyPart(newBodyPart[1], 1); //Adding the new body part.
But when I am retrieving the text in bodypart at later stages of my application ,I am getting corrupted data and if I am retrieving the 'charset' parameter later I am getting a different value.e.g. if initially the value is "iso-8859-1" of 'charset', i am getting the 'charset' parameter value as "us-ascii" later. Why is it so?
OK.. I am really confused by what you are doing here. Either I am looking at it completely wrong, or you are doing a whole lot of unneccessary stuff here.
When you get the content of a Part in JavaMail, it should be automatically decoding it unless the encoding type is not supported. So, what I normally do is:
Get the Part content (this is an Object) using getContent();
Get the Part content type
Get the Part content disposition
Test to see if the content is a Multipart using an instanceof test. If so, recursively call this function for each part
Otherwise, if the content type is text/plain or text/html then assume the content Object is a String and just call toString() or cast it.
Otherwise if the content disposition is "inline" or "attachment" assume the content is a binary stream and use the Part.getDataHandler().getInputStream() method
This will fail is the encoding of the Part is not one supported by Java. For example, this happens with UTF-7 encoding (often used for Delivery Status Notifications) so you would have to write your own decoder for this and any other charsets you expect which are outside the range supported by Java.
Similar Messages
-
Apex_util.get_print_document results in "503-service unavailable"
I'm using APEX 4.2.0.3.00.08 with GlassFish 3.1.2.2 on an Oracle 10.2.0.5 database.
Recently I created a report-query together with a xsl-fo report-layout created in Altova Stylevision. I've enabled and configured print-options and when I press my application button, I'm perfectly capable of viewing and/or saving the pdf-version of my report.
Additionally I want to save my report as BLOB in the database, but when I try this using apex_util.get_print_document, all I get in my table is a html-page containing the message "503-service unavailable".
I used the following page as reference:
Creating High Fidelity PDF Reports with Oracle Application Express but apparently I'm missing something or doing something wrong......I truly hope there's someone out here to help me!!
Thanks in advance!Hello Mike,
I've been trying to create an application on apex.oracle.com to reproduce the problem, but I can't seem to get it to work.
I've uploaded a very simple layout created in StylusStudio, a simple query on the EMP-table only containgin FIRST_NAME, LAST_NAME and EMAIL and when I add the layout to the query and press "Test report", it works fine.
When I run the report from my application, it only shows a pdf with a thick, horizontal lines, like it's showing only empty cell borders.
Meanwhile I found out that the APEX-listener keeps reporting similair errors, even when I use that same simple stylesheet (created with StylusStudio) on the EMP-table, even when the stylesheet does not contain any special characters at all. In stead of the message starting with INFO: Character decoding failed. Parameter [#x200B;</xsl:text> , it then ignores the complete xslt-stylesheet (the complete contents of the stylesheet is between the brackets, in stead of just the string containg the special chars).
To be honest I'm a little lost now. First my focus was on how to get rid of the special characters, but now it looks like, even when I might succeed in that, it doesn't even solve my problem.
Any idea why my application doesn't show me the same report I see when testing the report-query?
The application can be found here:
https://apex.oracle.com/pls/apex/htmldb/f?p=29586
The bottom region is an attempt to show the pdf with the highest id, but I think it does not show the actual pdf (http-404)
The source for that PL/SQL region is:
declare
src_ varchar2(256);
mime_ varchar(48);
id_ number;
begin
select max(id)
into id_
from report_archive;
select mimetype
into mime_
from report_archive
where id = id_;
src_ := 'src="#OWNER#.download_doc?i_doc_id=' || id_ || '" ';
htp.p('<div style="">');
if instr(mime_,'pdf') > 0 then
htp.p('<embed height="800" width="1200" name="statement" ');
elsif instr(mime_,'excel') > 0 then
htp.p('<embed height="800" width="1200" name="statement" ');
else
htp.p('<embed height="800" name="statement" ');
end if;
htp.p(src_);
htp.p('type="' || mime_ || '" />');
htp.p('</div>');
exception
when no_data_found then
null;
end;
I really hope we can solve this!!!!
Best regards,
Marco -
PDF with Tomcat - failing with isHexDigit conversion
Hi
I've built a small report writer with printed output using Tomcat.
All works fine until a '%' is used in a parameter in the report.
I then get a Tomcat Error
2007/05/22 06:57:36 org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Character decoding failed. Parameter skipped.
java.io.CharConversionException: isHexDigit
Once that happens all subsequent attempts to print - with our without the wildcard give the same error.
Does anyone know how to trap the contents of the XML passed to Tomcat to see what it's complaining about? Or what APEX is generating?
Thanks
MikeVadim,
Report queries and report region use the same generic report layout. However the processing is handled by different engines. The underlying technical problem with your case is that the substitution string #TEXT_ALIGN# is not substituted in all cases for report queries. This usually does not cause any problems, but appears not to work when using Cocoon.
I'll see that we can this resolved with the next version of APEX, however when working with report layouts, you would typically use your own RTF or XSL-FO stylesheets, where this problem would not occur. The option to use the generic report layout is only included so the data can be tested independently from the layout and is not really intended to be used as the actual layout at runtime.
The generic report layout function is mainly designed to be used for report regions.
Regards,
Marc -
we are using iplanet 4.1 server that invokes our servlet for user requests. in our doGet(), and doPost() methods, we want to get the http GET request as it is received from the client, without any character decoding. we have clients that send us requests that may look like:
/abcd/acs/%2Fcds%2Fads%2F/f1_010717.gif
however, when we use the HttpServletRequest object (say we name it "request"), and call request.getRequestURI(), or HttpUtils.getRequestURL(request), we get a string with the character encoded resolved to their respective values:
abcd/acs//cds/ads//f1_010717.gif
is there a way for us to get the uri with its character encoding intact in our servlet? any help would be greatly appreciated. please email me directly at [email protected]
thanks,
naveed alam
[email protected]Greetings,
is there a way for us to get the uri with its character encoding intact in our servlet? any helpHave a look at the ....util.URIUtil class of the Jakarta Project's Commons HttpClient package: http://jakarta.apache.org/commons/httpclient.
thanks,
naveed alam
[email protected]
Regards,
Tony "Vee Schade" Cook -
Flash Player 10 removes HTML encoding in CDATA when parsing XML
I have an application that was written with Flash Professional 8/AS2 and it parses XML for rendering dynamic media content. The XML pulls text with HTML markup out of CDATA sections and places them into an html enabled text field. Everything has worked wonderfully until Flash Player 10.
Now, if we use html escape characters for greater than or less than symbols, they are being decoded by the xml parser.
Here's my example CDATA section:
Here <u>we</u> go: This <node> <works>
when I grab its value using nodeValue or toString, the results are different from Flash Player 9 to 10. Here's what I'm getting:
node.nodeValue (Flash Player 9):
Here <u>we</u> go: This <node> <works>
node.nodeValue (Flash Player 10):
Here <u>we</u> go: This <node> <works>
node.toString (Flash Player 9):
Here <u>we</u> go: This <node> <works>
node.toString (Flash Player 10):
Here <u>we</u> go: This <node> <works>
In Flash 10, if I escape the ampersand, it will work, but this doesn't work in 9. for example, the following works in 10:
<![CDATA[Here <u>we</u> go: This &#60;node&#62; &lt;works&gt;]]>
This all happens before I assign it to a text field. How do I keep the parser from destroying my escaped characters in Flash 10? Do I just need to drop support for Flash Player 9 and go for what works in 10, or is there a solution for both?
Message was edited by: XygarI'm not an action script programmer. I'm just trying to fix some code written like 3 years ago. So I think I am wrong about where this problem is coming from.
The original developer actually set up a class to load a remote xml file via sendAndLoad on a LoadVars object. It passes an object with an onData delegate set that passes the event object to an xml parsing method.
the parsing method looks like this:
private function parseXml(eventObj:Object){
if(eventObj != undefined)
try
//ExternalInterface.call("logMessage", eventObj.toString());
_xmlDoc.parseXML(eventObj.toString());
_xmlDoc.loaded = true;
_xmlDoc.onLoad(true);
catch(ex)
_xmlDoc.onLoad(false);
else
_xmlDoc.onLoad(false);
I added the ExternalInterface call so that I could log the stuff out in javascript (since I'm not sure how to debug this app).
_xmlDoc is defined as: private var _xmlDoc:XML;
The eventObj receives the xml string and then passes it to the parseXML thing. Here's the odd part. In Flash Player 10, if I comment out my ExternalInterface call, the xml string has the escaped character decoded before it gets to the parser.
However, if I uncomment my ExternalInterface call, it logs the escaped strings as i would expect, but the parser gets the correct formatting this time! Suddenly it all works.
I really wish I had an AS2 programmer on campus still.... -
Chinese Character cannot be decoded
hi,
I would like to implement two JSP pages. The first JSP is just a html form, which is used to submit unicoded chinese data to a target JSP file.
The target JSP file received those data and display.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> is added in the first JSP file. As a result, data will be submitted in UTF-8 format.
In target JSP, I used the following code to recieve and decode data:
<%@ page contentType="text/html; charset=UTF-8" %>
<%
String para = request.getParameter("para"); // where para is name of received parameter
byte[] bytes = para.getBytes();
para = new String(bytes, "UTF-8");
out.println("Recieved character: " + para);
%>
My Problem:
After I submitted chinese characters from the first JSP file, only some of them can be displayed on target JSP. Some of those characters are missing.
For example, when I input "�@", target JSP can display the character. On the other hand, when I input "�p", nothing is displayed. But I know that variable "bytes" stored 3 bytes for each chinese character. I would like ask why
para = new String(bytes, "UTF-8");
cannot encode properly. Is anything wrong about my coding?
ThxMore information can be provided.
OS: Windows 2000 server
web server: iPlanet
P.S. : I have set the Character set to UTF-8 in iPlanet.
thx.
hi,
I would like to implement two JSP pages. The
The first JSP is just a html form, which is used to
submit unicoded chinese data to a target JSP file.
The target JSP file received those data and
and display.
<meta http-equiv="Content-Type"
ype" content="text/html; charset=UTF-8"> is added in
the first JSP file. As a result, data will be
submitted in UTF-8 format.
In target JSP, I used the following code to
to recieve and decode data:
<%@ page contentType="text/html; charset=UTF-8"
F-8" %>
<%
String para = request.getParameter("para"); //
// where para is name of received parameter
byte[] bytes = para.getBytes();
para = new String(bytes, "UTF-8");
out.println("Recieved character: " + para);
%>
My Problem:
After I submitted chinese characters from the
m the first JSP file, only some of them can be
displayed on target JSP. Some of those characters are
missing.
For example, when I input "�@", target JSP can
P can display the character. On the other hand, when I
input "�p", nothing is displayed. But I know that
variable "bytes" stored 3 bytes for each chinese
character. I would like ask why
para = new String(bytes, "UTF-8");
cannot encode properly. Is anything wrong about my
coding?
Thx -
How can I decode Japanese character using java from JavaScript escape() function
Hi:
I have an application which supports Japanese character. I am using JavaScript escape() function to encode the text field before I posted it through web server and then I will just convert it into hex number to decode it through an Integer. It works fine for the character between ascii 1-255. However, it faild on all the double bytes character. All the unicode has the format of "%uXXXX" after it is escaped from JavaScript. How can I resolve the decoding problem?
Thank,
DavidPlease use 'encodeURI()', though it is supported only IE after 5.5.
I'm not sure Netscape.
Thanks,
Katsumi
dwang <[email protected]> wrote:
Hi:
I have an application which supports Japanese character. I am using JavaScript
escape() function to encode the text field before I posted it through
web server and then I will just convert it into hex number to decode
it through an Integer. It works fine for the character between ascii
1-255. However, it faild on all the double bytes character. All the
unicode has the format of "%uXXXX" after it is escaped from JavaScript.
How can I resolve the decoding problem?
Thank,
David -
This is from my question at stack overflow java - Weblogic xss vulnerablity : html character entities getting decoded in jsp - Stack Overflow
I am using a filter to prevent xss by encoding html character of my jsp form parameters.
I am resolving them in jsp using ${param} expression.
This is working fine in tomcat as the values are resolved as is, but on weblogic the values are getting decoded, causing the XSS to succeed
I am using this simple code in jsp to test it
<c:set var="testing" value="eb011"><img src=a onerror=confirm(1)>47379"/> <input type="hidden" name="encoding" value="${testing }"/>
Result in tomcat
<input type="hidden" onerror="confirm(1)>47379"/" src="a" ><img="" value="eb011" name="encoding">
Result in weblogic
<input type="hidden" value="eb011" name="encoding"><img onerror="confirm(1)" src="a">47379"/>
why is weblogic decoding html codes and what could be done to prevent it.It is really handy to learn how to read schema validation errors. It really does say exactly what's wrong there. If you can get access to the XSD that your XML document is prescribing, you should be able to tell what mistake you made. If you learn how to do this, you'll never have to ask questions like this again. :)
The error refers to the "http://www.bea.com/ns/weblogic/weblogic-web-app" namespace, which I believe is in your "weblogic.xml" file. It's saying that in the "jsp-descriptor" element, it found a "noTryBlocks" element at a point where it was not legal. At that point, it expected to find either a "'precompile-continue" or several other elements, but not that one. Read the XSD to determine the correct order for elements. If you're editing this file in Eclipse, you may not even have to obtain the XSD. If you hover the mouse over the root element of the document, it will give you a popup showing the syntax details of the element, which will tell you what the expected order of elements is. -
ExtractValue vs. XMLTable Character Entity Decoding
In removing the deprecated extract/extractValue methods from my queries, I have run into an issue with character data being extracted via XMLTable.
Character entity encoded data (e.g. "'" as "'") was decoded by extractValue, but remains encoded by XMLTable. For example:
WITH myXML AS
SELECT XMLTYPE.createXML('<root desc="Here' || chr(38) || 'apos;s an example"/>') AS x
FROM dual
SELECT
x,
extractValue(x, '/root/@desc'),
mytab.example,
XMLQuery('/root/@desc' PASSING x RETURNING CONTENT).getStringVal()
FROM
myXML,
XMLTable
'/root'
PASSING myXML.x
COLUMNS
example VARCHAR2(39) PATH '@desc'
) mytab;returns
<root desc="Here's an example"/> Here's an example Here's an example Here's an example
Wrapping each column in the SELECT clause in dbms_xmlgen.convert() seems like overkill. Am I doing something wrong?
Thanks.Funny, didn't notice that one before.
It seems it happens only with attributes in transient XMLType instances.
For example, it works if the XML document is store in an XMLType column/table :
SQL> create table tmp_xml of xmltype;
Table created
SQL> set scan off
SQL> insert into tmp_xml values (xmltype('<root desc="Here's an example">R&D</root>'));
1 row inserted
SQL>
SQL> SELECT x.*
2 FROM tmp_xml t
3 , XMLTable('/root'
4 PASSING t.object_value
5 COLUMNS
6 example varchar2(20) PATH '@desc'
7 , content varchar2(30) PATH 'text()'
8 ) x
9 ;
EXAMPLE CONTENT
Here's an example R&D
Workaround with a transient XMLType : the fn:data() function
SQL> SELECT x.*
2 FROM XMLTable('/root'
3 PASSING xmltype('<root desc="Here's an example">R&D</root>')
4 COLUMNS
5 example varchar2(20) PATH '@desc'
6 , content varchar2(30) PATH 'text()'
7 ) x
8 ;
EXAMPLE CONTENT
Here's an examp R&D
SQL>
SQL> SELECT x.*
2 FROM XMLTable('/root'
3 PASSING xmltype('<root desc="Here's an example">R&D</root>')
4 COLUMNS
5 example varchar2(20) PATH 'data(@desc)'
6 , content varchar2(30) PATH 'text()'
7 ) x
8 ;
EXAMPLE CONTENT
Here's an example R&D -
Use properties to get character in file but some char could not be decode
i use properties class to get a file with Big5 character inside the file, but some character could not be display properly.....
sample code:
import java.io.*;
import java.util.*;
public class Frankie {
public static void main(String[] arg) {
try {
Properties p = new Properties();
p.load(new FileInputStream("file.ini"));
Enumeration e = p.propertyNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = p.getProperty(name);
String coded_value = new String(value.getBytes("iso-8859-1"), "Big5");
System.out.println(name + " : " + coded_value);
byte[] bBytes2 = coded_value.getBytes();
for (int k = 0; k < bBytes2.length; k++) {
System.out.println("byte " + "iso1" + "[" + k + "] = " + bBytes2[k]);
catch (Exception e) {
e.printStackTrace();
==================
file.ini
people=你
a=餐
==================
result:
a : ?
byte iso1[0] = 63
people : 你
byte iso1[0] = -89
byte iso1[1] = 65
==================
the proper byte of "餐" should be (-64, 92).....
If i use a varible to store this character in the source code, and use value.getBytes("big5"), the byte could be properly display for this character....
how can i solve this? thanks a lot!The Properties class javadoc says
The load and store methods load and store properties in a simple line-oriented format specified
below. This format uses the ISO 8859-1 character encoding. Characters that cannot be directly
represented in this encoding can be written using Unicode escapes ; only a single 'u' character
is allowed in an escape sequence. The native2ascii tool can be used to convert property files to
and from other character encodings.
which means you are not supposed to use "big5" encoding in your Properties text file
directly. There is a commandline tool "native2ascii" bundled with your jdk package that
you can use to convert your "big5" encoded Properties file into unicode escapes based
text file, then you no longer needs to play the trick
String coded_value = new String(value.getBytes("iso-8859-1"), "Big5");
p.getProperty(name) will give you exactly the correct "value" defined in your properties
file.
-x
btw, when using "native2ascii", if you are not in a "big5" env, using "-encoding big5" option
to force it. -
How to auto decode the character in from(to,cc,bcc)?
i decode raw mail like this:
1,
System.setProperty("mail.mime.decodetext.strict", "false");
System.setProperty("mail.mime.address.strict", "false");
2,
MimeMessage mm = null;
FileInputStream fis = new FileInputStream(f);
mm = new MimeMessage(null, fis);
fis.close();
3,
mm.getRecipients(RecipientType.TO)
mm.getRecipients(RecipientType.CC)
mm.getRecipients(RecipientType.BCC)
mm.getFrom()
but i got the from like:
=?iso-2022-jp?B?GyRCSXtFZzdDGyhC?= <[email protected]>
how to let the javamail decode sender's name?
thank you very much.Is this a different problem than the one you described in this other thread?
http://forum.java.sun.com/thread.jspa?threadID=5310547
Did the solution there not solve this problem as well? -
Decoding character received on a socket
Hello,
My Java program is reading a byte array containing a word with
special characters (>127) -> Oxe9 for é.
I saw that the TCP packet was right using the tcpdump with hexa view.
My default encoding charset is Latin-1 (ISO-8859-1), the one I think
being good :-| (System.setProperty("file.encoding", "ISO-8859-1");)
When doing a System.out.println with the word converted into a
String (new String(myArray, "ISO-8859-1")), the special character
isn't properly converted... I see a ? instead of a é
Help me please ':-|
LudovicSystem.out.println goes to your terminal/console, right?
Are you sure your terminal can display the special char???
I'd try to do the debug output using JOptionPane.showMessageDialog -
Decode HTML escaped character references
sure, I can write
string.replace(" " , " ")
but obviously can't do that for all Unicode character references in the world, and surely this problem must be a routine library call .... but eh ... which? I don't seem to be able to find anything by googling.
thanks in advance@hugoT - thanks for the link to the list ...
... but eh .. I really don't want to do this myself, if there's a public library that will do it for me ... something like ... I send a string over, full of escaped character references, and get a nice and human readable string back.
this kind of bread and butter code must be out there somewhere (i hope) -
Decode HTML character in hyperlink parameter
Hi all,
I have some problem in passing parameters from a report to another. In particular, the LOVs of prompts have particular formatting:
1._ _ _ first value
2._ _ _ second value
Does anybody know how to decode "dots" and "dashes" in html syntax?
Thanks
RiccardoHi,
Are the "dots" and "dashes" in the value really causing problems ?
You can try enclosing the values within double quotes. Use Char(34) formula to include double quotes in the URL.
Note: If there is a space within the value, please replace the space with a '+' using Replace function and you will not have to use double quotes.
For example, replace
1._ _ _ first value
by
1._+_+_+first+value
I think it is the spaces within the values which can cause problem and not the dashes and dots.
Regards -
Error while replacing IF statements with DECODE function in procedure
Hi All,
I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
Procedure:
IF (var_int_sev = '0')
THEN
var_sev := '2';
ELSE
SELECT sev
INTO var_int_sev
FROM errorconfig
WHERE errorcode = var_errorcode;
var_sev := var_int_sev;
END IF;
I converted the above IF statement into DECODE function as mentioned below:
var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
But it throws below error at the select statement used inside DECODE.
Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
read this:
When your query takes too long ...
Maybe you are looking for
-
Urgent!!Error in the front end when trying to view a report
Hi All, I am getting this error when I am trying to view a report in the front-end. View Display Error Odbc driver returned an error (SQLExecDirectW). Error Details Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P State: HY000. Code: 10058. [NQODBC] [SQL_STAT
-
Trying to use a Nano with 10.2.8
Alrigth, I just bought an iPod Nano. On the car ride home, I see that you need 10.3.4 to use it. I can't get that unless I buy a new computer... which isn't gonna happen. I have an iMac G3, 10.2.8,iTunes 6.0.1, and a highspeed 2.0 USB. Can I use the
-
How to move a Preview digital signature?
I made a digital signature in Preview to use to sign pdfs. I did this on my Air because that has a camera (you have to take a picture of your signature). I want to move this digital signature I made on the Air to Preview on my Mac mini (where I don't
-
Errors occurs when localizing an Struts webapps in Tomcat5.0 under Linux.
I have an Struts webapps,which was deployed correctly and ran well in my Tomat5.0 under win2K. Then i copied the webapps to the Tomcat5.0_HOME/webapps/ under Linux. Then i copied all the struts *.jar files to the Tomcat5.0_HOME/common/lib. With the w
-
Firefox kde4 file type association
All I see is an empty list for applications in firefox preferences. How can i populate it , I am on kdemod4 http://bayimg.com/bAkeBaabD Last edited by venky80 (2008-08-13 07:19:38)