Using Java Service to call Canonicalizer

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