webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Using Java Service to call Canonicalizer

  • 1.  Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 08:53 AM

    I created a consumer service which will call a service developed in .Net. As part of the process I need to canonilize my XML request. I was hoping I could create a Java service which will do this, but I am not seeing the library. Has anyone already done this, can I use maven at all to import the proper library, or do you know where to best capture the binary jar files.

    ~\IntegrationServer\instances\default\packages\FibCoaServices\code\source\sbaloan100k\work.java:10: error: package com.sun.org.apache.xml.internal.security.c14n does not exist
    
    import com.sun.org.apache.xml.internal.security.c14n.*;
    
    ~\IntegrationServer\instances\default\packages\FibCoaServices\code\source\sbaloan100k\work.java:43: error: cannot find symbol
    
    Canonicalizer canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods
    #Service-Designer


  • 2.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 09:04 AM

    The classes you want to use must be in the Integration server classpath , there are multiple ways to do this, please take a look at Adding Classes to the Server Classpath (softwareag.com) for the exact steps and options.

    -NP


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #Service-Designer


  • 3.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 09:14 AM

    Thank you for the response. I understand how to add it to the classpath, but what I am asking is has anyone already implemented a Java Service which incorporates Canonicalizer? What libraries are available in webMethods? Also, is this achievable in the flow services using the pub services? So far I have not seen anything and am left to assume I need to write this externally and create a jar file myself.


    #Service-Designer
    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 4.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 09:54 AM

    I understand ,I do not see a direct way of doing this using built-in services, but I would suggest you to refer the built in services for the pub.xml folder , to see if you could use those a combination of those services , would wait for more accurate answers from someone who has done this.
    -NP


    #Integration-Server-and-ESB
    #Service-Designer
    #webMethods
    #Flow-and-Java-services


  • 5.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 09:57 AM

    Basically I am trying to run the following through a canonicalizer if possible via flow service but if necessary a java service.

    <fiAPI xmlns="http://integration.fiapi.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <fiHeader Version="2.2">
    <Service Name="?" Version="9.0">
    <DateTime>2022-02-07T07:42:08-07:00</DateTime>
    <UUID>1d6a7a13-d38d-46a8-abeb-aea180b9f1b1</UUID>
    </Service>
    <Security>
    <AuthenticationMaterial>
    <PrincipalPWD>
    <EncryptedData>
    <CipherData xmlns="http://www.w3.org/2001/04/xmlenc#">
    <CipherValue>?</CipherValue>
    </CipherData>
    </EncryptedData>
    </PrincipalPWD>
    </AuthenticationMaterial>
    <PrincipalID>?</PrincipalID>
    <TrustRelationship xmlns="http://www.ITIWnet.com/">Application</TrustRelationship>
    </Security>
    <Client>
    <VendorID>?</VendorID>
    <AppID>?</AppID>
    <OrgID>?</OrgID>
    <SessionID></SessionID>
    </Client>
    <DataSource>
    <URI>?</URI>
    </DataSource>
    </fiHeader>
    <Request Echo="false" TypeOfRequest="Login" Version="1.1"></Request>
    </fiAPI>
    

    #Service-Designer
    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 11:00 AM


  • 7.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 07, 2022 11:16 AM

    Can you post how you resolved it for the benefit of others? I’m sure many others would have faced this.

    -NP


    #Service-Designer
    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 8.  RE: Using Java Service to call Canonicalizer

    Posted Tue February 08, 2022 05:48 PM

    What I did to resolve the problem was create my own function in java to canonicalize, converted it to a jar file, and installed it on the integration server and added it to the build path in Designer. A little disappointed I couldn’t get it to work in Java Service.


    #Integration-Server-and-ESB
    #webMethods
    #Service-Designer
    #Flow-and-Java-services


  • 9.  RE: Using Java Service to call Canonicalizer

    Posted Mon February 14, 2022 11:07 PM

    Figured out the issue with using Canonicalize() in my Java Service. I had to drop back to xmlsec-2.0.jar. Not sure why there was a parm conflict but this resolved the issue.

    This seems to work:

    		// pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String	inputXML = IDataUtil.getString( pipelineCursor, "inputXML" );
    pipelineCursor.destroy();
    
    byte[] bytes = inputXML.getBytes();
    ByteArrayOutputStream os = new ByteArrayOutputStream(); 
    Canonicalizer canon = null;
    
    Init.init();
    
    try {
    canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    } catch (InvalidCanonicalizerException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    byte [] canByte = null;
    try {
    canByte = canon.canonicalize(bytes);
    } catch (CanonicalizationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (ParserConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SAXException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    String newValue = null;
    try {
    newValue = new String (canByte, "Windows-1252");
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    
    String outputXML = newValue.replaceAll("(?:>)(\\s*)<", "><");
    
    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    IDataUtil.put( pipelineCursor_1, "outputXML", outputXML );
    pipelineCursor_1.destroy();
    
    

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #Service-Designer
    #webMethods