手写webservice
步骤
web配置
http://localhost:8181/UserCenter2/SupplierHttpPortPort?wsdl
web.xml
</servlet-mapping>
<servlet-mapping>
<servlet-name>interfaceServlet</servlet-name>
<url-pattern>/SupplierHttpPortPort</url-pattern>
</servlet-mapping>
<servlet>
<description>JAX-WS endpoint - interfaceServlet</description>
<display-name>interfaceServlet</display-name>
<servlet-name>interfaceServlet</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
过滤器
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>com.tempus.modules.web.struts2.filter.MySelfStrutsPrepareAndExecute</filter-class>
<init-param>
<param-name>exclude</param-name>
<!-- 此处加入排除参数,可跳过struts2,用于接口,资源等等不需要进入struts2的地址。 -->
<param-
value>Display,css,css/,interface,MemberHttpPort,GuestHttpPort,CheckMemberHttpPort,MarkHttpPort,xls,VoucherNewHttpPort,CompanyMemberHttpPort,CostCenterHttpIm
plPort,WgHttpPortImplPort,FxHttpPortImplPort,SupplierHttpPortPort,HotelHttpPortImplPort,CompanyQueryTMCPort,MemberSourceHttpPortImplPort,PayModelHttpPortImp
lPort,ComplainsPort</param-value>
</init-param>
</filter>
public class MySelfStrutsPrepareAndExecute extends StrutsPrepareAndExecuteFilter {
private static Logger logger = LoggerFactory.getLogger(MySelfStrutsPrepareAndExecute.class);
private String exclude;
private List<InterfaceIp> ip = null ;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
if (request instanceof HttpServletRequest) {
HttpServletRequest hsq = (HttpServletRequest) request;
String uri =hsq.getRequestURI();
String[] excludeArray = exclude.split(",");
for (String exc : excludeArray) {
if (hsq.getRequestURI().endsWith(exc)) {
if(uri.indexOf("HttpPort")!=-1)
{
/*String requestip = Struts2Utils.getRequestIP(request);
// ip = (List<InterfaceIp>)hsq.getSession().getServletContext().getAttribute("ipList");
SpyMemcachedClient memcachedClient =null;
try {
memcachedClient = (SpyMemcachedClient)SpringContextUtil.getBean("spyMemcachedClient");
ip = memcachedClient.get("ipList");
} catch (Exception e) {
e.printStackTrace();
}
if(ip==null)
{
ip = ((InterfaceService)SpringContextUtil.getBean("interfaceService")).getAllIp();
}
boolean flag=false;
for(InterfaceIp interfaceIp:ip)
{
if(requestip.equals(interfaceIp.getIp())&&!"1".equals(interfaceIp.getZt()))
{
flag=true;
logger.info("请求接口的IP为:"+requestip+"访问成功!");
hsq.getSession().setAttribute("requestIP", requestip);
break;
}
}
if(!flag){
logger.info("请求接口的IP为:"+requestip+"访问失败,原因:没有权限!");
hsq.getSession().setAttribute("returnip", requestip);
HttpServletResponse hsr = (HttpServletResponse)response;
hsr.sendRedirect(hsq.getContextPath()+"/ip.jsp");
}*/
}
chain.doFilter(request, response);
return;
}
}
}
super.doFilter(request, response, chain);
}
@Override
public void init(FilterConfig config) throws ServletException {
super.init(config);
exclude = config.getInitParameter("exclude");
}
}
web.xml
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
sun-jaxws.xml
<?xml version = "1.0"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint name="SupplierHttpPortPort"
implementation="com.tempus.userCenter.service.webservice.gys.SupplierHttpPortDelegate"
url-pattern="/SupplierHttpPortPort">
</endpoint>
</endpoints>
具体方法
@javax.jws.WebService(targetNamespace = "http://gys.webservice.service.userCenter.tempus.com/", serviceName = "SupplierHttpPortService", portName =
"SupplierHttpPortPort")
public class SupplierHttpPortDelegate {
com.tempus.userCenter.service.webservice.gys.SupplierHttpPort supplierHttpPort = new com.tempus.userCenter.service.webservice.gys.SupplierHttpPort
();
public ResSupplierOut updateSupplier(UpdateSupplierInput updateSupplierInput){
return supplierHttpPort.updateSupplier(updateSupplierInput);
}
}
实现方法
public class SupplierHttpPort {
private SupplierService tempusCountManager = (SupplierService) SpringContextUtil
.getBean("supplierService");
public ResSupplierOut updateSupplier(UpdateSupplierInput updSuppInp){
ResSupplierOut out=new ResSupplierOut();
SupplierCategory supplierCategory=null;
具体操作
}
}
传入对象必须格式
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "updateSupplierInput", propOrder = {"id","name","supplierCategory","payDay","subCompany","code","taxpayer","country","state",
"address","province","city","postal","supplierAddr","contactTitle","contact",
"email","phone","bankName","bankBranch","bankCode","bankUserName","payType",
"currencyBill","payBill","createTime","createName","updateTime","updateName",
"requestIp","updateUser","remark","agreementCode","businessType","isFixedSupplier","overTime",
"useNum","sftbgd","invoiceTitle"})
public class UpdateSupplierInput {
private String id;
/** 名称 */