Ales Novak's old blog

     
 

Sun will buy SeeBeyond


Just look at SeeBeyond. Another link is at yahoo news. So now we have the best integration software on the planet.

XML, SAX and DOM too


Read as XML sucks... The subject was once a name of a speech of my two colleagues nominated for JavaOne session. Fortunately not accepted. That was before the web services buzz was all around. Maybe they were right. There is a sample of client/server communication, when using Web Services Security. One would think that we only need to send SUNW and Hello words to the other side. Do not forget to multiply that by 2 for server reply. Here we go:


run-sample:
     [echo] Running the simple.TestClient program....
     [java] Service URL=http://localhost:8080/securesimple/Ping
     [java] Jun 28, 2005 2:00:07 PM com.sun.xml.wss.filter.DumpFilter process
     [java] INFO: ==== Sending Message Start ====
     [java] <?xml version="1.0" encoding="UTF-8"?>
     [java] <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://xmlsoap.org/Ping" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     [java] <env:Header>
     [java] <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" env:mustUnderstand="1">
     [java] <wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="Id-7200843894568839789">MIIDWTCCAsKgAwIBAgIBAjANBgkqhkiG9w0BAQQFADB0MQswCQYDVQQGEwJOQTELMAkGA1UECBMC
     [java] TkExCzAJBgNVBAcTAk5BMQswCQYDVQQKEwJOQTELMAkGA1UECxMCTkExHjAcBgNVBAMTFWNlcnRp
     [java] ZmljYXRlLWF1dGhvcml0eTERMA8GCSqGSIb3DQEJARYCTkEwHhcNMDQwNDA5MjAyMDA0WhcNMDUw
     [java] NDA5MjAyMDA0WjByMQswCQYDVQQGEwJOQTELMAkGA1UECBMCTkExCzAJBgNVBAcTAk5BMQswCQYD
     [java] VQQKEwJOQTELMAkGA1UECxMCTkExHDAaBgNVBAMTE3h3cy1zZWN1cml0eS1jbGllbnQxETAPBgkq
     [java] hkiG9w0BCQEWAk5BMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChxbTlPz21PNp5YSh3Wr0Q
     [java] 97HhHOenXMI4G/mAkknS3gEFV8CJJR8sE2+WeweOk2M2UIpQLYHPE2mFKoe9SV82IW5o0dJwrh5J
     [java] ELSq9fR3x6wdE5/O8leY0dFL5zPtm4gWHU7b/pV1kfijrGiIBTO7M59oACxhHJE7RB0WYy1zUQID
     [java] AQABo4H8MIH5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENl
     [java] cnRpZmljYXRlMB0GA1UdDgQWBBSdEF+wTGtncGGY/Pd6MpAKaIRhtDCBngYDVR0jBIGWMIGTgBS1
     [java] BYo8LSYEn16yMWhvreilyanXfqF4pHYwdDELMAkGA1UEBhMCTkExCzAJBgNVBAgTAk5BMQswCQYD
     [java] VQQHEwJOQTELMAkGA1UEChMCTkExCzAJBgNVBAsTAk5BMR4wHAYDVQQDExVjZXJ0aWZpY2F0ZS1h
     [java] dXRob3JpdHkxETAPBgkqhkiG9w0BCQEWAk5BggEAMA0GCSqGSIb3DQEBBAUAA4GBAMxAGol7R7BT
     [java] BWW/Jv+51R0JAtWfZyI54qmU0cfYkgiIk5wp7LrVge4NlJwmlnq0exp5LKPB2gLqHVP9oK6PIEbS
     [java] P6yMzV0G2/qXbsi1UPQvQlKeAdkcsbYeq1WpQUzdNLCVg4eTIsoZQoosSdAiL672kRBEW2fDtRuK
     [java] qV+oNKQk</wsse:BinarySecurityToken>
     [java] <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
     [java] <ds:SignedInfo>
     [java] <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
     [java] <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
     [java] <ds:Reference URI="#Id-4825289659218818612">
     [java] <ds:Transforms>
     [java] <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
     [java] </ds:Transforms>
     [java] <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
     [java] <ds:DigestValue>letnI/+7kxBE7cq0wFwd4Rxr/xc=</ds:DigestValue>
     [java] </ds:Reference>
     [java] <ds:Reference URI="#Id-442752300277299994">
     [java] <ds:Transforms>
     [java] <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
     [java] </ds:Transforms>
     [java] <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
     [java] <ds:DigestValue>2AHArZHXUEG2g5os+Hfc/+IUySE=</ds:DigestValue>
     [java] </ds:Reference>
     [java] </ds:SignedInfo>
     [java] <ds:SignatureValue>
     [java] cHhgyrI+/Jq3qCoJ8XD2UMl+N4Mpma9fTdKNXhFwL72vTuZDOWYiim77ATLn4XQ+rxR8viM324V3
     [java] h9VRHziR+pmH+UoyjjI4rvRJSo/+U4H/lE95F/Nz3u2hCE0J+n0qbhj4PZPUXmJ+iPIOJK7Qh67K
     [java] ZutcDzA375eIg3kQfFU=
     [java] </ds:SignatureValue>
     [java] <ds:KeyInfo>
     [java] <wsse:SecurityTokenReference>
     [java] <wsse:Reference URI="#Id-7200843894568839789" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
     [java] </wsse:SecurityTokenReference>
     [java] </ds:KeyInfo>
     [java] </ds:Signature>
     [java] <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-442752300277299994">
     [java] <wsu:Created>2005-06-28T12:00:06Z</wsu:Created>
     [java] <wsu:Expires>2005-06-28T12:05:06Z</wsu:Expires>
     [java] </wsu:Timestamp>
     [java] </wsse:Security>
     [java] </env:Header>
     [java] <env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-4825289659218818612">
     [java] <ns0:Ping>
     [java] <ns0:ticket>SUNW</ns0:ticket>
     [java] <ns0:text>Hello !</ns0:text>
     [java] </ns0:Ping>
     [java] </env:Body>
     [java] </env:Envelope>
     [java] ==== Sending Message End ====




