cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Felix.1973" <felix.merca...@omnipaygroup.com>
Subject Interceptors not triggered in WebLogic 12c ?
Date Tue, 23 Sep 2014 15:45:50 GMT
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):

<http://cxf.547215.n5.nabble.com/file/n5749133/Intellij.jpg> 



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

<http://cxf.547215.n5.nabble.com/file/n5749133/WebLogic.jpg> 


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;

@WebService()
public class HelloWorldImpl implements HelloWorld {

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

    @WebMethod
    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;
        System.out.println(result);
        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() {
        super(Phase.PRE_PROTOCOL);
        getAfter().add(SAAJInInterceptor.class.getName());
    }

    public void handleMessage(SoapMessage message) throws Fault {
        SOAPMessage doc = message.getContent(SOAPMessage.class);
        if (doc == null) {
            saajIn.handleMessage(message);
            doc = message.getContent(SOAPMessage.class);
        }
        SOAPHeader headerr = null;
        try {
            headerr = doc.getSOAPHeader();
        } catch (SOAPException e) {
            e.printStackTrace();
        }
        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);
        if(null!=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
        &quot;-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN&quot;
       
&quot;http://java.sun.com/dtd/application_1_3.dtd&quot;><application>
    <display-name>test_interceptors</display-name>
    <module>
        <web>
            <web-uri>/</web-uri>
            <context-root>/</context-root>
        </web>
    </module>
</application>


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">
    <wls:application-param>
        <wls:param-name>webapp.encoding.default</wls:param-name>
        <wls:param-value>UTF-8</wls:param-value>
    </wls:application-param>
    <wls:prefer-application-packages>
        <wls:package-name>javax.wsdl.*</wls:package-name>
        <wls:package-name>javax.ws.rs.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:weblogic-application>


5) web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           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/web-app_2_5.xsd"
           version="2.5">

    <description>cxf</description>

    <display-name>cxf</display-name>
    <servlet>
        <description>Apache CXF Endpoint</description>
        <display-name>cxf</display-name>
        <servlet-name>cxf</servlet-name>
       
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>


6) weblogic.xml

<weblogic-web-app
        xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">

    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>

</weblogic-web-app>


7) cxf-servlet.xml

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

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cxf="http://cxf.apache.org/core"
      xmlns:jaxws="http://cxf.apache.org/jaxws"
      xmlns:soap="http://cxf.apache.org/bindings/soap"
      xsi:schemaLocation="
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">
</beans>


Please, any help is very appreciated.

thanks
Felix Mercader.




--
View this message in context: http://cxf.547215.n5.nabble.com/Interceptors-not-triggered-in-WebLogic-12c-tp5749133.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Mime
View raw message