I have trouble working with interceptors in CXF.
My project is layed out as below
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC" xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/1FSgkdj http://ift.tt/1zMZJEw"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/root-config.xml</param-value>
</context-param>
<listener>
<display-name>contextLoaderListener</display-name>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
root-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:flex="http://ift.tt/1ePwsgl" xmlns:security="http://ift.tt/1c8inpe"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:cxf="http://ift.tt/1iXPlPh" xmlns:jaxws="http://ift.tt/1ej3bYY"
xsi:schemaLocation="
http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/1ePwsgl
http://ift.tt/1ePwvbL
http://ift.tt/1c8inpe
http://ift.tt/1fChGbz
http://ift.tt/GArMu7
http://ift.tt/QEDs1k">
<import resource="cxf-service.xml" />
</beans>
cxf-service.xml
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:http-conf="http://ift.tt/1fgHZC8"
xmlns:jaxws="http://ift.tt/1ej3bYY"
xsi:schemaLocation="http://ift.tt/1fgHZC8
http://ift.tt/1ol0hto
http://ift.tt/1ej3bYY
http://ift.tt/1ej3cfe
http://ift.tt/GArMu6
http://ift.tt/1jdM0fG">
<import resource="classpath*:META-INF/cxf/cxf.xml" />
<import resource="classpath*:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath*:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" />
<jaxws:endpoint>
id="helloWorldService"
address="/helloworld">
<jaxws:implementor>
<bean id="HelloWorldImpl" class="com.jorge.test.hello.webservices.HelloWorldImpl">
</bean>
</jaxws:implementor>
<jaxws:inInterceptors>
<bean class="com.jorge.test.hello.interceptors.ValueCheckInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
HelloWorld.java
package com.jorge.test.hello.webservices;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public abstract String sayHello(@WebParam(name = "user") String user);
}
helloWorldImpl.java
package com.jorge.test.hello.webservices;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
@WebService(endpointInterface = "com.jorge.test.hello.webservices.HelloWorld", serviceName = "hello")
@BindingType("http://ift.tt/1asjJ1m")
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String user) {
if ((user == null) || (user.length() == 0)) {
return "hello world";
}
return "hello world " + user;
}
}
ValueCheckInterceptor.java
package com.jorge.test.hello.interceptors;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
public class ValueCheckInterceptor extends AbstractSoapInterceptor {
public ValueCheckInterceptor() {
super(Phase.RECEIVE);
System.out.println("ValueCheckInterceptor Instantiated");
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
// TODO Auto-generated method stub
System.out.println("Intercepted at RECEIVE");
}
}
When I compile and deploy this in JBOSS I get one endpoint(based on servicename annotation on HelloWorldImpl) http://localhost:8080/helloworldws/hello and another based on cxf (address value) http://localhost:8080/helloworldws/services/helloworld
Both these endpoints are able to receive request and process it. The problem is that when I send the request to the first endpoint the Interceptor is not invoked, understandable since CXF does not know this endpoint.When I send request to the second end point interceptor is invoked.
I tried removing the servicename annotation on the HellowWorldImpl, but then it just exposes the service on http://localhost:8080/helloworldws/HelloWorldImpl
Aucun commentaire:
Enregistrer un commentaire