ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:34:48 2017 +0800
Revision:
45:2aa9f933c8d2
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 45:2aa9f933c8d2 1 /*
TMBOY 45:2aa9f933c8d2 2 * Copyright (c) 2017 Baidu, Inc. All Rights Reserved.
TMBOY 45:2aa9f933c8d2 3 *
TMBOY 45:2aa9f933c8d2 4 * Licensed under the Apache License, Version 2.0 (the "License");
TMBOY 45:2aa9f933c8d2 5 * you may not use this file except in compliance with the License.
TMBOY 45:2aa9f933c8d2 6 * You may obtain a copy of the License at
TMBOY 45:2aa9f933c8d2 7 *
TMBOY 45:2aa9f933c8d2 8 * http://www.apache.org/licenses/LICENSE-2.0
TMBOY 45:2aa9f933c8d2 9 *
TMBOY 45:2aa9f933c8d2 10 * Unless required by applicable law or agreed to in writing, software
TMBOY 45:2aa9f933c8d2 11 * distributed under the License is distributed on an "AS IS" BASIS,
TMBOY 45:2aa9f933c8d2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
TMBOY 45:2aa9f933c8d2 13 * See the License for the specific language governing permissions and
TMBOY 45:2aa9f933c8d2 14 * limitations under the License.
TMBOY 45:2aa9f933c8d2 15 */
TMBOY 45:2aa9f933c8d2 16 package com.baidu.duer.dcs.http;
TMBOY 45:2aa9f933c8d2 17
TMBOY 45:2aa9f933c8d2 18 import com.baidu.duer.dcs.util.CommonUtil;
TMBOY 45:2aa9f933c8d2 19
TMBOY 45:2aa9f933c8d2 20 import java.util.HashMap;
TMBOY 45:2aa9f933c8d2 21 import java.util.Map;
TMBOY 45:2aa9f933c8d2 22
TMBOY 45:2aa9f933c8d2 23 /**
TMBOY 45:2aa9f933c8d2 24 * HttpConfig
TMBOY 45:2aa9f933c8d2 25 * <p>
TMBOY 45:2aa9f933c8d2 26 * Created by zhangyan42@baidu.com on 2017/6/1.
TMBOY 45:2aa9f933c8d2 27 */
TMBOY 45:2aa9f933c8d2 28 public class HttpConfig {
TMBOY 45:2aa9f933c8d2 29 // 请求https
TMBOY 45:2aa9f933c8d2 30 public static final String HTTP_PREFIX = "https://";
TMBOY 45:2aa9f933c8d2 31 // 请求host
TMBOY 45:2aa9f933c8d2 32 public static final String HOST = "dueros-h2.baidu.com";
TMBOY 45:2aa9f933c8d2 33 public static String endpoint = null;
TMBOY 45:2aa9f933c8d2 34 // 请求event事件
TMBOY 45:2aa9f933c8d2 35 public static final String EVENTS = "/dcs/v1/events";
TMBOY 45:2aa9f933c8d2 36 // 请求directives事件
TMBOY 45:2aa9f933c8d2 37 public static final String DIRECTIVES = "/dcs/v1/directives";
TMBOY 45:2aa9f933c8d2 38 // ping
TMBOY 45:2aa9f933c8d2 39 public static final String PING = "/dcs/v1/ping";
TMBOY 45:2aa9f933c8d2 40 // 请求event事件TAG
TMBOY 45:2aa9f933c8d2 41 public static final String HTTP_EVENT_TAG = "event";
TMBOY 45:2aa9f933c8d2 42 // 请求directives事件TAG
TMBOY 45:2aa9f933c8d2 43 public static final String HTTP_DIRECTIVES_TAG = "directives";
TMBOY 45:2aa9f933c8d2 44 // 请求ping的TAG
TMBOY 45:2aa9f933c8d2 45 public static final String HTTP_PING_TAG = "ping";
TMBOY 45:2aa9f933c8d2 46
TMBOY 45:2aa9f933c8d2 47 public static String getEndpoint() {
TMBOY 45:2aa9f933c8d2 48 if (null == endpoint || "".equals(endpoint)) {
TMBOY 45:2aa9f933c8d2 49 endpoint = HTTP_PREFIX + HOST;
TMBOY 45:2aa9f933c8d2 50 }
TMBOY 45:2aa9f933c8d2 51 return endpoint;
TMBOY 45:2aa9f933c8d2 52 }
TMBOY 45:2aa9f933c8d2 53
TMBOY 45:2aa9f933c8d2 54 public static void setEndpoint(String endpoint) {
TMBOY 45:2aa9f933c8d2 55 HttpConfig.endpoint = endpoint;
TMBOY 45:2aa9f933c8d2 56 }
TMBOY 45:2aa9f933c8d2 57
TMBOY 45:2aa9f933c8d2 58 public static String getEventsUrl() {
TMBOY 45:2aa9f933c8d2 59 return getEndpoint() + EVENTS;
TMBOY 45:2aa9f933c8d2 60 }
TMBOY 45:2aa9f933c8d2 61
TMBOY 45:2aa9f933c8d2 62 public static String getDirectivesUrl() {
TMBOY 45:2aa9f933c8d2 63 return getEndpoint() + DIRECTIVES;
TMBOY 45:2aa9f933c8d2 64 }
TMBOY 45:2aa9f933c8d2 65
TMBOY 45:2aa9f933c8d2 66 public static String getPingUrl() {
TMBOY 45:2aa9f933c8d2 67 return getEndpoint() + PING;
TMBOY 45:2aa9f933c8d2 68 }
TMBOY 45:2aa9f933c8d2 69
TMBOY 45:2aa9f933c8d2 70 public static class HttpHeaders {
TMBOY 45:2aa9f933c8d2 71 public static final String CONTENT_TYPE = "Content-Type";
TMBOY 45:2aa9f933c8d2 72 public static final String DUEROS_DEVICE_ID = "dueros-device-id";
TMBOY 45:2aa9f933c8d2 73 public static final String AUTHORIZATION = "Authorization";
TMBOY 45:2aa9f933c8d2 74 public static final String CONTENT_ID = "Content-ID";
TMBOY 45:2aa9f933c8d2 75 public static final String BEARER = "Bearer ";
TMBOY 45:2aa9f933c8d2 76 public static final String DEBUG = "debug";
TMBOY 45:2aa9f933c8d2 77 public static final String DEBUG_PARAM = "0";
TMBOY 45:2aa9f933c8d2 78 }
TMBOY 45:2aa9f933c8d2 79
TMBOY 45:2aa9f933c8d2 80 public static class ContentTypes {
TMBOY 45:2aa9f933c8d2 81 public static final String JSON = "application/json";
TMBOY 45:2aa9f933c8d2 82 public static final String FORM_MULTIPART = "multipart/form-data boundary=dumi-boundory";
TMBOY 45:2aa9f933c8d2 83 public static final String APPLICATION_JSON = JSON + ";" + " charset=UTF-8";
TMBOY 45:2aa9f933c8d2 84 public static final String APPLICATION_AUDIO = "application/octet-stream";
TMBOY 45:2aa9f933c8d2 85 }
TMBOY 45:2aa9f933c8d2 86
TMBOY 45:2aa9f933c8d2 87 public static class Parameters {
TMBOY 45:2aa9f933c8d2 88 public static final String BOUNDARY = "boundary";
TMBOY 45:2aa9f933c8d2 89 public static final String DATA_METADATA = "metadata";
TMBOY 45:2aa9f933c8d2 90 public static final String DATA_AUDIO = "audio";
TMBOY 45:2aa9f933c8d2 91 }
TMBOY 45:2aa9f933c8d2 92
TMBOY 45:2aa9f933c8d2 93 public static String accessToken = "";
TMBOY 45:2aa9f933c8d2 94
TMBOY 45:2aa9f933c8d2 95 public static String getAccessToken() {
TMBOY 45:2aa9f933c8d2 96 return accessToken;
TMBOY 45:2aa9f933c8d2 97 }
TMBOY 45:2aa9f933c8d2 98
TMBOY 45:2aa9f933c8d2 99 public static void setAccessToken(String accessToken) {
TMBOY 45:2aa9f933c8d2 100 HttpConfig.accessToken = accessToken;
TMBOY 45:2aa9f933c8d2 101 }
TMBOY 45:2aa9f933c8d2 102
TMBOY 45:2aa9f933c8d2 103 /**
TMBOY 45:2aa9f933c8d2 104 * 获取dcs的headers
TMBOY 45:2aa9f933c8d2 105 *
TMBOY 45:2aa9f933c8d2 106 * @return header集合
TMBOY 45:2aa9f933c8d2 107 */
TMBOY 45:2aa9f933c8d2 108 public static Map<String, String> getDCSHeaders() {
TMBOY 45:2aa9f933c8d2 109 Map<String, String> headers = new HashMap<>();
TMBOY 45:2aa9f933c8d2 110 headers.put(HttpConfig.HttpHeaders.AUTHORIZATION,
TMBOY 45:2aa9f933c8d2 111 HttpConfig.HttpHeaders.BEARER + getAccessToken());
TMBOY 45:2aa9f933c8d2 112 headers.put(HttpConfig.HttpHeaders.CONTENT_TYPE,
TMBOY 45:2aa9f933c8d2 113 HttpConfig.ContentTypes.FORM_MULTIPART);
TMBOY 45:2aa9f933c8d2 114 headers.put(HttpConfig.HttpHeaders.DUEROS_DEVICE_ID,
TMBOY 45:2aa9f933c8d2 115 CommonUtil.getDeviceUniqueID());
TMBOY 45:2aa9f933c8d2 116 headers.put(HttpConfig.HttpHeaders.DEBUG,
TMBOY 45:2aa9f933c8d2 117 HttpConfig.HttpHeaders.DEBUG_PARAM);
TMBOY 45:2aa9f933c8d2 118 return headers;
TMBOY 45:2aa9f933c8d2 119 }
TMBOY 45:2aa9f933c8d2 120 }