How to create a header section to authenticate a request from classes generated from an xsd file?

For a SOAP request, I have some xsd files from which I have generated Java classes. All the necessary files (both request and response classes) got generated except for the authentication class. Now I am not able to write a method which will be authenticating my request. I am new to using SOAP. Any sort of help will be appreciated.

Replies

  • Bapan Mazumder
    Bapan Mazumder
    Hi I have solved the issue. By using SoapMessage, I was able to create the authentication header for my request message. Sample codes are:
    public static SoapMessage Authentication(){
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMsg = messageFactory.createMessage();
    SOAPPart soapPart = soapMsg.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    
    SOAPHeader header = envelope.getHeader();
    SOAPHeaderElement headerElemmm = header.addHeaderElement(envelope.createQName("TargetEnvironment", "..."));
    headerElemmm.addTextNode(enviromnent);
    ......................................................
    ......................................................
    MimeHeaders headers = soapMsg.getMimeHeaders();
    headers.addHeader("SOAPAction", soapAction);
    soapMsg.saveChanges();
    return soapResponse;
    } 

You are reading an archived discussion.

Related Posts

Nurturing Green was founded by Annu Grover in January 2009 with a mission to open people’s minds towards increasing the importance of plants in their everyday lives and the startup...
Google has taken its idea of self-driving cars to the next level by designing and building its own car from scratch. Its previous attempts involved fitting its systems aboard cars...
June 02, 2014 will mark the beginning of a new era in the CrazyEngineers world; and we hope to have you with us to experience it all with us. Stay...
Dovetailed, a Cambridge UK based design studio cum innovation lab, has come up with something really revolutionary. It has developed a 3D Food Printer that can print edible fruits. The...
Regarding the mathematics of the unusual shape and profile of the Wankel engine triangular rotor and combustion chamber housing, I'm reviewing a mathematics demonstration I have just come across but...