Troubleshooting
If a service exception occurs, locate the fault using the following method.
Connection Timeout
Generally, the service address (endpoint) is incorrect or the network is disconnected. In this case, check the service address, network status, and proxy settings.
Error Handling
When the Java SDK is used, if an error occurs on the server or SDK, the SDK returns the corresponding error information. Error information includes an error code and an error message.
- Error code: Find the error description and error type by referring to Error Codes.
- Error information: helps quickly locate and rectify faults.
You can add the logic for fixing errors during development.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// If an error message is returned:
if(BaseResponse.FAIL == createTrancodingResponse.getStatus())
{
// Add your own logic for fixing errors.
// For example, print error details.
System.out.println("ErrorCode ="+ rsp.getErrorCode());
System.out.println("ErrorMsg ="+ rsp.getErrorMsg());
}
// If a success message is returned:
else
{
// Return the result.
System.out.println(new Gson().toJson(createTrancodingResponse));
}
|
Example Code
If you need to fix SDK errors, compile code by referring to the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import com.google.gson.Gson;
import com.huawei.mpc.client.ClientConfig;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.transcoding.CreateTrancodingResponse;
import com.huawei.mpc.model.transcoding.CreateTranscodingRequest;
// Set the method for constructing MPC configuration items.
MpcConfig mpcconfig = new MpcConfig();
// Mandatory. Set the endpoint of MPC. For details, see section "Obtaining Key Parameters."
mpcConfig.setEndPoint(endPoint);
// Mandatory. Set the user's project ID. For details, see section "Obtaining Key Parameters."
mpcConfig.setProjectId(projectId);
// Mandatory. Set the SK. For details, see section "Obtaining Key Parameters."
mpcConfig.setSk(sk);
// Mandatory. Set the AK. For details, see section "Obtaining Key Parameters."
mpcConfig.setAk(ak);
/*if you need proxy*/
// Optional. Set the proxy if necessary.
/*
ClientConfig clientConfig = new ClientConfig();
// Set the IP address of the proxy server.
clientConfig.setProxyHost(proxyHost);
// Set the port number of the proxy server.
clientConfig.setProxyPort(Integer.parseInt(proxyPort));
// Set the username for accessing the proxy server.
clientConfig.setProxyUserName(proxyUserName);
// Set the password for accessing the proxy server.
clientConfig.setProxyPassword(proxyPassword);
*/
// MPC construction method
MpcClient mpcClient = new MpcClient(mpcconfig);
/*
* proxy provided
// MPC construction method. If a proxy needs to be configured, use this construction method.
* MpcClient mpcClient=new MpcClient(mpcconfig, clientConfig);
*/
// Set request parameters.
CreateTranscodingRequest createTranscodingRequest = new CreateTranscodingRequest();
// Set the storage location of an input file.
CreateTranscodingRequest.ObsObjInfo input = new CreateTranscodingRequest.ObsObjInfo();
// Set the OBS bucket name.
input.setBucket("OBS bucket name");
// Set the region where the input OBS bucket is deployed.
input.setLocation("cn-north-4");
// Set the input file path.
input.setObject("Path");
createTranscodingRequest.setInput(input);
// Set the location of an output file.
CreateTranscodingRequest.ObsObjInfo output = new CreateTranscodingRequest.ObsObjInfo();
// Set the OBS bucket name.
output.setBucket("OBS bucket name");
// Set the region where the output OBS bucket is deployed.
output.setLocation("cn-north-4");
// Set the output file path.
output.setObject("Path");
createTranscodingRequest.setOutput(output);
/*
* Transcoding template ID, aln array, each transcoding output corresponds to a transcoding configuration template ID example:trans_template_id : [203,212,210]
*/
// Template IDs
int[] transTempIds = {203, 212, 210};
// Set the transcoding template ID.
createTranscodingRequest.setThumb_template_id(transTempIds);
// Send a transcoding request.
CreateTrancodingResponse createTrancodingResponse=mpcClient.createTranscodingTask(createTranscodingRequest);
// If an error message is returned:
if(BaseResponse.FAIL == createTrancodingResponse.getStatus())
{
// Add your own logic for fixing errors.
// For example, print error details.
System.out.println("ErrorCode ="+ rsp.getErrorCode());
System.out.println("ErrorMsg ="+ rsp.getErrorMsg());
}
// If a success message is returned:
else
{
// Return the result.
System.out.println(new Gson().toJson(createTrancodingResponse));
}
|
Last Article: Deleting a Watermark Template
Next Article: Mappings Between MPC SDK & APIs
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.