You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Landslide <xi...@landslide.com> on 2008/06/16 20:03:58 UTC

CXF 2.1 client does not retrieve HTTP session header info correctly

I took the latest code drop of CXF 2.1 and built a test client as below to
retrieve HTTP session header info sent back from my CXF SOAP server (2.1):

public class WsClientNoWsse {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		
		SoapService_Service service = new SoapService_Service();
		SoapService port = service.getSoapServicePort();
		
		BindingProvider bp = (BindingProvider)port;
		bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
true);

		try {
			String result = port.sayHi("John");
			System.out.println("SOAP response: " + result);
			
			Map<String, List<String>> headers = (Map<String,
List<String>>)((BindingProvider)port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
			System.out.println("Headers: " + headers);
			List<String> header = headers.get("Set-Cookie");
			if (header != null && !header.isEmpty()) {
				for (int i=0; i<header.size(); i++) {
					System.out.println("Header: " + header.get(i));
				}
			}

			result = port.sayHi("Peter");
			System.out.println("SOAP response: " + result);
			
			headers = null;
			header = null;
			headers = (Map<String,
List<String>>)((BindingProvider)port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
			System.out.println("Headers: " + headers);
			header = headers.get("Set-Cookie");
			if (header != null && !header.isEmpty()) {
				for (int i=0; i<header.size(); i++) {
					System.out.println("Header: " + header.get(i));
				}
			}
			
			result = port.sayHi("Mary");
			System.out.println("SOAP response: " + result);
			
			headers = null;
			header = null;
			headers = (Map<String,
List<String>>)((BindingProvider)port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
			System.out.println("Headers: " + headers);
			header = headers.get("Set-Cookie");
			if (header != null && !header.isEmpty()) {
				for (int i=0; i<header.size(); i++) {
					System.out.println("Header: " + header.get(i));
				}
			}

		} catch(Exception e) {
			e.printStackTrace();
		}

	}

}

The following was my test result. As could be seen, the CXF 2.1 client did
retrieve HTTP session header info correctly in the 1st response, which
contained 2 different cookies (MyCookie and JSESSIONID). However, in the 2nd
and 3rd responses, the CXF 2.1 client failed to retrieve the cookie
"JSESSIONID" correctly since its value has not been modified by my SOAP
server since its 1st response.

SOAP response 1: Hello, John
Headers: {Content-Length=[237], X-Powered-By=[Servlet 2.4; JBoss-4.0.5.GA
(build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
Set-Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1; Version=1,
JSESSIONID=1FBE5EDFF76385CC9F194BD4DD4C727B; Path=/], Date=[Mon, 16 Jun 2008
17:44:21 GMT], SOAPAction=[""], Server=[Apache-Coyote/1.1],
content-type=[text/xml;charset=UTF-8]}
Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1; Version=1
Header: JSESSIONID=1FBE5EDFF76385CC9F194BD4DD4C727B; Path=/

SOAP response 2: Hello, Peter
Headers: {Content-Length=[238], X-Powered-By=[Servlet 2.4; JBoss-4.0.5.GA
(build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
Set-Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified1;
Version=1], Date=[Mon, 16 Jun 2008 17:44:21 GMT], SOAPAction=[""],
Server=[Apache-Coyote/1.1], content-type=[text/xml;charset=UTF-8]}
Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified1;
Version=1

SOAP response 3: Hello, Mary
Headers: {Content-Length=[237], X-Powered-By=[Servlet 2.4; JBoss-4.0.5.GA
(build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
Set-Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified2;
Version=1], Date=[Mon, 16 Jun 2008 17:44:21 GMT], SOAPAction=[""],
Server=[Apache-Coyote/1.1], content-type=[text/xml;charset=UTF-8]}
Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified2;
Version=1

On my SOAP server side, I did receive the returned cookies (both of them)
correctly for all 3 requests as the following 2 lines of code were working
correctly on the CXF client side:

	BindingProvider bp = (BindingProvider)port;
	bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
true);

-- 
View this message in context: http://www.nabble.com/CXF-2.1-client-does-not-retrieve-HTTP-session-header-info-correctly-tp17870106p17870106.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF 2.1 client does not retrieve HTTP session header info correctly

Posted by Landslide <xi...@landslide.com>.
Here is what I got on the server side:

Request 1:

17:15:41,484 ERROR [STDERR] Jun 16, 2008 5:15:41 PM
org.apache.cxf.interceptor.LoggingInInterceptor logging
INFO: Inbound Message
----------------------------
Encoding: UTF-8
Headers: {connection=[keep-alive], cache-control=[no-cache],
host=[landslide.localhost.salesgene.com:8888], user-agent=[Java/1.5.0_12],
transfer-encoding=[chunked], pragma=[no-cache], content-type=[text/xml;
charset=UTF-8], accept=[*], soapaction=[""]}

Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHi
xmlns:ns2="http://www.landslide.com/webservices/SoapService"><arg0>John</arg0></ns2:sayHi></soap:Body></soap:Envelope>


Request 2:

17:15:42,171 ERROR [STDERR] Jun 16, 2008 5:15:42 PM
org.apache.cxf.interceptor.LoggingInInterceptor logging
INFO: Inbound Message
----------------------------
Encoding: UTF-8
Headers: {connection=[keep-alive], cache-control=[no-cache],
host=[landslide.localhost.salesgene.com:8888], user-agent=[Java/1.5.0_12],
transfer-encoding=[chunked], pragma=[no-cache], content-type=[text/xml;
charset=UTF-8], cookie=[$Version="1";
JSESSIONID=8079DC2B51E3E69908BBFA12F4AD7317; $Path=/, $Version="1";
LSCookie=8079DC2B51E3E69908BBFA12F4AD7317127.0.0.1], accept=[*],
soapaction=[""]}

Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHi
xmlns:ns2="http://www.landslide.com/webservices/SoapService"><arg0>Peter</arg0></ns2:sayHi></soap:Body></soap:Envelope>


Request 3:

17:15:42,187 ERROR [STDERR] Jun 16, 2008 5:15:43 PM
org.apache.cxf.interceptor.LoggingInInterceptor logging
INFO: Inbound Message
----------------------------
Encoding: UTF-8
Headers: {connection=[keep-alive], cache-control=[no-cache],
host=[landslide.localhost.salesgene.com:8888], user-agent=[Java/1.5.0_12],
transfer-encoding=[chunked], pragma=[no-cache], content-type=[text/xml;
charset=UTF-8], cookie=[$Version="1";
LSCookie=8079DC2B51E3E69908BBFA12F4AD7317127.0.0.1Modified1, $Version="1";
JSESSIONID=8079DC2B51E3E69908BBFA12F4AD7317; $Path=/], accept=[*],
soapaction=[""]}

Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHi
xmlns:ns2="http://www.landslide.com/webservices/SoapService"><arg0>Mary</arg0></ns2:sayHi></soap:Body></soap:Envelope>

-- 
View this message in context: http://www.nabble.com/CXF-2.1-client-does-not-retrieve-HTTP-session-header-info-correctly-tp17870106p17873610.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF 2.1 client does not retrieve HTTP session header info correctly

Posted by Daniel Kulp <dk...@apache.org>.
I'd have to see the raw wire transfers.  See:
http://cwiki.apache.org/CXF20DOC/debugging.html
on how to enable them.

Most likely, they AREN'T there.   Many web servers, if they get a  
JSESSSIONID comming in, they don't send it back.   There isn't a point  
as they know the client is configured to honor the session and will  
keep sending it.

I checked the code and we don't remove anything from the map.   The  
HTTP_RESPONSE_HEADER map is an exact copy of the map returned from the  
HTTPUrlConnection.getHeaderFields() call.

Dan



On Jun 16, 2008, at 4:52 PM, Landslide wrote:

>
> The issue is that the cookie "JSESSIONID" is indeed in the HTTP  
> header of the
> 2nd and 3rd responses. That's the only way that the server side can  
> track
> this exact same HTTP session based on its session ID value initially  
> set by
> the server side in the 1st response.
>
> As I mentioned previously, I could see this "JSESSIONID" cookie in  
> the 2nd
> and 3rd incoming requests on the server side since the client indeed  
> sent
> back the whole headers correctly.
>
> If I use the Apache Axis2 (1.3.0), I can retrieve, on the client  
> side, the
> cookie "JSESSIONID" in all 3 responses with the correct value (one  
> value
> only and no change set by the server side).
> -- 
> View this message in context: http://www.nabble.com/CXF-2.1-client-does-not-retrieve-HTTP-session-header-info-correctly-tp17870106p17873057.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog





Re: CXF 2.1 client does not retrieve HTTP session header info correctly

Posted by Landslide <xi...@landslide.com>.
The issue is that the cookie "JSESSIONID" is indeed in the HTTP header of the
2nd and 3rd responses. That's the only way that the server side can track
this exact same HTTP session based on its session ID value initially set by
the server side in the 1st response.

As I mentioned previously, I could see this "JSESSIONID" cookie in the 2nd
and 3rd incoming requests on the server side since the client indeed sent
back the whole headers correctly.

If I use the Apache Axis2 (1.3.0), I can retrieve, on the client side, the
cookie "JSESSIONID" in all 3 responses with the correct value (one value
only and no change set by the server side).
-- 
View this message in context: http://www.nabble.com/CXF-2.1-client-does-not-retrieve-HTTP-session-header-info-correctly-tp17870106p17873057.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF 2.1 client does not retrieve HTTP session header info correctly

Posted by Daniel Kulp <dk...@apache.org>.
I believe this is working completely as specified.   The  
MessageContext.HTTP_RESPONSE_HEADER return the headers that came in  
for the very last response only.   They aren't supposed to be an  
aggregate.   Since responses 2 and 3 don't have the JSESSIONID in the  
headers, they wouldn't be in the map of headers.

Dan



On Jun 16, 2008, at 2:03 PM, Landslide wrote:

>
> I took the latest code drop of CXF 2.1 and built a test client as  
> below to
> retrieve HTTP session header info sent back from my CXF SOAP server  
> (2.1):
>
> public class WsClientNoWsse {
>
> 	/**
> 	 * @param args
> 	 */
> 	@SuppressWarnings("unchecked")
> 	public static void main(String[] args) {
> 		
> 		SoapService_Service service = new SoapService_Service();
> 		SoapService port = service.getSoapServicePort();
> 		
> 		BindingProvider bp = (BindingProvider)port;
> 		 
> bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
> true);
>
> 		try {
> 			String result = port.sayHi("John");
> 			System.out.println("SOAP response: " + result);
> 			
> 			Map<String, List<String>> headers = (Map<String,
> List<String>>) 
> ((BindingProvider 
> )port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
> 			System.out.println("Headers: " + headers);
> 			List<String> header = headers.get("Set-Cookie");
> 			if (header != null && !header.isEmpty()) {
> 				for (int i=0; i<header.size(); i++) {
> 					System.out.println("Header: " + header.get(i));
> 				}
> 			}
>
> 			result = port.sayHi("Peter");
> 			System.out.println("SOAP response: " + result);
> 			
> 			headers = null;
> 			header = null;
> 			headers = (Map<String,
> List<String>>) 
> ((BindingProvider 
> )port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
> 			System.out.println("Headers: " + headers);
> 			header = headers.get("Set-Cookie");
> 			if (header != null && !header.isEmpty()) {
> 				for (int i=0; i<header.size(); i++) {
> 					System.out.println("Header: " + header.get(i));
> 				}
> 			}
> 			
> 			result = port.sayHi("Mary");
> 			System.out.println("SOAP response: " + result);
> 			
> 			headers = null;
> 			header = null;
> 			headers = (Map<String,
> List<String>>) 
> ((BindingProvider 
> )port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
> 			System.out.println("Headers: " + headers);
> 			header = headers.get("Set-Cookie");
> 			if (header != null && !header.isEmpty()) {
> 				for (int i=0; i<header.size(); i++) {
> 					System.out.println("Header: " + header.get(i));
> 				}
> 			}
>
> 		} catch(Exception e) {
> 			e.printStackTrace();
> 		}
>
> 	}
>
> }
>
> The following was my test result. As could be seen, the CXF 2.1  
> client did
> retrieve HTTP session header info correctly in the 1st response, which
> contained 2 different cookies (MyCookie and JSESSIONID). However, in  
> the 2nd
> and 3rd responses, the CXF 2.1 client failed to retrieve the cookie
> "JSESSIONID" correctly since its value has not been modified by my  
> SOAP
> server since its 1st response.
>
> SOAP response 1: Hello, John
> Headers: {Content-Length=[237], X-Powered-By=[Servlet 2.4;  
> JBoss-4.0.5.GA
> (build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
> Set-Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1;  
> Version=1,
> JSESSIONID=1FBE5EDFF76385CC9F194BD4DD4C727B; Path=/], Date=[Mon, 16  
> Jun 2008
> 17:44:21 GMT], SOAPAction=[""], Server=[Apache-Coyote/1.1],
> content-type=[text/xml;charset=UTF-8]}
> Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1; Version=1
> Header: JSESSIONID=1FBE5EDFF76385CC9F194BD4DD4C727B; Path=/
>
> SOAP response 2: Hello, Peter
> Headers: {Content-Length=[238], X-Powered-By=[Servlet 2.4;  
> JBoss-4.0.5.GA
> (build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
> Set- 
> Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified1;
> Version=1], Date=[Mon, 16 Jun 2008 17:44:21 GMT], SOAPAction=[""],
> Server=[Apache-Coyote/1.1], content-type=[text/xml;charset=UTF-8]}
> Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified1;
> Version=1
>
> SOAP response 3: Hello, Mary
> Headers: {Content-Length=[237], X-Powered-By=[Servlet 2.4;  
> JBoss-4.0.5.GA
> (build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5],
> Set- 
> Cookie=[MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified2;
> Version=1], Date=[Mon, 16 Jun 2008 17:44:21 GMT], SOAPAction=[""],
> Server=[Apache-Coyote/1.1], content-type=[text/xml;charset=UTF-8]}
> Header: MyCookie=1FBE5EDFF76385CC9F194BD4DD4C727B127.0.0.1Modified2;
> Version=1
>
> On my SOAP server side, I did receive the returned cookies (both of  
> them)
> correctly for all 3 requests as the following 2 lines of code were  
> working
> correctly on the CXF client side:
>
> 	BindingProvider bp = (BindingProvider)port;
> 	bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,
> true);
>
> -- 
> View this message in context: http://www.nabble.com/CXF-2.1-client-does-not-retrieve-HTTP-session-header-info-correctly-tp17870106p17870106.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog