title: SAML generate metadata from entityId
body: <p>I am trying to generate SAML metadata for Service provider,I have created simple servlet and trying to generate metadata in a methoad doGet()</p>
  
  <p>this is the code I have tried below</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import java.io.IOException;
  import java.io.PrintWriter;
  import java.net.HttpRetryException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.xml.namespace.QName;
  
  
  import org.opensaml.Configuration;
  import org.opensaml.saml2.metadata.EntityDescriptor;
  import org.opensaml.xml.XMLObjectBuilderFactory;
  
  
  public class MetadataProviderServlet extends HttpServlet{
   protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
    PrintWriter writer = response.getWriter();
    response.setContentType("text/html");
    writer.println("Hello world");
    
    String entityId = "www.sampleEntityId.com";
    
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
     
    EntityDescriptor descriptor = (EntityDescriptor)(builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME).buildObject(EntityDescriptor.DEFAULT_ELEMENT_NAME));
    descriptor.setEntityID(entityId);
  
    
    
    
   }
   
   
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>But when I run the web application using one application server I got the NUllpointer Exception in particularly creation the object Entity Descriptor.Can Anyone please figure out what went wrong?</p>