Search in sources :

Example 21 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class LiveChannelOperation method listLiveChannels.

/**
 * List live channels.
 */
public LiveChannelListing listLiveChannels(ListLiveChannelsRequest listLiveChannelRequest) throws OSSException, ClientException {
    assertParameterNotNull(listLiveChannelRequest, "listObjectsRequest");
    String bucketName = listLiveChannelRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    Map<String, String> parameters = new LinkedHashMap<String, String>();
    parameters.put(RequestParameters.SUBRESOURCE_LIVE, null);
    populateListLiveChannelsRequestParameters(listLiveChannelRequest, parameters);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(parameters).setOriginalRequest(listLiveChannelRequest).build();
    return doOperation(request, listLiveChannelsReponseParser, bucketName, null, true);
}
Also used : RequestMessage(com.aliyun.oss.common.comm.RequestMessage) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class LiveChannelOperation method generateRtmpUri.

public String generateRtmpUri(GenerateRtmpUriRequest request) throws OSSException, ClientException {
    assertParameterNotNull(request, "request");
    String bucketName = request.getBucketName();
    String liveChannelName = request.getLiveChannelName();
    String playlistName = request.getPlaylistName();
    Long expires = request.getExpires();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    assertParameterNotNull(liveChannelName, "liveChannelName");
    ensureLiveChannelNameValid(liveChannelName);
    assertParameterNotNull(playlistName, "playlistName");
    assertParameterNotNull(expires, "expires");
    Credentials currentCreds = this.credsProvider.getCredentials();
    String accessId = currentCreds.getAccessKeyId();
    String accessKey = currentCreds.getSecretAccessKey();
    boolean useSecurityToken = currentCreds.useSecurityToken();
    // Endpoint
    RequestMessage requestMessage = new RequestMessage(bucketName, liveChannelName);
    ClientConfiguration config = this.client.getClientConfiguration();
    requestMessage.setEndpoint(OSSUtils.determineFinalEndpoint(this.endpoint, bucketName, config));
    // Headers
    requestMessage.addHeader(HttpHeaders.DATE, expires.toString());
    // Parameters
    requestMessage.addParameter(RequestParameters.PLAYLIST_NAME, playlistName);
    if (useSecurityToken) {
        requestMessage.addParameter(SECURITY_TOKEN, currentCreds.getSecurityToken());
    }
    // Signature
    String canonicalResource = "/" + bucketName + "/" + liveChannelName;
    String canonicalString = SignUtils.buildRtmpCanonicalString(canonicalResource, requestMessage, expires.toString());
    String signature = ServiceSignature.create().computeSignature(accessKey, canonicalString);
    // Build query string
    Map<String, String> params = new LinkedHashMap<String, String>();
    params.put(HttpHeaders.EXPIRES, expires.toString());
    params.put(OSS_ACCESS_KEY_ID, accessId);
    params.put(SIGNATURE, signature);
    params.putAll(requestMessage.getParameters());
    String queryString = HttpUtil.paramToQueryString(params, DEFAULT_CHARSET_NAME);
    // Compose rtmp request uri
    String uri = requestMessage.getEndpoint().toString();
    String livChan = RequestParameters.SUBRESOURCE_LIVE + "/" + liveChannelName;
    if (uri.startsWith(OSSConstants.PROTOCOL_HTTP)) {
        uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTP, OSSConstants.PROTOCOL_RTMP);
    } else if (uri.startsWith(OSSConstants.PROTOCOL_HTTPS)) {
        uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTPS, OSSConstants.PROTOCOL_RTMP);
    } else if (!uri.startsWith(OSSConstants.PROTOCOL_RTMP)) {
        uri = OSSConstants.PROTOCOL_RTMP + uri;
    }
    if (!uri.endsWith("/")) {
        uri += "/";
    }
    uri += livChan + "?" + queryString;
    return uri;
}
Also used : RequestMessage(com.aliyun.oss.common.comm.RequestMessage) Credentials(com.aliyun.oss.common.auth.Credentials) ClientConfiguration(com.aliyun.oss.ClientConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method setBucketStorageCapacity.

public void setBucketStorageCapacity(SetBucketStorageCapacityRequest setBucketStorageCapacityRequest) throws OSSException, ClientException {
    assertParameterNotNull(setBucketStorageCapacityRequest, "setBucketStorageCapacityRequest");
    assertParameterNotNull(setBucketStorageCapacityRequest.getUserQos(), "setBucketStorageCapacityRequest.userQos");
    String bucketName = setBucketStorageCapacityRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    UserQos userQos = setBucketStorageCapacityRequest.getUserQos();
    assertParameterNotNull(userQos.getStorageCapacity(), "StorageCapacity");
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_QOS, null);
    byte[] rawContent = setBucketQosRequestMarshaller.marshall(userQos);
    Map<String, String> headers = new HashMap<String, String>();
    addRequestRequiredHeaders(headers, rawContent);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params).setHeaders(headers).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).setOriginalRequest(setBucketStorageCapacityRequest).build();
    doOperation(request, emptyResponseParser, bucketName, null);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) UserQos(com.aliyun.oss.model.UserQos)

Example 24 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method deleteBucketWebsite.

/**
 * Delete bucket website.
 */
public void deleteBucketWebsite(GenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String bucketName = genericRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(SUBRESOURCE_WEBSITE, null);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.DELETE).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
    doOperation(request, emptyResponseParser, bucketName, null);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 25 with RequestMessage

use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.

the class OSSBucketOperation method getBucketStat.

public BucketStat getBucketStat(GenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String bucketName = genericRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(RequestParameters.SUBRESOURCE_STAT, null);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params).setOriginalRequest(genericRequest).build();
    return doOperation(request, getBucketStatResponseParser, bucketName, null, true);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Aggregations

RequestMessage (com.aliyun.oss.common.comm.RequestMessage)98 LinkedHashMap (java.util.LinkedHashMap)88 HashMap (java.util.HashMap)78 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ClientException (com.aliyun.oss.ClientException)9 ClientConfiguration (com.aliyun.oss.ClientConfiguration)6 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)6 InputStream (java.io.InputStream)6 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)5 IOUtils.newRepeatableInputStream (com.aliyun.oss.common.utils.IOUtils.newRepeatableInputStream)5 ProgressListener (com.aliyun.oss.event.ProgressListener)5 ArrayList (java.util.ArrayList)5 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)4 ProgressInputStream (com.aliyun.oss.event.ProgressInputStream)4 URI (java.net.URI)4 CheckedInputStream (java.util.zip.CheckedInputStream)4 ServiceException (com.aliyun.oss.ServiceException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Credentials (com.aliyun.oss.common.auth.Credentials)2