Skip to content

Commit

Permalink
Logging unexpected content type.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Dec 29, 2024
1 parent af43640 commit 8151174
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,23 @@ public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Ob
return session.getClient().execute(resource, new OcsUploadShareResponseHandler() {
@Override
public DescriptiveUrl handleEntity(final HttpEntity entity) throws IOException {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
// Additional request, because permissions are ignored in POST
final StringBuilder request = new StringBuilder(String.format("https://%s/ocs/v1.php/apps/files_sharing/api/v1/shares/%s?permissions=%d",
bookmark.getHostname(),
value.data.id,
SHARE_PERMISSIONS_CREATE
));
final HttpPut put = new HttpPut(request.toString());
put.setHeader("OCS-APIRequest", "true");
put.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_XML.getMimeType());
session.getClient().execute(put, new VoidResponseHandler());
if(isXml(entity)) {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
// Additional request, because permissions are ignored in POST
final StringBuilder request = new StringBuilder(String.format("https://%s/ocs/v1.php/apps/files_sharing/api/v1/shares/%s?permissions=%d",
bookmark.getHostname(),
value.data.id,
SHARE_PERMISSIONS_CREATE
));
final HttpPut put = new HttpPut(request.toString());
put.setHeader("OCS-APIRequest", "true");
put.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_XML.getMimeType());
session.getClient().execute(put, new VoidResponseHandler());
}
else {
log.warn("Ignore entity {}", entity);
}
return super.handleEntity(entity);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public OcsCapabilities handleEntity(final HttpEntity entity) throws IOException
}
}
}
else {
log.warn("Ignore entity {}", entity);
}
log.debug("Determined OCS capabilities {}", capabilities);
return capabilities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,30 @@
import ch.cyberduck.core.ocs.model.Share;

import org.apache.http.HttpEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public class OcsDownloadShareResponseHandler extends OcsResponseHandler<DescriptiveUrl> {
private static final Logger log = LogManager.getLogger(OcsDownloadShareResponseHandler.class);

@Override
public DescriptiveUrl handleEntity(final HttpEntity entity) throws IOException {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
if(null != value.data) {
if(null != value.data.url) {
return new DescriptiveUrl(value.data.url, DescriptiveUrl.Type.http);
if(isXml(entity)) {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
if(null != value.data) {
if(null != value.data.url) {
return new DescriptiveUrl(value.data.url, DescriptiveUrl.Type.http);
}
}
}
else {
log.warn("Ignore entity {}", entity);
}
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public R handleResponse(final HttpResponse response) throws IOException {
log.warn("Failure parsing status code in response {}", error);
}
}
else {
log.warn("Ignore entity {}", response.getEntity());
}
}
return super.handleResponse(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import ch.cyberduck.core.features.Share;

import org.apache.http.HttpEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -27,22 +29,28 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public class OcsShareeResponseHandler extends OcsResponseHandler<Set<Share.Sharee>> {
private static final Logger log = LogManager.getLogger(OcsShareeResponseHandler.class);

@Override
public Set<Share.Sharee> handleEntity(final HttpEntity entity) throws IOException {
final XmlMapper mapper = new XmlMapper();
final ch.cyberduck.core.ocs.model.Share value = mapper.readValue(entity.getContent(), ch.cyberduck.core.ocs.model.Share.class);
if(value.data != null) {
if(value.data.users != null) {
final Set<Share.Sharee> sharees = new HashSet<>();
for(ch.cyberduck.core.ocs.model.Share.user user : value.data.users) {
final String id = user.value.shareWith;
final String label = String.format("%s (%s)", user.label, user.shareWithDisplayNameUnique);
sharees.add(new Share.Sharee(id, label));
if(isXml(entity)) {
final XmlMapper mapper = new XmlMapper();
final ch.cyberduck.core.ocs.model.Share value = mapper.readValue(entity.getContent(), ch.cyberduck.core.ocs.model.Share.class);
if(value.data != null) {
if(value.data.users != null) {
final Set<Share.Sharee> sharees = new HashSet<>();
for(ch.cyberduck.core.ocs.model.Share.user user : value.data.users) {
final String id = user.value.shareWith;
final String label = String.format("%s (%s)", user.label, user.shareWithDisplayNameUnique);
sharees.add(new Share.Sharee(id, label));
}
return sharees;
}
return sharees;
}
}
else {
log.warn("Ignore entity {}", entity);
}
return Collections.emptySet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,30 @@
import ch.cyberduck.core.ocs.model.Share;

import org.apache.http.HttpEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public class OcsUploadShareResponseHandler extends OcsResponseHandler<DescriptiveUrl> {
private static final Logger log = LogManager.getLogger(OcsUploadShareResponseHandler.class);

@Override
public DescriptiveUrl handleEntity(final HttpEntity entity) throws IOException {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
if(null != value.data) {
if(null != value.data.url) {
return new DescriptiveUrl(value.data.url, DescriptiveUrl.Type.http);
if(isXml(entity)) {
final XmlMapper mapper = new XmlMapper();
final Share value = mapper.readValue(entity.getContent(), Share.class);
if(null != value.data) {
if(null != value.data.url) {
return new DescriptiveUrl(value.data.url, DescriptiveUrl.Type.http);
}
}
}
else {
log.warn("Ignore entity {}", entity);
}
return DescriptiveUrl.EMPTY;
}
}

0 comments on commit 8151174

Please sign in to comment.