Apache CXF – getting ServletContext in code

It is common to get a Servlet context on implementing WEB API. Apache CXF has a little different approach to get this instance. The following code show how to get ServletContext instance for RS.


public interface IServiceInterface {
    void SampleFunction();
}

public class ImplementClass implement IServiceInterface {
    @Context
    private org.apache.cxf.jaxrs.ext.MessageContext messgeContext;

    public void SampleFunction() {
        ServletContext servletContext = messgeContext.getServletContext();
    }
}
Advertisements
This entry was posted in Java, Programming and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s