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

    Updated: Oct 26, 2024
    Views: 1.0K
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Bapan Mazumder

    MemberJul 3, 2014

    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;
    } 
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register