Skip to Content.
Sympa Menu

mace-opensaml-users - Re: UTF-8 character encoding

Subject: OpenSAML user discussion

List archive

Re: UTF-8 character encoding


Chronological Thread 
  • From: "Prasanna Krishna" <>
  • To:
  • Subject: Re: UTF-8 character encoding
  • Date: Wed, 01 Aug 2007 22:23:53 +0000

Hi Chad -

Here is the code sample:

XMLObjectBuilderFactory builderFactory = Configuration
.getBuilderFactory();

Response response = (Response) buildXMLObject(Response.DEFAULT_ELEMENT_NAME);
//Filling required values in response like issuer id, etc.

// Creating assertion object
Assertion assertion = (Assertion) buildXMLObject(Assertion.DEFAULT_ELEMENT_NAME);
//Filling in the required values like name, subject, conditions, attributes etc.

// Generating the signature through signature builder
// Setting the signature to response object

// Marshalling the response
Element authElement = marshall(response);

// Converting to base 64 encoding



---- Sample code for Marshall method

private Element marshall(XMLObject marshallMe) throws Exception {
try {
MarshallerFactory marshallerFactory = Configuration
.getMarshallerFactory();
Marshaller marshaller =
marshallerFactory.getMarshaller(marshallMe);
if (marshaller == null)
throw new MarshallingException(
"unable to locate marshaller for
["
+
marshallMe.getElementQName() + "]");

// Convert SAML metadata to XML DOM (includes
signature)
return marshaller.marshall(marshallMe);

} catch (Exception x) {
throw new Exception(x);
}
}


----- Sample code for base 64 encoding


private String getBase64SAML(Element authElement) throws Exception {
try {
// Serialize to string
DOMImplementationRegistry registry =
DOMImplementationRegistry
.newInstance();
DOMImplementationLS impl = (DOMImplementationLS)
registry
.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
String str = writer.writeToString(authElement);

str = Base64.encode(str.getBytes());

return str;
} catch (Exception x) {
throw new Exception(x);
}
}


Thanks
Prasanna Krishna


From: Chad La Joie
<>
Date: Wed, 01 Aug 2007 16:46:29 -0400

Okay, and how are you serializing the DOM (that is changing it into the textual representation where you see UTF-16 encoding attribute in the prolog)? Can you show that code?

Prasanna Krishna wrote:
Hi Chad -

Java language jdk 1.5

thanks
Prasanna Krishna


From: Chad La Joie
<>
Date: Wed, 01 Aug 2007 16:38:39 -0400

What language are you using?


wrote:
Hello -

When I generate an assertion using open SAML 2, the XML is UTF-16 encoded by default (hope I am not setting any property to that affect)
<?xml version="1.0" encoding="UTF-16"?>

How do I change the encoding to UTF-8.

Thanks for the help

Regards
Prasanna Krishna

_________________________________________________________________
Voice your questions and our experts will answer them http://content.msn.co.in/Lifestyle/AskExpert/Default01.htm

--
Chad La Joie 2052-C Harris Bldg
OIS-Middleware 202.687.0124

_________________________________________________________________
http://newlivehotmail.com




Archive powered by MHonArc 2.6.16.

Top of Page