public static String encodeForRedirect(final String str){
  String classMethod="SAML2Utils.encodeForRedirect: ";
  byte[] input;
  try {
    input=str.getBytes("UTF-8");
  }
 catch (  UnsupportedEncodingException uee) {
    debug.error(classMethod + "cannot get byte array: ",uee);
    return null;
  }
  Deflater deflater=new Deflater(Deflater.DEFAULT_COMPRESSION,true);
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  DeflaterOutputStream deflaterOutputStream=new DeflaterOutputStream(out,deflater);
  try {
    deflaterOutputStream.write(input);
  }
 catch (  IOException e) {
    debug.error(classMethod + "There was a problem compressing the input",e);
    return null;
  }
 finally {
    IOUtils.closeIfNotNull(deflaterOutputStream);
  }
  String encoded=URLEncDec.encode(Base64.encode(out.toByteArray()));
  if (debug.messageEnabled()) {
    debug.message(classMethod + "out string length : " + encoded.length());
    debug.message(classMethod + "out string is ===>" + encoded+ "<===");
  }
  return encoded;
}

public static String encodeForRedirect ( final String str ) { String classMethod = "SAML2Utils.encodeForRedirect: " ; byte [ ] input ; try { input = str . getBytes ( "UTF-8" ) ; } catch ( UnsupportedEncodingException uee ) { debug . error ( classMethod + "cannot get byte array: " , uee ) ; return null ; } Deflater deflater = new Deflater ( Deflater . DEFAULT_COMPRESSION , true ) ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream ( out , deflater ) ; try { deflaterOutputStream . write ( input ) ; } catch ( IOException e ) { debug . error ( classMethod + "There was a problem compressing the input" , e ) ; return null ; } finally { IOUtils . closeIfNotNull ( deflaterOutputStream ) ; } String encoded = URLEncDec . encode ( Base64 . encode ( out . toByteArray ( ) ) ) ; if ( debug . messageEnabled ( ) ) { debug . message ( classMethod + "out string length : " + encoded . length ( ) ) ; debug . message ( classMethod + "out string is ===>" + encoded + "<===" ) ; } return encoded ; }
returns the encoded request message . the saml request message must be encoded before being transmitted . the request message is encoded as follows : 1 . url encoded using the deflate compression method . 2 . then the message is base - 64 encoded according to the rules specified in rfc2045 .
