CFESB标准请求-JAVA接入

前言

​ 如何快速接入CFESB,只需要简单的三步:1、注册服务;2、授权业务系统;3、请求CFESB地址;

参考:

1、CFESB企业服务总线平台-服务注册

2、CFESB企业服务总线平台-服务维护

3、CFESB企业服务总线平台-服务授权

前题资源

​ CFESB管理平台已注册服务并获得如下参数:

​ CFESB请求地址:http://cfesb.zicp.net/esb/REST_REST/standard

​ 服务编号:01002000000001

​ 请求系统号:01003

CFESB请求

​ 使用soapui新建REST工程并使用标准post请求

image-20210705173043674

JAVA程序请求-ws

image-20210706113838429

程序源码-请求WS

package com.http.request;

import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class Request {
    public static void main(String[] args){
        String Xmlparam = "<arg0>1</arg0>";
        String token = "w9PJslBtNGJMuLXY3y08pZwddp-m53-l";
        String requestbody= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:impl=\"http://impl.webservcice.eis.com/\">"
                + "   <soapenv:Header/>"
                + "   <soapenv:Body>"
                + "      <esbService>"
                + "         <msg>"
                + "            <Service>"
                + "               <Route>"
                + "<token>"+token+"</token>"
                + "               </Route>"
                + "               <Data>"
                + "                  <Request>"
                +                        Xmlparam
                + "                  </Request>"
                + "               </Data>"
                + "            </Service>"
                + "         </msg>"
                + "      </esbService>"
                + "   </soapenv:Body>"
                + "</soapenv:Envelope>";
        HttpClient httpClient = HttpClients.createDefault();
        //url为ESB的访问地址
        String  url = "http://cfesb.zicp.net/esb/WS_WS/standard";
        HttpPost httppost = new HttpPost(url);
        HttpEntity he;
        try {
            he = new StringEntity(requestbody, "UTF-8");
            httppost.setHeader("Content-Type","text/xml;charset=UTF-8");
            httppost.setEntity(he);
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try{
            HttpResponse response = httpClient.execute(httppost);
            String responseStr = "";
            responseStr = EntityUtils.toString(response.getEntity());
            System.out.println(responseStr);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

JAVA程序请求-REST

image-20210706114356643

程序源码-请求REST

package com.http.request;

import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class RequestRest {
    public static void main(String[] args){
        String param = "{ \"employeeId\":\"4\"}";
        String token = "cZBRM1xNyD5MuLXY3y08pdDeBOEWmhCx";
        String requestbody= "{"
                + "  \"Service\": {"
                + "    \"Route\": {"
                + "      \"token\": \""+token+"\""
                + "    },"
                + "    \"Data\": {"
                + "      \"Control\": \"?\","
                + "      \"Request\":"+param+""
                + "    }"
                + "  }"
                + "}";
        HttpClient httpClient = HttpClients.createDefault();
        //url为ESB的访问地址
        String  url = "http://cfesb.zicp.net/esb/REST_REST/standard";
        HttpPost httppost = new HttpPost(url);
        HttpEntity he;
        try {
            he = new StringEntity(requestbody, "UTF-8");
            httppost.setHeader("Content-Type","application/json;charset=UTF-8");
            httppost.setEntity(he);
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try{
            HttpResponse response = httpClient.execute(httppost);
            String responseStr = "";
            responseStr = EntityUtils.toString(response.getEntity());
            System.out.println(responseStr);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

© 2021 CFESB.CN all right reserved,powered by Gitbook 本文档更新于: 2021-07-06 16:26

results matching ""

    No results matching ""