CXF Session Management

CXF session Management explains about Enabling Session Handling In Apache CXF

I am showing here, How to do session management in CXF framework, this is applicable for both SOAP & RESTFul services

Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
HttpSession  session = request.getSession(true);

On this code, we are getting HttpServletRequest and from that we are getting HttpSession Using CXF

You can see the below CXF Session example, on which we are storing a value to session and retrieving the same, using CXF Framework


This tutorial is also applicable for JAX-WS Web services because PhaseInterceptorChain.getCurrentMessage() applicable for both JAX-WS and JAX-RS based services

You can change CXF Web Service Tutorial according to the below tutorial, if you are using JAX-WS based service

Session Management Using CXF

I am going to re-use CXF Restful Tutorial

We are making changes ChangeStudentDetailsImpl class, just adding

PhaseInterceptorChain.getCurrentMessage() and getting HttpServletRequest, so that we can access HttpSession object in CXF Framework

package com.student;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;

public class ChangeStudentDetailsImpl implements ChangeStudentDetails {
public Student changeName(Student student) {
// Here We are getting session from Message
Message message = PhaseInterceptorChain.getCurrentMessage();
    HttpServletRequest request =
    HttpSession  session = request.getSession
("name","HELLO "+student.getName());
return student;

public Student getName() {
Student student = new Student();
return student;

1 2 Next

2 Responses to "CXF Session Management"
  1. sort 2012-09-10 08:05:01.0
  1. admin 2012-09-11 08:05:01.0

Your email address will not be published. Required fields are marked *