HAP_hap调用rest接口

接口:


HAP_hap调用rest接口_第1张图片
image.png
public interface IOra20796StudentRestService extends IBaseService, ProxySelf {

    public ResponseData intgAction(IRequest requestContext, Ora20796Student dto) throws Exception;
}

实现接口:

package wht.ora20796.service.impl;

import com.hand.hap.core.IRequest;
import com.hand.hap.intergration.dto.HapInterfaceHeader;
import com.hand.hap.intergration.service.IHapApiService;
import com.hand.hap.intergration.service.IHapInterfaceHeaderService;
import com.hand.hap.intergration.service.impl.HapRestApiServiceImpl;
import com.hand.hap.system.dto.ResponseData;
import com.hand.hap.system.service.impl.BaseServiceImpl;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import wht.ora20796.dto.Ora20796Student;
import wht.ora20796.service.IOra20796StudentRestService;
import wht.ora20796.service.IOra20796StudentService;

import javax.annotation.Resource;

public class Ora20796RestApiServiceImpl extends BaseServiceImpl implements IOra20796StudentRestService {
    @Autowired
    private IHapInterfaceHeaderService headerService;
    @Resource(name = "restBean")
    private IHapApiService restService;
    @Override
    public ResponseData intgAction(IRequest requestContext, Ora20796Student dto) throws Exception {
        ResponseData responseData = new ResponseData();
        JSONObject Response_Json;
        JSONObject jsonObj;
        try {
            jsonObj = JSONObject.fromObject(dto);
            System.out.println("返回报文:" + jsonObj.toString());
    //RestApiTest1--系统代码,REST--接口代码
            HapInterfaceHeader hapInterfaceHeader = this.headerService
                    .getHeaderAndLine("RestApiTest1", "REST");
            Response_Json = this.restService.invoke(hapInterfaceHeader, jsonObj);
            if (Response_Json != null) {
                System.out.println("返回报文:" + Response_Json.toString());
                responseData.setMessage(Response_Json.toString());
            }
        } catch (Exception e) {
            throw e;
        }
        return responseData;
    }
}

你可能感兴趣的:(HAP_hap调用rest接口)