1、需要发布webservice服务端
package com.hst.ces.fmapi;
import com.hst.ces.fmapi.service.component.FmApiAuthInterceptor;
import com.hst.ces.fmapi.webservice.IWebserviceJaxws;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
/**
* @author chenhuanwei
* @date 2019/12/26
*/
@Configuration
public class WebserviceConfig {
/**
* 发布的访问URL
**/
private static final String PUBLISH_URL_MEETING = "/jaxws";
/**
* Webservice发布
*/
@Bean
@Qualifier("FMAPI_MEETING_ENDPOINT")
public Endpoint meetEndpoint(Bus bus,FmApiAuthInterceptor authInterceptor,IWebserviceJaxws jaxws) {
EndpointImpl endpoint = new EndpointImpl(bus, jaxws);
endpoint.publish(PUBLISH_URL_MEETING);
endpoint.getInInterceptors().add(authInterceptor);
return endpoint;
}
}
bus中使用了cxf发布:
hst:
ces:
#录播参数
record:
secretKey: 2e3a0126-1ab1-47f7-a68f-467a78370d5e
accessKey: cec3ed07-2c0d-49d7-b424-f64a2064f9d7
paths:
query: /tpi/ces/getRescByCesQuery
delete: /tpi/ces/deleteResc
playUrl: /tpi/ces/queryRescPlayUrl
downloadUrl: /tpi/ces/queryRescDownloadUrl
thumbnailsUrl: /tpi/ces/queryRescThumbnails
fmapi:
keyCode: fswebservice2011
onlinePort: 4430
cxf:
path: /fmapi/webservice //地址
servlet:
load-on-startup: 1
2、也可以做拦截处理权限
/*
* Project Name:fmapi
* File Name:AuthInterceptor.java
* Package Name:com.hst.ces.utils
* Date:2016年6月1日
* Copyright (c) 2016 HST Inc. All Rights Reserved.
*
*/
package com.hst.ces.fmapi.service.component;
import com.hst.ces.base.constant.CacheConstant;
import com.hst.ces.cache.HstCache;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.springframework.stereotype.Component;
/**
* @author Solin
*/
@Component
public class FmApiAuthInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
public FmApiAuthInterceptor() {
// 拦截器在调用方法之前拦截SOAP消息
super(Phase.PRE_INVOKE);
}
/**
* @param msg 被拦截到的SOAP消息
* @throws Fault authentication does not support
* @Description: 拦截器操作
*/
@Override
public void handleMessage(SoapMessage msg) throws Fault {
String authType = HstCache.getString(HstCache.SYSTEM,
CacheConstant.SYS_PARAM_PREFIX + "AuthType");
if (!"FSMeetingAuth".equals(authType)) {
throw new Fault(new IllegalArgumentException(
"The system does not support the current authentication type!!"));
}
}
}
3、写webService接口。
@Controller
@WebService(targetNamespace = "http://webservice.ces.hst.com/")
public interface IWebserviceJaxws {
/**
* 添加会议室(默认开启录制接口)
*/
String defaultRecording(@WebParam(name = "roomName") String roomName,
@WebParam(name = "endRecordInterval") Integer endRecordInterval,
@WebParam(name = "recordStartTime") String recordStartTime,
@WebParam(name = "userId") Integer userId,
@WebParam(name = "maxUserCount") Integer maxUserCount,
@WebParam(name = "enableRecord") String enableRecord,
@WebParam(name = "workNo") Integer workNo,
@WebParam(name = "keyCode") String keyCode);
}
4、写接口实现类
@Controller("jaxwsSerivce")
@WebService(targetNamespace = "http://webservice.ces.hst.com/",
endpointInterface = "com.hst.ces.webservice.IWebserviceJaxws",
serviceName = "jaxws")
public class WebServiceJaxws implements IWebserviceJaxws {
@Override
public String defaultRecording(String roomName, Integer endRecordInterval, String recordStartTime, Integer userId, Integer maxUserCount, String enableRecord, Integer workNo, String keyCode) {
return SpringContextUtil.getBean(AddRoominfoImpl.class)
.dealRecording(roomName, endRecordInterval, recordStartTime, maxUserCount, userId, enableRecord, workNo, keyCode, null);
}
}
5、工具类利用SpringContextUtil 上下文获取bean
@Component("springContextUtil")
public class SpringContextUtil implements ApplicationContextAware {
/**
* 根据类从spring上下文获取bean。
*
* @param cls class类型
*/
public static <T> T getBean(Class<T> cls) {
return applicationContext.getBean(cls);
}
}
6、添加会议室的逻辑并在结尾返回soap协议的返回值
public String dealRecording(String roomName, Integer endRecordInterval, String recordStartTime, Integer maxUserCount, Integer userId, String enableRecord, Integer workNo, String keyCode, Integer departId) {
String info = RoominfoCheckout.dealRecordingCheckout(roomName, endRecordInterval, recordStartTime, maxUserCount,
userId, enableRecord, workNo, keyCode, departId);
if (!"SUCCESS".equals(info)) {
return ResponseXmlUtil.ResponseDefeat(info);
}
RoominfoBean room = new RoominfoBean();
room.setRoomName(roomName);
room.setMaxUserCount(maxUserCount);
room.setEnableRecord(enableRecord);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
room.setRecordStartTime(simpleDateFormat.parse(recordStartTime));
} catch (ParseException parseException) {
log.info("defaultRecording throws Exception " + parseException.getMessage());
}
room.setDepartId(Optional.ofNullable(departId)
.filter(id -> id != 0)
.orElseGet(departService::findRootDepartID));
room.setVerifyMode("1");
int returnid = roomService.insertFast(room);
RecordSettingsBean recordSetting = new RecordSettingsBean();
recordSetting.setEndRecordInterval(endRecordInterval);
recordSetting.setRecordStartTime(recordStartTime);
recordSetting.setRoomid(returnid);
recordSetting.setAutoRecord(true);
recordSetting.setAutoAudit(true);
recordSetting.setGlobalSwitch(true);
recordSetting.setVideoResolution((byte) 3);
recordSetting.setRecordMode((byte) 1);
recordSetting.setVideoDisplayMode((byte) 2);
recordSetting.setDataDisplayMode((byte) 3);
recordSetting.setRecordFileSlice(true);
recordSetting.setWatermarkMode((byte) 1);
recordSetting.setWatermarkLocation((byte) 5);
recordSetting.setTimestampInfo("3");
int insert = recordSttingService.insert(recordSetting);
RoomWorkBean roomWorkBean = new RoomWorkBean();
roomWorkBean.setRoomId(returnid);
roomWorkBean.setWorkNo(workNo);
int insertWork = roomWork.insert(roomWorkBean);
if (returnid < 1 && insert < 1 && insertWork < 1) {
log.info("defaultRecording,roomName = " + roomName + ";result = " + SystemConst.RESPONSE_DEFEAT);
return ResponseXmlUtil.ResponseDefeat(SystemConst.ROOM_SAVE_ERROR);
}
String code = SystemConst.SUCCESS;
String msg = SystemConst.RESPONSE_SUCCESS;
log.info("defaultRecording,roomName = " + roomName + ";result = " + SystemConst.RESPONSE_SUCCESS);
InvitecodeBean invitecodeBean = invitecodeDao.selectOne(returnid);
ResultBean resultBean = new ResultBean();
resultBean.setRoomId(returnid);
resultBean.setCodeId(invitecodeBean.getCodeId());
resultBean.setWorkNo(workNo);
resultBean.setRoomName(roomName);
resultBean.setRecordStartTime(recordStartTime);
resultBean.setEndRecordInterval(endRecordInterval);
resultBean.setMaxUserCount(maxUserCount);
List<ResultBean> list = new ArrayList<ResultBean>();
list.add(resultBean);
ResponseResultBean responseResultBean = new ResponseResultBean(code, msg, Collections.singletonList(resultBean), list.size());
return ResponseXmlUtil.ResponseToXml(responseResultBean);
}
7、测试
public class Test {
public static void main(String[] args) throws Exception {
private static String defaultRecording(String roomName, Integer endRecordInterval, String recordStartTime, Integer userId,Integer maxUserCount, String enableRecord, Integer workNo, String keyCode) throws Exception {
//调用时改为自己服务器地址端口
String wsUrl = "http://localhost:8087/webservice/jaxws?wsdl";
String method = "defaultRecording";
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(new URL(wsUrl));
Object[] object = {roomName, endRecordInterval, recordStartTime, maxUserCount, userId, enableRecord, workNo, keyCode};
Object[] res = client.invoke(method, object);
System.out.println(res[0].toString() + "");
return res[0].toString() + "";
}
}
经过测试创建成功。