Do you love it? I do. Several colleagues of mine were laughing a lot - poor old C and assembler guys!

Which Java class writes this? A simple debug facility.


Something like:

[07/Apr/2005:17:32:53] WARNING (27486): CORE3283: stderr: Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
[07/Apr/2005:17:32:53] WARNING (27486): CORE3283: stderr: set, which is probably not what is desired.  Parser will use a default
[07/Apr/2005:17:32:53] WARNING (27486): CORE3283: stderr: ErrorHandler to print the first 10 errors.  Please call
...
was written in appserver logs. Go and find it out, told me my manager. Our customer is not happy :-) I remember this task from my previous NetBeans career. It is quite simple. Use this:

public class DebugPrintStream extends PrintStream {

    private PrintStream orig;
    private String match;

    /** Creates a new instance of DebugPrintStream */
    public DebugPrintStream(PrintStream out, String match) throws UnsupportedEncodingException {
        super(out, true, "UTF-8");

        assert orig != null;
        assert match != null;

        this.orig = out;
        this.match = match.toLowerCase();
    }

    protected void filter(String s) {
        if (s == null) {
            return;
        }

        if (s.toLowerCase().indexOf(match) >= 0) {
            Exception e = new Exception();
            getOrig().println("DEBUG PRINT STREAM MATCH");
            e.printStackTrace(getOrig());
        }
    }

...

    public void print(String s) {
        filter(s);
        getOrig().print(s);
    }

    // more overriden methods from PrintStream follows 
...

Not complete source code, but it should give you sense what it does - if somebody calls this new PrintStream, the message is examinated by filter(), if matched then stack trace is written. Second part of the puzzle is sequence:

            DebugPrintStream dpserr = new DebugPrintStream(System.err, "Warning: validation was turned on but an org.xml.sax.ErrorHandler");
            DebugPrintStream dpsout = new DebugPrintStream(System.out, "Warning: validation was turned on but an org.xml.sax.ErrorHandler");

            System.setErr(dpserr);
            System.setOut(dpsout);


Add the previous code to a Main class, a JSP or a Servlet. The result in this case was:

[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at test.DebugPrintStream.filter(DebugPrintStream.java:43)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at test.DebugPrintStream.println(DebugPrintStream.java:69)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.jaxp.DefaultValidationErrorHandler.error(DefaultValidationErrorHandler.java:74)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1232)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1737)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:3552)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1159)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:949)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at com.iplanet.am.util.XMLUtils.toDOMDocument(XMLUtils.java:98)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at com.iplanet.services.comm.share.ResponseSetParser.(ResponseSetParser.java:36)
[01/Jun/2005:13:26:14] WARNING (10980): CORE3283: stderr:       at com.iplanet.services.comm.share.ResponseSet.parseXML(ResponseSet.java:93)
... many more frames here ...

As it turned out, by looking into iplanet classes, the message appears because those classes are using a validating parser on XML messages which do not define their DTD. However, the validation is on only if some debug flags for that classes are on. Who turned them on in config files? We will never know - maybe the customer, maybe system integrator, ...

 
 
 
 
 

« červen 2005 »
PoÚtStČtSoNe
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
29
30
   
       
Today

[This is a Roller site]
Theme by Rowell Sotto.
 
© anovak