From b593856f035b0467fcd54e5782c63d8c8f06ff60 Mon Sep 17 00:00:00 2001 From: FriendshipBridge Date: Thu, 3 Sep 2020 17:38:51 +0800 Subject: [PATCH] update bvw --- pom.xml | 6 -- .../com/baidubce/services/bvw/BvwClient.java | 62 ++----------------- .../videoedit/VideoEditCreateRequest.java | 52 ++++++++++------ 3 files changed, 37 insertions(+), 83 deletions(-) diff --git a/pom.xml b/pom.xml index e5d1fb2e..5883b208 100644 --- a/pom.xml +++ b/pom.xml @@ -203,12 +203,6 @@ 1.9.5 test - - org.json - json - 20140107 - compile - diff --git a/src/main/java/com/baidubce/services/bvw/BvwClient.java b/src/main/java/com/baidubce/services/bvw/BvwClient.java index 4ee55773..07d8dde4 100644 --- a/src/main/java/com/baidubce/services/bvw/BvwClient.java +++ b/src/main/java/com/baidubce/services/bvw/BvwClient.java @@ -71,7 +71,6 @@ import com.baidubce.util.HttpUtils; import com.baidubce.util.JsonUtils; import org.apache.commons.lang3.StringUtils; -import org.json.JSONObject; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -883,70 +882,17 @@ public Text2AudioResponse text2Audio(Text2AudioRequest text2AudioRequest) { return invokeHttpClient(request, Text2AudioResponse.class); } - /** - * The method to fill the internalRequest's content field with bceRequest. - * Only support HttpMethodName.POST or HttpMethodName.PUT - * - * @param internalRequest A request object, populated with endpoint, resource path, ready for callers to populate - * any additional headers or parameters, and execute. - * @param bceRequest The original request, as created by the user. - */ - private void fillEditPayload(InternalRequest internalRequest, AbstractBceRequest bceRequest) { - if (internalRequest.getHttpMethod() == HttpMethodName.POST - || internalRequest.getHttpMethod() == HttpMethodName.PUT) { - String strJson = new JSONObject(bceRequest).toString(); - byte[] requestJson; - try { - requestJson = strJson.getBytes(DEFAULT_ENCODING); - } catch (UnsupportedEncodingException e) { - throw new BceClientException("Unsupported encode.", e); - } - internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(requestJson.length)); - internalRequest.addHeader(Headers.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - internalRequest.setContent(RestartableInputStream.wrap(requestJson)); - } - } - - /** - * Creates and initializes a new request object for the specified bcc resource. This method is responsible - * for determining the right way to address resources. - * - * @param bceRequest The original request, as created by the user. - * @param httpMethod The HTTP method to use when sending the request. - * @param pathVariables The optional variables used in the URI path. - * @return A new request object, populated with endpoint, resource path, ready for callers to populate - * any additional headers or parameters, and execute. - */ - private InternalRequest createEditRequest(AbstractBceRequest bceRequest, HttpMethodName httpMethod, - String... pathVariables) { - List path = new ArrayList(); - path.add(VERSION); - if (pathVariables != null) { - for (String pathVariable : pathVariables) { - path.add(pathVariable); - } - } - URI uri = HttpUtils.appendUri(this.getEndpoint(), path.toArray(new String[path.size()])); - InternalRequest request = new InternalRequest(httpMethod, uri); - request.setCredentials(bceRequest.getRequestCredentials()); - if (httpMethod == HttpMethodName.POST - || httpMethod == HttpMethodName.PUT) { - fillEditPayload(request, bceRequest); - } - return request; - } - /** * create a task of video edit * The cmd Object in VideoEditCreateRequest - * 1> do not need to modify it by your self, you only put the json string to JSONObject to it(From web FE) - * 2> if you want to construct it by yourself, make object by JSONObject (Like Map) + * 1> do not need to modify it by your self, you only put the json string to Map to it(From web FE) + * 2> if you want to construct it by yourself, make object by Map * * @param videoEditCreateRequest * @return A response of job create result */ public VideoEditCreateResponse createVideoEdit(VideoEditCreateRequest videoEditCreateRequest) { - InternalRequest request = this.createEditRequest(videoEditCreateRequest, HttpMethodName.POST, VIDEO_EDIT, + InternalRequest request = this.createRequest(videoEditCreateRequest, HttpMethodName.POST, VIDEO_EDIT, VIDEO_EDIT_CREATE); return invokeHttpClient(request, VideoEditCreateResponse.class); } @@ -959,7 +905,7 @@ public VideoEditCreateResponse createVideoEdit(VideoEditCreateRequest videoEditC */ public VideoEditPollingResponse pollingVideoEdit(long editId) { VideoEditPollingRequest videoEditPollingRequest = new VideoEditPollingRequest(editId); - InternalRequest request = this.createEditRequest(videoEditPollingRequest, HttpMethodName.GET, + InternalRequest request = this.createRequest(videoEditPollingRequest, HttpMethodName.GET, VIDEO_EDIT, VIDEO_EDIT_POLLING, String.format("%d", editId)); return invokeHttpClient(request, VideoEditPollingResponse.class); } diff --git a/src/main/java/com/baidubce/services/bvw/model/videoedit/VideoEditCreateRequest.java b/src/main/java/com/baidubce/services/bvw/model/videoedit/VideoEditCreateRequest.java index 98d4c75f..3fc21705 100644 --- a/src/main/java/com/baidubce/services/bvw/model/videoedit/VideoEditCreateRequest.java +++ b/src/main/java/com/baidubce/services/bvw/model/videoedit/VideoEditCreateRequest.java @@ -12,9 +12,11 @@ */ package com.baidubce.services.bvw.model.videoedit; +import com.baidubce.BceClientException; import com.baidubce.auth.BceCredentials; import com.baidubce.model.AbstractBceRequest; -import org.json.JSONObject; + +import java.util.Map; public class VideoEditCreateRequest extends AbstractBceRequest { private static final long DefaultTaskId = 1; @@ -48,32 +50,44 @@ public class VideoEditCreateRequest extends AbstractBceRequest { /** * request body */ - private JSONObject cmd; + private Map cmd; + + public String getString(Object object) { + if (object instanceof String) { + return (String) object; + } + throw new BceClientException("bucket/title not a string."); + } public VideoEditCreateRequest() { } - public VideoEditCreateRequest(JSONObject jsonObject) { - this.cmd = jsonObject.has(CmdKey) ? jsonObject.getJSONObject(CmdKey) : null; - this.bucket = jsonObject.has(BucketKey) ? jsonObject.getString(BucketKey) : null; - this.title = jsonObject.has(TitleKey) ? jsonObject.getString(TitleKey) : null; - this.taskId = jsonObject.has(TaskIdKey) ? jsonObject.getLong(TaskIdKey) : DefaultTaskId; + public VideoEditCreateRequest(Map jsonObject) { + this.cmd = jsonObject.containsKey(CmdKey) ? (Map) jsonObject.get(CmdKey) : null; + this.bucket = jsonObject.containsKey(BucketKey) ? getString(jsonObject.get(BucketKey)) : null; + this.title = jsonObject.containsKey(TitleKey) ? getString(jsonObject.get(TitleKey)) : null; + this.taskId = jsonObject.containsKey(TaskIdKey) ? + Long.parseLong(String.valueOf(jsonObject.get(TaskIdKey))) : DefaultTaskId; this.referer = RefererType.baidu.name(); } - public VideoEditCreateRequest(JSONObject jsonObject, RefererType refererType) { - this.cmd = jsonObject.has(CmdKey) ? jsonObject.getJSONObject(CmdKey) : null; - this.bucket = jsonObject.has(BucketKey) ? jsonObject.getString(BucketKey) : null; - this.title = jsonObject.has(TitleKey) ? jsonObject.getString(TitleKey) : null; - this.taskId = jsonObject.has(TaskIdKey) ? jsonObject.getLong(TaskIdKey) : DefaultTaskId; + public VideoEditCreateRequest( + Map jsonObject, RefererType refererType) { + this.cmd = jsonObject.containsKey(CmdKey) ? (Map) jsonObject.get(CmdKey) : null; + this.bucket = jsonObject.containsKey(BucketKey) ? getString(jsonObject.get(BucketKey)) : null; + this.title = jsonObject.containsKey(TitleKey) ? getString(jsonObject.get(TitleKey)) : null; + this.taskId = jsonObject.containsKey(TaskIdKey) ? + Long.parseLong(String.valueOf(jsonObject.get(TaskIdKey))) : DefaultTaskId; this.referer = refererType.name(); } - public VideoEditCreateRequest(JSONObject jsonObject, RefererType refererType, String notification) { - this.cmd = jsonObject.has(CmdKey) ? jsonObject.getJSONObject(CmdKey) : null; - this.bucket = jsonObject.has(BucketKey) ? jsonObject.getString(BucketKey) : null; - this.title = jsonObject.has(TitleKey) ? jsonObject.getString(TitleKey) : null; - this.taskId = jsonObject.has(TaskIdKey) ? jsonObject.getLong(TaskIdKey) : DefaultTaskId; + public VideoEditCreateRequest( + Map jsonObject, RefererType refererType, String notification) { + this.cmd = jsonObject.containsKey(CmdKey) ? (Map) jsonObject.get(CmdKey) : null; + this.bucket = jsonObject.containsKey(BucketKey) ? getString(jsonObject.get(BucketKey)) : null; + this.title = jsonObject.containsKey(TitleKey) ? getString(jsonObject.get(TitleKey)) : null; + this.taskId = jsonObject.containsKey(TaskIdKey) ? + Long.parseLong(String.valueOf(jsonObject.get(TaskIdKey))) : DefaultTaskId; this.referer = refererType.name(); this.notification = notification; } @@ -102,7 +116,7 @@ public String getNotification() { return notification; } - public JSONObject getCmd() { + public Map getCmd() { return cmd; } @@ -126,7 +140,7 @@ public void setNotification(String notification) { this.notification = notification; } - public void setCmd(JSONObject cmd) { + public void setCmd(Map cmd) { this.cmd = cmd; }