Announcement Announcement Module
Collapse
No announcement yet.
HTTP Session from the client Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTP Session from the client

    Hi,

    I am trying to figure out how to get the HTTP Request before I send out the SOAP request to add in some properties to the SOAP request (IE HTTP Session and IP Address). Does anyone know how to do this? I am using spring-ws-1.5.9.

    Here is my applicationContext:

    Code:
            <bean id="facade" class="com.company.facade.facadeImpl" parent="webServiceGatewaySupport">
    		<property name="messageSender" ref="commonsMessageSender" />
    	</bean>
    	
    	<bean id="commonsMessageSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
    		<constructor-arg ref="httpClient" />
    		<property name="credentials" ref="credentials" />
    	</bean>
    	<bean id="credentials" class="org.apache.commons.httpclient.UsernamePasswordCredentials">
    		<constructor-arg value="USERNAME" />
    		<constructor-arg value="PASSWORD" />
    	</bean>
            <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
        
    	<bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
                <property name="authenticationPreemptive" value="false" />
                <property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" />
            </bean>
        
            <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
                <constructor-arg ref="httpClientParams" />
            </bean>
    Here is the code:

    Code:
    public class FacadeImpl extends WebServiceGatewaySupport 
        implements Facade {
        
        /**
         * The HTTP Message Sender.
         */
        protected CommonsHttpMessageSender messageSender;
        
        /**
         * Default constructor
         */
        public FacadeImpl() {
            super();
        }
        
        /**
         * Constructor accepting MessageFactory
         * @param messageFactory
         */
        public FacadeImpl(WebServiceMessageFactory messageFactory) {
            super(messageFactory);
        }
       
        public Response createRequest(
                Request request) throws Exception {
            Response response = null;
            try {
                response = (Response) super.getWebServiceTemplate()
                        .marshalSendAndReceive(request,
                            new CustomWebServiceMessageCallback(){
                    public void doWithMessage(WebServiceMessage message) {
                        try {
                            /*
                             * Modify the SOAP Headers.
                             */
                            modifySOAPHeader(message, text);
                        } catch (Exception e) {
                        }
                    }
                });
            } catch(Exception e) {
                throw e;
            }
            return response;
        }
    }
    public abstract class CustomWebServiceMessageCallback
    		implements WebServiceMessageCallback {
    	
    	/**
    	 * Modify the SOAP Headers for common properties.
    	 * 
    	 * @param message
    	 * @param text
    	 */
    	public void modifySOAPHeader(WebServiceMessage message,
    			String text) {
    		/*
    		 * Modify the soap header for specific fields.
    		 */
    		SoapMessage soap = (SoapMessage) message;
    		SoapHeader soapHeader = soap.getSoapHeader();
    		//TODO: GET THE IP Address and Session ID
    		SoapHeaderElement ipAddress = soapHeader.
    			addHeaderElement(new QName(
    					Util.DUMMY_XSD,
    					Util.IP_ADDRESS));
    		ipAddress.setText(HOW TO GET THIS?);
    		SoapHeaderElement sessionId = soapHeader.
    			addHeaderElement(new QName(
    					Util.DUMMY_XSD,
    					Util.SESSION_ID));
    		sessionId.setText(HOW TO GET THIS?);
    	}
    }
    Thanks,
    Bill

  • #2
    I found this documentation, but it is for the server side. Need to know how from the client side.

    Server Side

    Comment

    Working...
    X