CXF Interceptor Example

Modify cxf.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:cxf="http://cxf.apache.org/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd  
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<!--CXF interceptor Example -->
	<bean class="com.student.ServiceResponseInterceptor" id="ServiceRequestInterceptor" />
	<cxf:bus>
		<cxf:inInterceptors>
			<ref bean="ServiceRequestInterceptor" />
		</cxf:inInterceptors>
	</cxf:bus>
	<jaxws:endpoint id="changeStudent"
		implementor="com.student.ChangeStudentDetailsImpl" address="/ChangeStudent" />
</beans>

Now run the below client and see the output

Run
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.student.ChangeStudentDetails;
import com.student.Student;

// CXF JAX-WS Client / Consuming Web Services With CXF

public final class StudentClient {

   
public static void main(String args[]) throws Exception {

     
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

      factory.setServiceClass
(ChangeStudentDetails.class);
      factory.setAddress
("http://localhost:8080/CXFTutorial/ChangeStudent?wsdl");
      factory.getInInterceptors
().add(new LoggingInInterceptor());
      factory.getOutInterceptors
().add(new LoggingOutInterceptor());
      ChangeStudentDetails client =
(ChangeStudentDetails) factory.create();
      Student student =
new Student();
      student.setName
("Rockey");
      Student changeName = client.changeName
(student);
      System.out.println
("Server said: " + changeName.getName());
      System.exit
(0);
   
}
}
Output
Server said: Hello Ramu

We are actually sending the name as Rockey but it is changed to Ramu dynamically using CXF interceptor.





Previous 1 2








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