Flask接口签名sign原理与实例代码浅析
316
2023-03-18
基于CXF搭建webService的实例讲解
1.导入相关jar包,具体哪些包我记不太清了
2.在applicationContext中加入相关配置信息,如下所示:
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:xsd="http://w3.org/2001/XMLSchema" xmlns:context="http://springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.0.xsd http://springframework.org/schema/conhttp://text http://springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schttp://hemas/jaxws.xsd"> id="OrderWS" implementor="com.cxf.spring.ws.OrderWSImpl"//类所在地址或者#+对应bean的id address="/OrderWS" > //随意命名
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://w3.org/2001/XMLSchema"
xmlns:context="http://springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans-3.0.xsd
http://springframework.org/schema/conhttp://text
http://springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schttp://hemas/jaxws.xsd">
id="OrderWS" implementor="com.cxf.spring.ws.OrderWSImpl"//类所在地址或者#+对应bean的id address="/OrderWS" > //随意命名
id="OrderWS"
implementor="com.cxf.spring.ws.OrderWSImpl"//类所在地址或者#+对应bean的id
address="/OrderWS" > //随意命名
3.在web.xml文件中加入:
4.在service层加入:
@WebService
public interface OrderWS {
@WebMethod
public Order getOrderById(int id);
}
5.若存在struts2,会发生冲突,则重写过滤器
5.1 写一个类ExtendStrutsFilter:
package com.nbu.retailer.filter;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
public class ExtendStrutsFilter extends StrutsPrepareAndExecuteFilter{
private static Logger log = LoggerFactory.getLogger(ExtendStrutsFilter.class);
@Override
public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain)
throws IOException, ServletException {
try {
HttpServletRequest request = (HttpServletRequest) req;
// 判断是否是向WebService发出的请求
if (request.getRequestURI().contains("/CXFServlet")) {
// 如果是来自向CXFService发出的请求
chain.doFilter(req, res);
}
else {
// 默认action请求
super.doFilter(req, res, chain);
}
}
catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
}
5.2 在web.xml中改变过滤器的地址:
5.3 注意,CXF的url和struts2的url不能相同。之前就这个问题困扰了我好久才发现的。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~