Skip to Content.
Sympa Menu

mace-opensaml-users - NullPointerException when building objects

Subject: OpenSAML user discussion

List archive

NullPointerException when building objects


Chronological Thread 
  • From:
  • To:
  • Subject: NullPointerException when building objects
  • Date: Mon, 27 Aug 2007 02:01:49 -0300

Hi,

I'm trying to learn to to use the OpenSAML 2 lib, and following the wiki tips I typed a sample program that you can find at the end of this email. The problem is that when I try to run it, I get a NullPointerException when I try to call the builder.buildObject() for the Subject (I guess I'll get this too for the rest of the builders). Could someone tell me what is wrong with my program? I'm not very familiar with SAML yet, so I dont know if its a problem with the lib I built or with the way I'm calling the builder.

Thanks and best regards,
Maicon



-------------- sample program --------------

package teste;

import org.opensaml.Configuration;
import org.opensaml.xml.*;
import org.opensaml.saml2.core.*;
import org.opensaml.saml2.core.impl.*;
import org.opensaml.xml.io.*;
import org.w3c.dom.Element;


public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {

XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

SubjectBuilder builder = (SubjectBuilder ) builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
Subject subject = builder.buildObject(Subject.DEFAULT_ELEMENT_NAME);

NameIDBuilder builder2 = (NameIDBuilder ) builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME);
NameID nameID = builder2.buildObject();

SubjectConfirmationBuilder builder3 = (SubjectConfirmationBuilder ) builderFactory.getBuilder(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
SubjectConfirmation subjectConfirmation1 = builder3.buildObject();
SubjectConfirmation subjectConfirmation2 = builder3.buildObject();

subject.setNameID(nameID);
subject.getSubjectConfirmations().add(subjectConfirmation1);
subject.getSubjectConfirmations().add(subjectConfirmation2);

MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory();
Marshaller marshaller = marshallerFactory.getMarshaller(subject);

Element subjectElement = marshaller.marshall(subject);

System.out.println(subjectElement.toString());

} catch (Exception e) {
e.printStackTrace();
}
}

}


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





Archive powered by MHonArc 2.6.16.

Top of Page