UTF-8 Chacters Extracting from Java XMLDocument - Revised so example works

I'm working on a string XML document that has utf-8 charcters within the
text nodes, e.g. &;lsquo; &;rsquo; In the original string these are ok, and when represented through to a web page appear correctly as a ‘ ’
quotes.
<p>Example XML Document :- </p>
<p><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?><br>
<!DOCTYPE art [<br>
<!ELEMENT art (#PCDATA | b)*><br>
<!ELEMENT b (#PCDATA)><br>
<!ENTITY lsquo &quot;&;#x2018;&quot;><br>
<!ENTITY rsquo &quot;&;#x2019;&quot;><br>
]><br>
<art><br>
This ZZZ&;lsquo;La Sapienza&;rsquo; di Roma <b>some
Text</b><br>
ZZZZ&;lsquo;La Sapienza&;rsquo; 00185 ZZZZ<br>
</art></p>
<p>However if i use the oracle.xml.parser.v2.DOMParser to create a
oracle.xml.parser.v2.XMLDocument from the String, I cannot get the text from the
nodes correctly, using oracle.xml.parser.v2.XMLDocument.print(System.out) or
through the org.w3c.dom.Node.getNodeValue().</p>
<p>I need to Extract the <art> tags data,  the resulting text must be
:-</p>
<p>    <i>This ZZZ&;lsquo;La Sapienza&;rsquo; di Roma <b>some Text</b>ZZZZ&;lsquo;La Sapienza&;rsquo; 00185
ZZZZ</i></p>
<p>AND NOT :-</p>
<p>      This ZZZbLa Sapienzab
di Roma <b>some Text</b>ZZZZbLa
Sapienzab 00185 ZZZZ</p>
<p>AND NOT :-</p>
<p>      <i>This ZZZ&lsquo;La Sapienza&rsquo; di Roma <b>some Text</b>ZZZZ&lsquo;La Sapienza&rsquo; 00185
ZZZZ</i></p>
<p>Example Program,  Just copy &; Paste into Jdeveloper</p>
<p>Project Libraries Required  :- Oracle XML Parser 2.0 ( D:\jdev323\lib\xmlparserv2.jar
)</p>
<p>COPY FROM HERE >></p>
<p> import java.io.IOException;<br>
import org.w3c.dom.Node;<br>
import org.xml.sax.SAXException;<br>
import oracle.xml.parser.v2.XMLDocument;<br>
import oracle.xml.parser.v2.DOMParser;<br>
import oracle.xml.parser.v2.XSLException;<br>
import org.xml.sax.InputSource;<br>
import java.io.StringReader;<br>
<br>
public class Class3 extends Object {<br>
<br>
public Class3 () throws IOException , SAXException, XSLException{<br>
String docText =<br>
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"\n"+<br>
"<!DOCTYPE art [" + "\n"+<br>
"<!ELEMENT art (#PCDATA | b)*>" +"\n"+<br>
"<!ELEMENT b (#PCDATA)>" +"\n"+<br>
"<!ENTITY lsquo \"&;#x2018;\">" +"\n"+<br>
"<!ENTITY rsquo \"&;#x2019;\">" +"\n"+<br>
"]>" +"\n"+<br>
"<art>" +"\n"+<br>
" This ZZZ&;lsquo;La Sapienza&;rsquo; di Roma <b>some Text</b>"+"\n"+<br>
" ZZZZ&;lsquo;La Sapienza&;rsquo; 00185 ZZZZ" +"\n"+<br>
"</art>" + "\n";<br>
System.out.println("----------------------------------------");<br>
System.out.println("Original String Value ");<br>
System.out.println("----------------------------------------");<br>
System.out.println(docText);<br>
System.out.println("----------------------------------------");<br>
System.out.println("Value from XMLDocument.Print(Systen.out)");<br>
System.out.println("----------------------------------------");<br>
InputSource input = new InputSource(new StringReader(docText));<br>
DOMParser xp = new DOMParser();<br>
xp.setValidationMode(false);<br>
xp.setPreserveWhitespace(false);<br>
xp.parse (input);<br>
XMLDocument xMLDocument = (XMLDocument)xp.getDocument();<br>
xMLDocument.print(System.out );<br>
<br>
System.out.println("----------------------------------------");<br>
System.out.println("Value from Node Walk");<br>
System.out.println("----------------------------------------");<br>
Node theNode = xMLDocument.getFirstChild();<br>
this.walkNode(theNode);<br>
}<br>
<br>
public void showNode (Node inNode) {<br>
System.out.println(inNode.getNodeName() + " <--> "<br>
+ inNode.getNodeType() + " <--> "<br>
+ inNode.getNodeValue() + " <--> ");<br>
<br>
Node kid=inNode.getFirstChild();<br>
if(kid==null) {<br>
} else {<br>
walkNode(kid);<br>
}<br>
}<br>
<br>
public void walkNode (Node theFirst) {<br>
while(null!=theFirst){<br>
showNode(theFirst);<br>
theFirst=theFirst.getNextSibling();<br>
}<br>
}<br>
<br>
public static void main(String[] args) throws Exception {<br>
Class3 class3 = new Class3();<br>
<br>
}<br>
}<br>
<<  END HERE</p>
null

import java.io.IOException;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XSLException;
import org.xml.sax.InputSource;
import java.io.StringReader;
public class Class3 extends Object {
public Class3 () throws IOException , SAXException, XSLException{
String docText =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"\n"+
"<!DOCTYPE art [" + "\n"+
"<!ELEMENT art (#PCDATA | b)*>" +"\n"+
"<!ELEMENT b (#PCDATA)>" +"\n"+
"<!ENTITY lsquo \"&#x2018;\">" +"\n"+
"<!ENTITY rsquo \"&#x2019;\">" +"\n"+
"]>" +"\n"+
"<art>" +"\n"+
" This ZZZ&lsquo;La Sapienza&rsquo; di Roma <b>some Text</b>"+"\n"+
" ZZZZ&lsquo;La Sapienza&rsquo; 00185 ZZZZ" +"\n"+
"</art>" + "\n";
System.out.println("----------------------------------------");
System.out.println("Original String Value ");
System.out.println("----------------------------------------");
System.out.println(docText);
System.out.println("----------------------------------------");
System.out.println("Value from XMLDocument.Print(Systen.out)");
System.out.println("----------------------------------------");
InputSource input = new InputSource(new StringReader(docText));
DOMParser xp = new DOMParser();
xp.setValidationMode(false);
xp.setPreserveWhitespace(false);
xp.parse (input);
XMLDocument xMLDocument = (XMLDocument)xp.getDocument();
xMLDocument.print(System.out);
System.out.println("----------------------------------------");
System.out.println("Value from Node Walk");
System.out.println("----------------------------------------");
Node theNode = xMLDocument.getFirstChild();
this.walkNode(theNode);
public void showNode (Node inNode) {
System.out.println(inNode.getNodeName() + " <--> "
+ inNode.getNodeType() + " <--> "
+ inNode.getNodeValue() + " <--> ");
Node kid=inNode.getFirstChild();
if(kid==null) {
} else {
walkNode(kid);
public void walkNode (Node theFirst) {
while(null!=theFirst){
showNode(theFirst);
theFirst=theFirst.getNextSibling();
public static void main(String[] args) throws Exception {
Class3 class3 = new Class3();
}

Similar Messages

  • UTF-8 Chacters Extracting from XMLDocument

    I'm working on translating a string document that has utf-8 charcters within the text nodes, e.g. &lsquo &rsquo. In the original string these are 100% ok, and when represented through to a web page appear correctly as a left single and righ single quote.
    However if i use the oracle.xml.parser.v2.DOMParser to create a oracle.xml.parser.v2.XMLDocument from the String, I cannot get the text from the nodes correctly, using oracle.xml.parser.v2.XMLDocument.print(System.out)
    String xdoc =
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" +
    "<!DOCTYPE art SYSTEM \"simple.dtd\">" + "\n" +
    "<art>ThisZZZ&lsquo;La Sapienza&rsquo; di Roma <b>stuff</b> ZZZZ&lsquo;La Sapienza&rsquo; di Roma. P.le Al 00185 ZZZZ" +
    "</art>" + "\n";
    XMLDocument xMLDocument = XMLHelper.parse(xdoc,masterBaseStyleUrl);
    xMLDocument.print(System.out);
    Results in
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE art SYSTEM "simple.dtd">
    <art>ThisZZZbLa Sapienzab di Roma <b>stuff</b> ZZZZbLa Sapienzab di Roma. P.le Al 00185 </art>
    i've tried, org.w3c.dom.Node.getNodeValue() and others but they all corrupt the output.
    Any help on accessing the original document values through the xmldocument would be great, i.e. the &lsquo; and &rsquo.
    null

    I'm working on translating a string document that has utf-8 charcters within the text nodes, e.g. &lsquo &rsquo. In the original string these are 100% ok, and when represented through to a web page appear correctly as a left single and righ single quote.
    However if i use the oracle.xml.parser.v2.DOMParser to create a oracle.xml.parser.v2.XMLDocument from the String, I cannot get the text from the nodes correctly, using oracle.xml.parser.v2.XMLDocument.print(System.out)
    String xdoc =
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" +
    "<!DOCTYPE art SYSTEM \"simple.dtd\">" + "\n" +
    "<art>ThisZZZ&lsquo;La Sapienza&rsquo; di Roma <b>stuff</b> ZZZZ&lsquo;La Sapienza&rsquo; di Roma. P.le Al 00185 ZZZZ" +
    "</art>" + "\n";
    XMLDocument xMLDocument = XMLHelper.parse(xdoc,masterBaseStyleUrl);
    xMLDocument.print(System.out);
    Results in
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE art SYSTEM "simple.dtd">
    <art>ThisZZZbLa Sapienzab di Roma <b>stuff</b> ZZZZbLa Sapienzab di Roma. P.le Al 00185 </art>
    i've tried, org.w3c.dom.Node.getNodeValue() and others but they all corrupt the output.
    Any help on accessing the original document values through the xmldocument would be great, i.e. the &lsquo; and &rsquo.
    null

  • Trouble to invoke BPEL from Java Client following rmi example

    I still have troubles to invoke my BPEL process from Java Client by following tutorial sample of 102.InvokingProcesses/rmi .
    I created my Java class within NetBeans IDE. And the following line of code return null for url,
    java.net.URL url = ClassLoader.getSystemResource("context.properties");
    I think that I need to have SystemResource set up somewhere, how should I do that?

    if you using oc4j.. then please make a small change in oc4j_context.properties
    from
    java.naming.provider.url=[java.naming.provider.url]
    to
    java.naming.provider.url=ormi://hostname/orabpel
    And please make sure the context.properties file which gets copied to classes/context.properties has this above entry. For more details please refer to build.xml under rmi folder.
    Please do let me know if you face any issue.

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '&lt;&lt;ALL FILES&gt;&gt;', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • How to call a php function from java...

    helllo fellow java developers!
    Im trying to figure out how I can call a php function from my java code.
    I know it sounds a bit unintiutive, seeing how java is a rich programming language, BUT java simply cannot do the task that the php script can do. It simply acts differently.
    So I am trying to call a php function, that returns a string object, and capture that string object....
    is this possible?
    something like....
    String strMyString = phpFunction( strVariable )
    ???????/ any ideaS?

    idea #1 - come up with a better plan that doesn't involve invoking php from java.
    Give one example of something php can do that java can't.
    idea #2 - forget java, and just write it in php.
    Involving multiple frameworks/languages/runtime environments is a recipe for an overcomplicated solution that will be impossible to maintain.
    I'd say keep it simple and stupid, and stick with one language.
    If you're still hooked on the idea, maybe try [this link|http://www.infoq.com/news/2007/10/php-java-stack]

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Execute shell command from Java

    Hi all,
    I need some idea for executing shell script from Java programe.
    For example i have start.sh script in /tmp/start.sh  folder of unix server.
    I want to execute shell script from local java code.
    Any idea on this.

    Hi,
           Read the following articles/posts, maybe this could help you:
          How to execute shell command from Java
    Running system commands in Java applications | java exec example | alvinalexander.com
    Want to invoke a linux shell command from Java - Stack Overflow

  • Reading selection parameters of transaction from Java

    Hi everyone,
    I 'm trying to find a way to read the selection parameters of a transaction from Java code. For example, the transaction MM03 (Display Material) expects a parameter called RMMG1-MATNR. I would like to be able to get the parameter's name in Java code via some RFC using JCO.
    Regards,
    Yoav.

    When the write end of the FIFO pipe is closedNamed pipes can be opened through several file desciptors. When all open file desriptors referring to a pipe are closed, only then is EOF indicated at the reading side. Named pipes "dwell" in the file system, and can be accessed as files through their names in the file system.

  • Installing Java 7 from Oracle just made Applets not work, how to fix

    Mac 10.7.4. I tried installing Java 7 from Oracle, but all it did was remove half the prefs from Java and make Applets not work. How do I revert/reinstall Java?

    Here you go!
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Extract d data from Java

    Dear experts,
    My company is implementing SAP newly.Right now no Data in my SAP system.My company requirement is just by sending the employee id the perticular employees salary should be generated in the SAP system.Again if the employee wants further details in the generated salary means if he click on any thing in the salary screen the detailed information should be extracted from the JAVA application.They don't want to post all the Java application data into SAP.Just by sending the employee id there should be generate SALARY of that employee in SAP and if further details if the employee wants to see then that shoul be extracted from the JAVA application.My Java application using MYSQL database.Please kindly suggest me how can it possible and any suggested links for my requirement.Please send me the links and the process how it possible.

    At SAP system, maintain a user interface through an ABAP report which internally makes a client ABAP proxy call Or calls an RFC. Both are suitable for synchronous communication. XI can therefore use ABAP proxy or RFC adapter at sender. The data from the receiver can be retrieved using receiver JDBC adapter of XI.
    Regards,
    Prateek

  • DOS 11g SOA have the Locator API's - How to Invoke a BPEL process from Java

    In BPEL 10.1.3.1, a java client could use the "Locator" API's to look up a BPEL service and invoke it directly from Java,
    Is that still present in SOA 11g ? Or is there another way to look up the BPEL process ...
    Here's an example of the 10g BPEL Service locator facilities :
    Get the BPEL service locator. This is retrieved as follows:
    loc = new Locator(domain, domainPassword);
    The initial installation BPEL domain is "domain" and the initial password is "bpel". We then use the locator to get the delivery service. We could also use the locator to retrieve the workflow service.
    IDeliveryService svc = (IDeliveryService)loc.lookupService(IDeliveryService.SERVICE_NAME);
    Now we have the delivery service we can "deliver" requests to the BPEL process. To do this we first need to create a new message.
    NormalizedMessage msg = new NormalizedMessage();
    String content = "<SyncHelloWorldProcessRequest xmlns=\"http://antony.blog/SyncHelloWorld\">"+
    "<input>"+
    name+
    "</input>"+
    "</SyncHelloWorldProcessRequest>";
    msg.addPart(msgPart, content);

    Can you please tell me how to include adf binding.ws in composite.xml ? My composite.xml for your ref:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SOA Modeler version 1.0 at [11/1/10 5:41 PM]. -->
    <composite name="BPEL2"
    revision="1.0"
    label="2010-11-01_17-41-11_593"
    mode="active"
    state="on"
    xmlns="http://xmlns.oracle.com/sca/1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
    xmlns:ui="http://xmlns.oracle.com/soa/designer/">
    <import namespace="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1"
    location="BPELProcess1.wsdl" importType="wsdl"/>
    <service name="bpelprocess1_client_ep" ui:wsdlLocation="BPELProcess1.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.interface(BPELProcess1)"/>
    <binding.ws port="http://xmlns.oracle.com/CallBPEL_jws/BPEL2/BPELProcess1#wsdl.endpoint(bpelprocess1_client_ep/BPELProcess1_pt)"/>
    </service>
    <component name="BPELProcess1">
    <implementation.bpel src="BPELProcess1.bpel"/>
    </component>
    <wire>
    <source.uri>bpelprocess1_client_ep</source.uri>
    <target.uri>BPELProcess1/bpelprocess1_client</target.uri>
    </wire>
    </composite>
    Eric, when I select the BPEL wsdl file in "Create Web Service Data Control" wizard, immediately I am getting the error. When I click 'OK', the 'Service' dropdown is disabled and blank in the wizard.
    Thanks for pointing to the sample application URL. But it is built in jdev 10g. Can I migrate it to 11g?
    Thanks both of you!

  • DBMS_XDB.CREATERESOURCE from JAVA

    Hi all,
    i'm trying to load XML-data into the database with the following pseudocode:
    SQLText := "DECLARE
                  retB boolean;
                  XMLDoc XMLType;
                BEGIN
                  XMLDoc := XMLType(?);
                  retB   := DBMS_XDB.CREATERESOURCE('Resourcename', XMLDoc);
                END";
    SQLStmt := (OraclePreparedStatement) _conn.prepareStatement(SQLText);
    SQLStmt.setString(1, xml);
    SQLStmt.execute();
    It works in JAVA with one exception. All characters using more than one byte in UTF-8 are double encoded. That means, if the XML-String contains an german umlaut &auml; (U+00E4) this character is encoded as "C3 A4" in the string. After submitting the XML to the database the &auml; has the value C3 83 C2 A4 => the value C3 is encoded as C3 83 and the value A4 is encoded as C2 A4.
    Thats no problem if i query the documents from Java because the way back is the same. But if i retrieve the document over the protocoll server (WebDav or FTP) the character encoding is corrupted (2 characters for &auml;).
    I am using Ora 11.2.0.1 on Linux with ojdbc6.jar. My NLS settings are as follows:
    NLS_LANGUAGE             GERMAN
    NLS_TERRITORY            GERMANY
    NLS_CHARACTERSET         AL32UTF8
    NLS_NCHAR_CHARACTERSET   AL16UTF16
    On the client GERMAN_GERMANY.WE8MSWIN1252, but i also tried with SET NLS_LANG=GERMAN_GERMANY.AL32UTF8 because of the UTF coding of the XML string.
    What I am doing the wrong way?
    Thanks for your help,
    regards
    Frank

    Hi odie_63,
    thanks for your reply. I have extracted the relevant code of the program into a tiny test application.
    package project1;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.text.MessageFormat;
    import oracle.jdbc.OraclePreparedStatement;
    import oracle.ucp.jdbc.PoolDataSource;
    import oracle.ucp.jdbc.PoolDataSourceFactory;
    public class Application1 {
        public static void main(String[] args) {
            try {
                doSimpleTest();
            } catch (Exception e) {
                e.printStackTrace();
        public static void doSimpleTest(){
            System.out.println("doing simple test case...");
            final String insertSQL    = "  DECLARE\n" +
                                        "    retB boolean;\n" +
                                        "    XMLDoc XMLType;\n" +
                                        "  BEGIN\n" +
                                        "    XMLDoc := XMLType(?);\n" +
                                        "    retB   := DBMS_XDB.CREATERESOURCE({0},XMLDoc);         \n" +
                                        "  END;";  
            final String xml            = "<?xml version=\"1.0\" encoding=\"utf-8\"?><test xmlns=\"http://www.gfai.de/Test\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.gfai.de/Test http://www.gfai.de/Test\">äöü</test>";
            String SQL_QUERY          = null;
            PoolDataSource _pds       = null;
            Connection _conn          = null;
            OraclePreparedStatement s = null;
            try{
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                //Creating a pool-enabled data source
                _pds = PoolDataSourceFactory.getPoolDataSource();
                //Setting connection properties of the data source
                _pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
                _pds.setURL("jdbc:oracle:thin:@10.10.182.110:1521:ORALX64");
                _pds.setUser("test");
                _pds.setPassword("tset");
                //Setting pool properties
                _pds.setInitialPoolSize(5);
                _pds.setMinPoolSize(5);
                _pds.setMaxPoolSize(10);
                // connection           
                _conn = _pds.getConnection();  
                // Insert
                SQL_QUERY = MessageFormat.format(insertSQL, new Object[]{"'/public/test/test.xml'"});
                s = (OraclePreparedStatement) _conn.prepareStatement(SQL_QUERY);
                s.setString(1, new String(xml.getBytes("UTF-8")));
                s.execute();
                System.out.println("inserted...");
            catch(Exception ex){
                ex.printStackTrace();
            finally{
                try{s.close();_conn.close();}catch(Exception ex){};
            return;
    Before running the test it's required to set up the user test and the XML-schema. I have done it with the following lines of code:
    CONNECT SYSTEM;
    CREATE USER TEST IDENTIFIED BY "tset";
    GRANT CREATE SESSION TO TEST;
    GRANT RESOURCE TO TEST;
    DECLARE
      RETB BOOLEAN;
    BEGIN
      RETB := DBMS_XDB.CREATEFOLDER('/sys/schemas/PUBLIC/www.gfai.de');
      RETB := DBMS_XDB.CREATEFOLDER('/sys/schemas/PUBLIC/www.gfai.de/test');
      RETB := DBMS_XDB.CREATEFOLDER('/public/test');
      COMMIT;
    END;
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '/home/oracle';
    GRANT  READ ON DIRECTORY TEST_DIR TO test;
    BEGIN
      DBMS_XMLSCHEMA.registerSchema(
    SCHEMAURL => 'http://www.gfai.de/Test',
    SCHEMADOC => BFILENAME('TEST_DIR','Test.xsd'),
    LOCAL => FALSE,
    GENTYPES => TRUE,
    GENTABLES => TRUE);
    END;
    After executing the test case i get the following results with sqlplus:
    SQL> select dump(extractvalue(object_value,'/test')) from test_document;
    DUMP(EXTRACTVALUE(OBJECT_VALUE,'/TEST'))
    Typ=1 Len=12: 195,131,194,164,195,131,194,182,195,131,194,188
    SQL>
    The whole document is saved as
    SQL> select xdburitype('/public/test/test.xml').getblob() from dual;
    XDBURITYPE('/PUBLIC/TEST/TEST.XML').GETBLOB()
    3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E0A3C
    7465737420786D6C6E733D22687474703A2F2F7777772E676661692E64652F546573742220786D6C
    6E733A7873693D22687474703A2F2F7777772E77332E6F72672F323030312F584D4C536368656D61
    2D696E7374616E636522207873693A736368656D614C6F636174696F6E3D22687474703A2F2F7777
    772E676661692E64652F5465737420687474703A2F2F7777772E676661692E64652F54657374223E
    C383C2A4C383C2B6C383C2BC3C2F746573743E0A
    SQL>
    The schema definition file is as follows:
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns="http://www.gfai.de/Test"
                targetNamespace="http://www.gfai.de/Test"
                elementFormDefault="qualified"
                xmlns:xdb="http://xmlns.oracle.com/xdb"
                xdb:storeVarrayAsTable="true">
      <xsd:element name="test" xdb:defaultTableSchema="TEST"
                   xdb:defaultTable="TEST_DOCUMENT">
        <xsd:complexType>
          <xsd:simpleContent>
            <xsd:extension base="xsd:string">
            </xsd:extension>
          </xsd:simpleContent>
        </xsd:complexType>
      </xsd:element>
    </xsd:Schema>
    thanks again,
    regards
    Frank

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • Error while running EJB from java client on JBOSS

    Hi
    As i am new to EJB i have created a helloworld application in ejb which is working fine when i try to call it from servlet but when i try to invoke the same ejb from java client (i.e from diff jvm) on jboss i got the following error:
    javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused]]]
         at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1399)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
         at javax.naming.InitialContext.lookup(InitialContext.java:351)
         at com.gl.TestClient.main(TestClient.java:39)
    Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused]]
         at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:254)
         at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1370)
         ... 4 more
    Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused]
         at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:228)
         ... 5 more
    Caused by: java.net.ConnectException: Connection refused
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
         at java.net.Socket.connect(Socket.java:519)
         at java.net.Socket.connect(Socket.java:469)
         at java.net.Socket.<init>(Socket.java:366)
         at java.net.Socket.<init>(Socket.java:266)
         at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:69)
         at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:62)
         at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:224)
         ... 5 more
    Following is my code:
    Home Interface:
    package com.gl;
    import javax.ejb.CreateException;
    public interface testHome extends EJBHome {
         String JNDI_NAME = "testBean";
         public     test create()
         throws java.rmi.RemoteException,CreateException;
    Remote Interface:
    package com.gl;
    import java.rmi.RemoteException;
    import javax.ejb.EJBObject;
    public interface test extends EJBObject {
         public String welcomeMessage() throws RemoteException;
    Bean:
    package com.gl;
    import java.rmi.RemoteException;
    import javax.ejb.EJBException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    public class testbean implements SessionBean {
         public void ejbActivate() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
         public void ejbPassivate() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
         public void ejbRemove() throws EJBException, RemoteException {
              // TODO Auto-generated method stub
         public void setSessionContext(SessionContext arg0) throws EJBException,
                   RemoteException {
              // TODO Auto-generated method stub
         public void ejbCreate(){}
         public String welcomeMessage(){
              return "Welcome to the World of EJB";
    ejb-jar.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <enterprise-beans>
    <session>
    <ejb-name>testBean</ejb-name>
    <home>com.gl.testHome</home>
    <remote>com.gl.test</remote>
    <ejb-class>com.gl.testbean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    </ejb-jar>
    jboss.xml:
    <?xml version='1.0' ?>
    <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
    <jboss>
    <enterprise-beans>
    <entity>
    <ejb-name>testBean</ejb-name>
    <jndi-name>testBean</jndi-name>
    </entity>
    </enterprise-beans>
    </jboss>
    Client code:
    package com.gl;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
    public class TestClient {
         public static void main(String[] args) throws Exception{
                   try{
                   /*     Properties props=new Properties();
                        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                        props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                        props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                   Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,
    "org.jnp.interfaces.NamingContextFactory");
    props.put(Context.PROVIDER_URL, "localhost:1099");
                        System.out.println("Properties ok");
                        //env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
                        //env.put(Context.PROVIDER_URL,"http://localhost:8080");
                        //env.put(Context.SECURITY_PRINCIPAL, "");
                        //env.put(Context.SECURITY_CREDENTIALS, "");
                        Context ctx=new InitialContext(props);
                        System.out.println("context ok");
                        //testHome home = (testHome)ctx.lookup("testBean");
                        Object obj = ctx.lookup ("testBean");
                        System.out.println("ojb = " + obj);
                        testHome ejbHome = (testHome)PortableRemoteObject.narrow(obj,testHome.class);
                   test ejbObject = ejbHome.create();
                   String message = ejbObject.welcomeMessage();
                        System.out.println("home ok");
                        System.out.println("remote ok");
                        System.out.println(message);
                        catch(Exception e){e.printStackTrace();}
    I am able to successfully deployed my ejb on JBOSS but i m getting above error when i am trying to invoke ejb from java client.
    kindly suggest me something to solve this issue.
    Regards
    Gagan
    Edited by: Gagan2914 on Aug 26, 2008 3:28 AM

    Is it a remote lookup? Then maybe this will help:
    [http://wiki.jboss.org/wiki/JBoss42FAQ]
    - Roy

  • Calling secured webservice from java

    Hi Experts,
    I am trying to call a secured webservice from java.
    I got the code to call a non secured web service in java.
    What changes do i need to do in this to call a secured webservice.
    Please help me.
    Thank you
    Regards
    Gayaz
    calling unsecured webservice
    package wscall1;
    import java.io.BufferedReader;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.StringBufferInputStream;
    import java.io.StringReader;
    import java.io.StringWriter;
    import java.io.Writer;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.security.Permission;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.ParserConfigurationException;
    import org.apache.xml.serialize.OutputFormat;
    import org.apache.xml.serialize.XMLSerializer;
    import org.w3c.css.sac.InputSource;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class WSCall2 {
    public WSCall2() {
    super();
    public static void main(String[] args) {
    try {
    WSCall2 ss = new WSCall2();
    System.out.println(ss.getWeather("Atlanta"));
    } catch (Exception e) {
    e.printStackTrace();
    public String getWeather(String city) throws MalformedURLException, IOException {
    //Code to make a webservice HTTP request
    String responseString = "";
    String outputString = "";
    String wsURL = "https://ewm52rdv:25100/Saws/SawsService";
    URL url = new URL(wsURL);
    URLConnection connection = url.openConnection();
    HttpURLConnection httpConn = (HttpURLConnection)connection;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    //Permission p= httpConn.getPermission();
    String xmlInput =
    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://www.ventyx.com/ServiceSuite\">\n" +
    " <soapenv:Header>\n" +
    "     <soapenv:Security>\n" +
    " <soapenv:UsernameToken>\n" +
    " <soapenv:Username>sawsuser</soapenv:Username>\n" +
    " <soapenv:Password>sawsuser1</soapenv:Password>\n" +
    " </soapenv:UsernameToken>\n" +
    " </soapenv:Security>" + "</soapenv:Header>" + " <soapenv:Body>\n" +
    " <ser:GetUser>\n" +
    " <request><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
                "                        <GetUser xmlns=\"http://www.ventyx.com/ServiceSuite\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
                "                        <UserId>rs24363t</UserId>\n" +
                "                        </GetUser>]]>\n" +
    " </request>\n" +
    " </ser:GetUser>\n" +
    " </soapenv:Body>\n" +
    "</soapenv:Envelope>";
    byte[] buffer = new byte[xmlInput.length()];
    buffer = xmlInput.getBytes();
    bout.write(buffer);
    byte[] b = bout.toByteArray();
    String SOAPAction = "GetUser";
    // Set the appropriate HTTP parameters.
    httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
    httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    httpConn.setRequestProperty("SOAPAction", SOAPAction);
    // System.out.println( "opening service for [" + httpConn.getURL() + "]" );
    httpConn.setRequestMethod("POST");
    httpConn.setDoOutput(true);
    httpConn.setDoInput(true);
    OutputStream out = httpConn.getOutputStream();
    //Write the content of the request to the outputstream of the HTTP Connection.
    out.write(b);
    out.close();
    //Ready with sending the request.
    //Read the response.
    InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
    BufferedReader in = new BufferedReader(isr);
    //Write the SOAP message response to a String.
    while ((responseString = in.readLine()) != null) {
    outputString = outputString + responseString;
    //Parse the String output to a org.w3c.dom.Document and be able to reach every node with the org.w3c.dom API.
    Document document = parseXmlFile(outputString);
    NodeList nodeLst = document.getElementsByTagName("User");
    String weatherResult = nodeLst.item(0).getTextContent();
    System.out.println("Weather: " + weatherResult);
    //Write the SOAP message formatted to the console.
    String formattedSOAPResponse = formatXML(outputString);
    System.out.println(formattedSOAPResponse);
    return weatherResult;
    public String formatXML(String unformattedXml) {
    try {
    Document document = parseXmlFile(unformattedXml);
    OutputFormat format = new OutputFormat(document);
    format.setIndenting(true);
    format.setIndent(3);
    format.setOmitXMLDeclaration(true);
    Writer out = new StringWriter();
    XMLSerializer serializer = new XMLSerializer(out, format);
    serializer.serialize(document);
    return out.toString();
    } catch (IOException e) {
    throw new RuntimeException(e);
    private Document parseXmlFile(String in) {
    try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(in));
    InputStream ins = new StringBufferInputStream(in);
    return db.parse(ins);
    } catch (ParserConfigurationException e) {
    throw new RuntimeException(e);
    } catch (SAXException e) {
    throw new RuntimeException(e);
    } catch (IOException e) {
    throw new RuntimeException(e);
    } catch (Exception e) {
    throw new RuntimeException(e);
    static {
    javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
    public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
    if (hostname.equals("ewm52rdv")) {
    return true;
    return false;
    }

    Gayaz  wrote:
    What we are trying is we are invoking webservice by passing SOAP request and we will get soap response back.I understand what you're trying to do, the problem is with tools you're using it will take a while for you do anything a little away from the trivial... Using string concatenation and URL connection and HTTP post to call webservices is like to use a hand drill... It may work well to go through soft wood, but it will take a lot of effort against a concrete wall...
    JAX-WS and JAXB and annotations will do everything for you in a couple of lines and IMHO you will take longer to figure out how to do everything by hand than to learn those technologies... they are standard java, no need to add any additional jars...
    That's my thought, hope it helps...
    Cheers,
    Vlad

Maybe you are looking for

  • Uninstall is incomplete and I need to reinstall software - don't know what to do

    Hello, After cleaning my hard drive Illustrator couldn't open any of its own .ai files and it was suggested in the forum that I reinstall CS6.  So I did an uninstall in Vista but found more CS6 lurking around in other directories, including fonts, .d

  • Itunes wont sync tunes to iphone

    I am trying to sync some tunes to my iphone, but it wont sync, nor can I drag and drop to the fone and do it that way. Have tried uninstalling itunes and reinstalling it. Any ideas?!?!?!?!?! 

  • MOVED: Beep Codes with One Video Card

    This topic has been moved to Intel Core-iX boards. https://forum-en.msi.com/index.php?topic=152148.0

  • Import QuickTime file to iMovie 9= nothing

    Suddenly, iMovie 9.01 would not recognise my latest Sony recording, perhaps because it was recorded in HD. Previous efforts have gone smoothly, I do not know if the previous recordings were recorded in HD or SD. So, it was imported to a newer MacBook

  • EPCF between BW Report and Par IView

    Hi, Can anyone please let me know how can I pass some value from a BW reoprt to another iView which has been developed using JSPDynpage. Thanks, Vivek