Announcement Announcement Module
Collapse
No announcement yet.
Problem with SOAP Header not being set Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with SOAP Header not being set

    Hi all... question: any reason why the following code is not setting the apiKey SOAP Header?

    Code:
    package com.hoovers.webservice.springdemo;
    
    import java.io.IOException;
    
    import javax.xml.namespace.QName;
    import javax.xml.transform.TransformerException;
    
    import org.springframework.ws.WebServiceMessage;
    import org.springframework.ws.client.core.WebServiceMessageCallback;
    import org.springframework.ws.soap.SoapHeader;
    import org.springframework.ws.soap.SoapHeaderElement;
    import org.springframework.ws.soap.SoapMessage;
    
    public class HeaderCallback implements WebServiceMessageCallback {
    
    	private String namespaceURI;
    	private String elementName;
    	private String apiKey;
    	private String usernameElement;
    	private String passwordElement;
    	private String username;
    	private String password;
    
    	public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
    		QName apiKeyElement = new QName(getNamespaceURI(), getElementName());
    		SoapMessage msg = (SoapMessage) message;
    		SoapHeader header = msg.getEnvelope().getHeader();
    		SoapHeaderElement headerElement = header.addHeaderElement(apiKeyElement);
    		headerElement.setText(apiKey);
    
    		/**
    		 * Set username & password in header to invoke authentication 
    		 * username & password are passed in from applicationContext.xml
    		 */
    		if (getUsernameElement() != null) {
    			SoapHeaderElement usernameHeaderElement = header.addHeaderElement(new QName(getNamespaceURI(),
    					getUsernameElement()));
    			usernameHeaderElement.setText(username);
    		}
    
    		if (getPasswordElement() != null) {
    			SoapHeaderElement passwordHeaderElement = header.addHeaderElement(new QName(getNamespaceURI(),
    					getPasswordElement()));
    			passwordHeaderElement.setText(password);
    		}
    
    	}
    
    	public String getNamespaceURI() {
    		return namespaceURI;
    	}
    
    	public void setNamespaceURI(String namespaceURI) {
    		this.namespaceURI = namespaceURI;
    	}
    
    	public String getApiKey() {
    		return apiKey;
    	}
    
    	public void setApiKey(String apiKey) {
    		this.apiKey = apiKey;
    	}
    
    	public void setElementName(String elementName) {
    		this.elementName = elementName;
    	}
    
    	public String getElementName() {
    		return elementName;
    	}
    
    	public String getUsernameElement() {
    		return usernameElement;
    	}
    
    	public void setUsernameElement(String usernameElement) {
    		this.usernameElement = usernameElement;
    	}
    
    	public String getPasswordElement() {
    		return passwordElement;
    	}
    
    	public void setPasswordElement(String passwordElement) {
    		this.passwordElement = passwordElement;
    	}
    
    	public String getUsername() {
    		return username;
    	}
    
    	public void setUsername(String username) {
    		this.username = username;
    	}
    
    	public String getPassword() {
    		return password;
    	}
    
    	public void setPassword(String password) {
    		this.password = password;
    	}
    
    }
    When I look inside the headerElement object all I see is "[API-KEY: null]" although the value of apiKey is not null but a string.
    Thanks in advance...
Working...
X