package org.jeecg.modules.system.util;

import javax.xml.namespace.QName;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;

import com.alibaba.fastjson.JSONObject;

public class WebServiceUtil {
	
	/**
	 * 调用openmeeting服务获取聊天室地址
	 * @param username 
	 * @param roomId
	 * @return
	 */
	public static String send(String username,Long roomId,String namespace) {
		//wsdl地址
        String url = namespace + "/openmeetings/services/ApiRoomService?wsdl";
        //命名空间
//        String namespace = "http://gxb.v1.idcfengye.com";
        //方法名
        String methodName = "getRoomUrl";
 
        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        Client client = factory.createClient(url);
        Endpoint endpoint = client.getEndpoint();
        QName opName = new QName(namespace, methodName);
        BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
        if (bindingInfo.getOperation(opName) == null) {
            for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
                if (methodName.equals(operationInfo.getName().getLocalPart())) {
                    opName = operationInfo.getName();
                    break;
                }
            }
        }
        try {
            Object[] objects = client.invoke(opName,  username,roomId);
            Object object = objects[0];
            String resultMsg = JSONObject.toJSONString(object);
            return resultMsg;
        } catch (java.lang.Exception e) {
            e.printStackTrace();
            System.out.println("异常信息 ：" + e.getMessage());
        }
        return null;
	}

}
