com.branch.cos.internal.COSXmlResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of branch_cos_api Show documentation
Show all versions of branch_cos_api Show documentation
branch java sdk for qcloud cos
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* According to cos feature, we modify some class,comment, field name, etc.
*/
package com.branch.cos.internal;
import java.io.InputStream;
import java.util.Map;
import com.branch.cos.model.BucketDomainConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.branch.cos.http.CosHttpResponse;
public class COSXmlResponseHandler extends AbstractCosResponseHandler {
/** The SAX unmarshaller to use when handling the response from COS */
private Unmarshaller responseUnmarshaller;
/** Shared logger for profiling information */
private static final Logger log = LoggerFactory.getLogger(COSXmlResponseHandler.class);
/** Response headers from the processed response */
private Map responseHeaders;
/**
* Constructs a new COS response handler that will use the specified SAX
* unmarshaller to turn the response into an object.
*
* @param responseUnmarshaller
* The SAX unmarshaller to use on the response from COS.
*/
public COSXmlResponseHandler(Unmarshaller responseUnmarshaller) {
this.responseUnmarshaller = responseUnmarshaller;
}
@Override
public CosServiceResponse handle(CosHttpResponse response) throws Exception {
CosServiceResponse cosResponse = parseResponseMetadata(response);
responseHeaders = response.getHeaders();
if (responseUnmarshaller != null) {
log.trace("Beginning to parse service response XML");
T result = responseUnmarshaller.unmarshall(response.getContent());
if(result instanceof BucketDomainConfiguration &&
responseHeaders.containsKey("x-cos-domain-txt-verification")) {
((BucketDomainConfiguration) result).setDomainTxtVerification(
responseHeaders.get("x-cos-domain-txt-verification"));
}
log.trace("Done parsing service response XML");
cosResponse.setResult(result);
}
return cosResponse;
}
/**
* Returns the headers from the processed response. Will return null until a
* response has been handled.
*
* @return the headers from the processed response.
*/
public Map getResponseHeaders() {
return responseHeaders;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy