91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么使用Java代碼在SAP Marketing Cloud上創建Contact數據

發布時間:2021-11-03 10:29:26 來源:億速云 閱讀:150 作者:iii 欄目:編程語言

本篇內容主要講解“怎么使用Java代碼在SAP Marketing Cloud上創建Contact數據”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么使用Java代碼在SAP Marketing Cloud上創建Contact數據”吧!

源代碼:

package partner1;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.net.URI;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.StatusLine;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.HttpClientBuilder;import sun.misc.BASE64Encoder;public class SimpleContactCreator {
    private ConfigUtil mConfigUtil = new ConfigUtil();
    HttpClient m_httpClient;
    public SimpleContactCreator(){
        enableHeaderWireAndContextLogging();
    }
    private void enableHeaderWireAndContextLogging(){
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
        System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
        System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");
    }
    private String getBasicAuth(){
        final String text = mConfigUtil.getConfig("user") + ":" + mConfigUtil.getConfig("password");        
        BASE64Encoder encoder = new BASE64Encoder();
        String credentials = "basic " + encoder.encode(text.getBytes());
        return credentials;
    }
    private HttpClient getHttpClient() {
        if (this.m_httpClient == null) {
            this.m_httpClient = HttpClientBuilder.create().build();
        }
        return this.m_httpClient;
    }
    private String getCSRFToken(){
        String url = mConfigUtil.getConfig("tokenurl");
        System.out.println("fetch CSRF token via url: " + url);
        final HttpGet get = new HttpGet(url);
        get.setHeader("Authorization", getBasicAuth());
        get.setHeader("Cache-Control", "no-cache");
        get.setHeader("content-type", "application/json");
        get.setHeader("Accept", "application/json");
        get.setHeader("x-csrf-token", "fetch");
        HttpResponse response;
        String token = null;
        try {
            response = getHttpClient().execute(get);
            StatusLine statusLine = response.getStatusLine();
            int code = statusLine.getStatusCode();
            System.out.println("Status code: " + code);
            System.out.println("reason: " + statusLine.getReasonPhrase());
            token = response.getFirstHeader("x-csrf-token").getValue();
            System.out.println("token: " + token);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException | UnsupportedOperationException e) {
            e.printStackTrace();
        }
        return token;
    }
    public void run(String body){
        String token = getCSRFToken();
        createContact(token, body);
    }
    private void createContact(String token, String body){
        final HttpPost post = new HttpPost(
            URI.create(mConfigUtil.getConfig("contactcreateurl")));
        post.setHeader("Authorization", getBasicAuth());
        post.setHeader("Content-Type", "application/json");
        post.setHeader("X-CSRF-Token", token);
        HttpEntity entity = null;
        try {
            entity = new StringEntity(body);
        } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        }
        post.setEntity(entity);
        HttpResponse response = null;
        try {
            response = getHttpClient().execute(post);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Response statusCode for Batch => "
            + response.getStatusLine().getStatusCode());
    }
    public static void main(String[] args) {
        SimpleContactCreator tool = new SimpleContactCreator();
        String body = "{\"IsConsumer\":true," + 
                      "\"Filter\":{\"MarketingArea\":\"CXXGLOBAL\"}," + 
                      "\"__metadata\":{\"type\":\"CUAN_CONTACT_SRV.InteractionContact\"}," + 
                      "\"FirstName\":\"SAP Diablo\",\"LastName\":\"SAP Wang\",\"Country\":\"CN\"," + 
                      "\"EMailAddress\":\"seya@sap.com\",\"YY1_WECHATID_MPS\":\"i042416\"," + 
                      "\"YY1_FACEID_MPS\":\"d042416\"}";
        tool.run(body);
    }}package partner1;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class ConfigUtil {
    Properties prop; 
    public ConfigUtil(){
        InputStream input = null;
        prop = new Properties();
        String propFileName = "config.properties";
        input = getClass().getClassLoader().getResourceAsStream(propFileName);
        if (input != null) {
                try {
                    prop.load(input);
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
    public String getConfig(String name){
        return prop.getProperty(name);
    }
    public static void main(String[] argv){
        ConfigUtil tool = new ConfigUtil();
        System.out.println("User: " + tool.getConfig("user"));
    }}

config.properties文件放在resources文件夾下:

user=mkt
password=MY
tokenurl=https://jerry.hybris.com/sap/opu/odata/sap/CUAN_COMMON_SRV/?sap-client=100
# not batch
contactcreateurl=https://jerry.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/InteractionContacts?sap-client=100

到此,相信大家對“怎么使用Java代碼在SAP Marketing Cloud上創建Contact數據”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

定西市| 肥乡县| 洛宁县| 融水| 三台县| 苍梧县| 余江县| 海城市| 康马县| 屯门区| 九江县| 佛冈县| 繁峙县| 宁安市| 祁东县| 古丈县| 贵港市| 田东县| 德保县| 林州市| 望城县| 北流市| 崇义县| 盐城市| 白城市| 会东县| 天门市| 平潭县| 顺义区| 石泉县| 尤溪县| 长岭县| 崇左市| 翁牛特旗| 龙里县| 灵川县| 星座| 岑巩县| 中西区| 益阳市| 加查县|