Webservice - Demo : Spring + CXF + JSON(服务器篇)

Webservice - Demo : Spring + CXF + JSON(服务器篇)

一、applicationContext-server.xml




            
            
            

            

 

二、PatientWs

package com.xxx.webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface PatientWs {
	
	/**
	 * 状态码 state: 0\1\9
	 * 		state = 9 : 病人签到成功	==> 进入大厅候诊队列
	 * 		state = 1 : 病人大厅候诊结束	==> 诊区候诊开始
	 * 		state = 0 : 病人诊区候诊结束	==> 医生就诊开始
	 * @param patientList
	 * @return
	 */
	@WebMethod
    @WebResult(name = "getPatient")
    public String getPatientsByJsonArray(@WebParam(name = "patientList")String patientList);
	
}

三、PatientWsImpl

package com.xxx.webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("patientWs")
@WebService(targetNamespace = "http://webservice.xxx.com")
@SOAPBinding(style = Style.RPC)
public class PatientWsImpl implements PatientWs{
	
    private Logger log = LoggerFactory.getLogger(this.getClass());
    
    /**
	 * 状态码 state: 0\1\9
	 * 		state = 9 : 病人签到成功	==> 进入大厅候诊队列
	 * 		state = 1 : 病人大厅候诊结束	==> 诊区候诊开始
	 * 		state = 0 : 病人诊区候诊结束	==> 医生就诊开始
	 * @param patientList
	 * @return
	 */
    @WebMethod
    @WebResult(name = "getPatients")
	public String getPatientsByJsonArray(@WebParam(name = "patientList")String patientList){
    	int f = 1;
    	Object[] obj = JsonUtil.getJsonToArray(patientList);
    	if(!obj.equals("")){ 
    		for(int i=0;i

四、补充个JsonUtil

package com.xxx.webservice;

import net.sf.json.JSONArray;

import com.alibaba.fastjson.JSON;

public class JsonUtil {
	
	private static final String DEFAULT_CHARSET_NAME = "UTF-8";
	
	public static String serialize(T object){
		return JSON.toJSONString(object);
	}
	
	public static Object[] getJsonToArray(String str) {
        JSONArray jsonArray = JSONArray.fromObject(str);
        return jsonArray.toArray();
    }
	
}

五、相关jar包下载

http://download.csdn.net/detail/u010823625/9674062

你可能感兴趣的:(WebService,-,Demo,(入门篇))