Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle text/xml response content type. #16722

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public ExtendedHttpRequestRetryHandler(final int retryCount) {
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
final Throwable cause = ExceptionUtils.getRootCause(exception);
if(cause instanceof RuntimeException) {
log.error("Cancel retry request with execution count {} for failure {}", executionCount, cause);
log.error("Cancel retry request with execution count {} for failure {}", executionCount, cause.toString());
return false;
}
final boolean retry = super.retryRequest(exception, executionCount, context);
if(retry) {
log.info("Retry request with failure {}", exception.getMessage());
log.info("Retry request with failure {}", exception.toString());
}
else {
log.warn("Cancel retry request with execution count {} for failure {}", executionCount, exception);
log.warn("Cancel retry request with execution count {} for failure {}", executionCount, exception.toString());
}
return retry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import ch.cyberduck.core.ocs.model.Capabilities;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -38,8 +36,7 @@ public OcsCapabilitiesResponseHandler(final OcsCapabilities capabilities) {

@Override
public OcsCapabilities handleEntity(final HttpEntity entity) throws IOException {
if(StringUtils.equals(ContentType.APPLICATION_XML.getMimeType(),
ContentType.parse(entity.getContentType().getValue()).getMimeType())) {
if(isXml(entity)) {
final XmlMapper mapper = new XmlMapper();
final Capabilities value = mapper.readValue(entity.getContent(), Capabilities.class);
if(value.data != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/

import ch.cyberduck.core.StringAppender;
import ch.cyberduck.core.nextcloud.NextcloudShareFeature;
import ch.cyberduck.core.ocs.model.Share;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpResponseException;
Expand All @@ -35,15 +35,14 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public abstract class OcsResponseHandler<R> extends AbstractResponseHandler<R> {
private static final Logger log = LogManager.getLogger(NextcloudShareFeature.class);
private static final Logger log = LogManager.getLogger(OcsResponseHandler.class);

@Override
public R handleResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
if(response.getEntity() != null) {
EntityUtils.updateEntity(response, new BufferedHttpEntity(response.getEntity()));
if(StringUtils.equals(ContentType.APPLICATION_XML.getMimeType(),
ContentType.parse(response.getEntity().getContentType().getValue()).getMimeType())) {
if(isXml(response.getEntity())) {
if(statusLine.getStatusCode() >= 300) {
final StringAppender message = new StringAppender();
message.append(statusLine.getReasonPhrase());
Expand All @@ -66,4 +65,11 @@ public R handleResponse(final HttpResponse response) throws IOException {
}
return super.handleResponse(response);
}

protected static boolean isXml(final HttpEntity response) {
return StringUtils.equals(ContentType.APPLICATION_XML.getMimeType(),
ContentType.parse(response.getContentType().getValue()).getMimeType())
|| StringUtils.equals(ContentType.TEXT_XML.getMimeType(),
ContentType.parse(response.getContentType().getValue()).getMimeType());
}
}
Loading