com.qcloud.cos.internal.COSXmlResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cos_api Show documentation
Show all versions of cos_api Show documentation
qcloud cos sdk for inner tencentyun
The newest version!
package com.qcloud.cos.internal;
import java.io.InputStream;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qcloud.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());
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;
}
}