WebService cxf提供接口

Posted wumengjuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebService cxf提供接口相关的知识,希望对你有一定的参考价值。

1.pom.xml配置

<cxf.version>3.1.7</cxf.version>

<!-- cxf.dependency -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>

2.web.xml

<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

3.mybatis.xml

---xmlns:jaxws="http://cxf.apache.org/jaxws" 

--http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- 扫描cxf包 -->
<context:component-scan base-package="com.djzh.cxf"></context:component-scan>
<!-- cxf整合spring -->
<jaxws:endpoint implementor="#query" address="/query" />

4.interface

@WebService
public interface CXFInterface {
String testConnection(String key);
String GetXJGH(int DWID,int JC,String Key);
String getXJDW(String ZH,String KHMC,String Key);
String getLastTime(int dwid,String Key);
String putLastTime(int DWID,String Date,String Key);
String GetPZS(int DWID,String Date1,String Date2,int XZED,String Key);
}

package com.djzh.cxf.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.djzh.basicdata.dao.IGhdmDao;
import com.djzh.cxf.CXFInterface;
import com.djzh.entity.Ghdm;
import com.djzh.entity.GhdmExample;
@Component("query")
@WebService
public class CXFInterfaceImpl implements CXFInterface {
private static String KEY="1";

@Resource
IGhdmDao ghdmDao;

@Override
public String testConnection(String key) {
if(KEY.equals(key)) {
return "CONNECTED";
}else {
throw new RuntimeException("key不相符");
}
}

@Override
public String GetXJGH(int dwid, int jc, String Key) {
//1.查询数据
GhdmExample ghdmExample=new GhdmExample();
ghdmExample.createCriteria().andSjghdmEqualTo(dwid+"").andGhccEqualTo(jc+"");
List<Ghdm> ghdmList=ghdmDao.selectByExample(ghdmExample);
//2.解析xml
String dws=getXml(ghdmList);

return dws;
}

private String getXml(List<Ghdm> ghdmList) {
if(ghdmList != null && ghdmList.size()>0) {
StringBuilder ghdmXmlStr = new StringBuilder();
ghdmXmlStr.append("<DWS>");
for(Ghdm ghdm:ghdmList) {
ghdmXmlStr.append("<DW><ID>"+ghdm.getGhdm()+"</ID><GHMC>"+ghdm.getGhmc()+"</GHMC><DW>");
}
ghdmXmlStr.append("</DWS>");
return ghdmXmlStr.toString();
}else {
return "";
}

}

@Override
public String getLastTime(int dwid, String Key) {
String lastTime=ghdmDao.getLastDownLoadTime(dwid);
return "<Res><LASTDATE>"+(lastTime==null?"":lastTime)+"</LASTDATE></Res>";
}

@Override
public String getXJDW(String ZH, String KHMC, String Key) {
// TODO Auto-generated method stub
return null;
}

@Override
public String putLastTime(int dwid, String date, String Key) {
ghdmDao.deleteLastDownLoadTime(dwid);
int insertFlag = ghdmDao.insertLastDownLoadTime(dwid,date);
if(insertFlag>0) {
return "<Res>OK</Res>";
}else {
return "上传失败";
}

}

@Override
public String GetPZS(int DWID, String Date1, String Date2, int XZED, String Key) {
// TODO Auto-generated method stub
return null;
}

}

 




































































































以上是关于WebService cxf提供接口的主要内容,如果未能解决你的问题,请参考以下文章

WebService cxf提供接口

webservice -- cxf客户端调用axis2服务端

如何使用CXF调用webservice接口

webService 接口调用问题

SpringBoot Spring Cloud 整合cxf开发webService接口服务端-流程步骤

webserive学习记录3-eclipse创建webservice