• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Apache CXF interceptors not triggered in WebLogic 12c ?

Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

Please, I am stuck for many days having always the same error. I am testing the helloWorld apache cxf example where I added an interceptor to get information from the HTTP header.

I am developing using IDEA Intellij 11.0.2 and it works wonderfully when I test it inside Intellij but when I deploy the artifact in WebLogic 12c I have always a null pointer exception.

I am having the same error in a local WebLogic 12c in my personal computer (Windows 7 Professional) and also in WebLogic 12c in a UNIX server AIX 7.1.

I use JDK 1.7.0 plus Apache CXF 2.7.12.

When I debug the code in IDEA Intellij, I see that the interceptor constructor is executed and the handleMessage too, so everything works fine. But when debugging in WebLogic, the constructor is executed but the handleMessage is never executed.

My problem is in this line of code:

Message message = PhaseInterceptorChain.getCurrentMessage();

Variable "message" is correctly populated when I execute/debug in IDEA Intellij but it is always NULL when I execute/debug in WebLogic. Anyway, I think the problem is happening before becuase as I wrote, "handleMessage" is never invoked in WebLogic but in IDEA Intellij is.

I add some screenshots of the debugging in IDEA Intellij and WebLogic to show you what I mean. I changed the line:

Message message = PhaseInterceptorChain.getCurrentMessage();

For these 3 lines because I saw I have the same results but more things to show you when debugging:

Bus bus = BusFactory.getDefaultBus();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
Message message = chain.getCurrentMessage();

This is what I get when debugging in Intellij (everything works fine):

--> Intellij attachment

And this is what I get when debugging in WebLogic (not working as I expected):

--> WebLogic attachment

Finally, some code:

1) HelloWorldImpl.java

package example;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.phase.PhaseManager;

public class HelloWorldImpl implements HelloWorld {

public HelloWorldImpl() {
Bus bus = BusFactory.getDefaultBus();
UserCredentialInterceptor myInterceptor = new UserCredentialInterceptor();

public String sayHelloWorldFrom(String from) {
//Message message = PhaseInterceptorChain.getCurrentMessage();
Bus bus = BusFactory.getDefaultBus();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
Message message = chain.getCurrentMessage();
if (message==null) {
System.out.println("HELLOWORLD ERROR");
} else {
System.out.println("HELLOWORLD OK");

String result = "Hello, world, from " + from;
return result;

2) UserCredentialInterceptor.java

package example;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.w3c.dom.NodeList;
import javax.servlet.http.HttpServletRequest;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import java.util.Enumeration;
import javax.servlet.http.Cookie;

public class UserCredentialInterceptor extends AbstractSoapInterceptor {
private SAAJInInterceptor saajIn = new SAAJInInterceptor();

public UserCredentialInterceptor() {

public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage doc = message.getContent(SOAPMessage.class);
if (doc == null) {
doc = message.getContent(SOAPMessage.class);
SOAPHeader headerr = null;
try {
headerr = doc.getSOAPHeader();
} catch (SOAPException e) {
if (headerr != null) {
NodeList nodes = headerr.getElementsByTagNameNS("http://asjava.com/types", "Username");
if (nodes != null && nodes.item(0) != null) {
String user = nodes.item(0).getTextContent();
//if you want to read more http header messages, just use get method to obtain from HttpServletRequest.
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
//Read http header to get client IP adress
String addr = request.getRemoteAddr();
//Read http header to get HeaderNames
Enumeration enums = request.getHeaderNames();
//Read http header to get cookie/
Cookie[] cookies = request.getCookies();

3) application.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"

4) weblogic-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd">

5) web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"


<description>Apache CXF Endpoint</description>

6) weblogic.xml




7) cxf-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

Please, any help is very appreciated.

Felix Mercader.

[Thumbnail for Intellij.jpg]
[Thumbnail for WebLogic.jpg]
Felix Mercader
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I opened a new topic because now I see that the problem is not interceptors, the problem is that CXF is not being used at all:
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic