【客户下单】后台提供webservice服务接收数据
在bos_fore系统中,添加OrderAction封装订单数据。
接下来调用webservice,将数据传递给bos_management系统。
在web.xml中配置CXF的servlet
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
在spring的配置文件applicationContext.xml中配置CXF的jaxrs
<jaxrs:server id="promotionService" address="/promotionService">
<jaxrs:serviceBeans>
<bean class="cn.niwotaxuexiba.bos.service.take_delivery.impl.PromotionServiceImpl" />
</jaxrs:serviceBeans>
<jaxrs:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxrs:outInterceptors>
</jaxrs:server>
<jaxrs:server id="orderService" address="/orderService">
<jaxrs:serviceBeans>
<bean class="cn.niwotaxuexiba.bos.service.take_delivery.impl.OrderServiceImpl" />
</jaxrs:serviceBeans>
<jaxrs:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxrs:outInterceptors>
</jaxrs:server>
修改bos_domain工程,在实体类Order和Area上添加@RootXmlElement注解。添加完注解后,因为是maven工程,因此需要执行install命令。
Order类
@XmlRootElement(name = "area")
public class Area {...}
Area类
@XmlRootElement(name = "order")
public class Order {...}
在bos_management中添加OrderService,发布WebService
public interface OrderService{
@Path("/order")
@POST
@Consumes({"application/xml","application/json"})//接收xml,json格式
public void saveOrder(Order order);
}
编写OrderService接口的实现类OrderServiceImpl,接收客户端bos_fore发送过来的数据。
@Service
@Transactional
public class OrderServiceImpl implements OrderService {
@Override
public void saveOrder(Order order){
System.out.println(order);
}
}
调用bos_management的webservice,将数据传递给bos_management系统,发送数据用POST,指定被传递数据的格式用type指定。
//调用webservice,将客户下单数据传递给bos_management系统
WebClient.create(Constants.BOS_MANAGEMENT_URL+"/services/orderService/order").type(MediaType.APPLICATION_JSON).post(model);