接口代碼如下:
@WebService
public interface SysCustomerAttachmentService {
@WebMethod
ESBResponseEntity insertCousterAttachment(@WebParam(name="header") ESBHeaderEntity header,@WebParam(name="list") List<CustomAttachmentContentEntity> list);
}
實現類代碼:
@WebService(targetNamespace="http://service.jfcus.modules.fawjiefang.com/",endpointInterface = "com.fawjiefang.modules.jfcus.service.SysCustomerAttachmentService")
//@Service("sysCustomerAttachmentService")
public class SysCustomerAttachmentServiceImpl extends ServiceImpl<SysCustomerAttachmentDao, CustomAttachmentContentEntity> implements SysCustomerAttachmentService {
@Autowired
SysCustomerAttachmentDao sysCustomerAttachmentDao;
@Transactional
@Override
public ESBResponseEntity insertCousterAttachment(ESBHeaderEntity header,List<CustomAttachmentContentEntity> list) {
ESBResponseEntity entity = new ESBResponseEntity();
try {
if(header == null){
entity.setResultType("0");
entity.setResultCode("502");
entity.setResultMessage("成功接收0條數據,報文中body中arg0信息是空");
return entity;
}
if(list == null || list.size() == 0){
entity.setResultType("0");
entity.setResultCode("502");
entity.setResultMessage("成功接收0條數據,報文中body中arg1信息爲空");
return entity;
}
for (int i=0;i<list.size();i++) {
UUID uuid = UUID.randomUUID();
list.get(i).setID(uuid.toString());
list.get(i).setJSTIME(new Date().toString());
list.get(i).setTRANSID(header.getTransID());
list.get(i).setMESSAGEID(header.getMessageID());
}
sysCustomerAttachmentDao.saveCustomAttachment(list);
entity.setCount(header.getCount());
entity.setMessageID(header.getMessageID());
entity.setTransID(header.getTransID());
entity.setInterfaceID(header.getInterfaceID());
entity.setResultType("0");
entity.setResultCode("502");
entity.setResultMessage("成功接收"+list.size()+"數據");
return entity;
} catch (Exception e) {
e.printStackTrace();
entity.setResultCode("402");
entity.setResultType("-1");
entity.setResultMessage("服務異常,請聯繫相關人員");
return entity;
}
}
}
配置類:
@Configuration
public class WebConfig{
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public ServletRegistrationBean getCXFServlet(){
return new ServletRegistrationBean(new CXFServlet() , "/webService/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus()
{
return new SpringBus();
}
@Bean
public SysCustomerAttachmentService sysCustomerAttachmentService()
{
return new SysCustomerAttachmentServiceImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint=new EndpointImpl(springBus(), sysCustomerAttachmentService());
endpoint.publish("/sysCustomerAttachmentService");
return endpoint;
}
}
如下截圖:是項目中shiro的路徑權限配置,注意紅色部分意思是不是任何路徑都可以匿名訪問的,所以利用cxf發佈接口時要注意發佈的路徑不可以是/**或者/*,發佈其他路徑時記得要在shiro權限過濾中設置發佈的路徑可以匿名訪問。如綠色框中的部分。重新啓動項目即可訪問成功。