Using Java Service to call Canonicalizer

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);

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

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.

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

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>

Resolved my issue

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

-NP

1 Like

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.

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();
			
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.