mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-14 22:26:44 +00:00
Rhizome Java API: insert journal is not implemented
Change the HTTP response code for unimplemented operations from 403 to 501
This commit is contained in:
parent
e35bf77938
commit
8842f32b19
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Serval Project Inc.
|
||||
*
|
||||
* This file is part of Serval Software (http://www.servalproject.org)
|
||||
*
|
||||
* Serval Software is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This source code is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this source code; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package org.servalproject.servaldna;
|
||||
|
||||
/**
|
||||
* Thrown when the Serval DNA interface is used to perform an operation that is not yet implemented,
|
||||
* but will be provided in future.
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
public class ServalDNotImplementedException extends ServalDInterfaceException
|
||||
{
|
||||
public ServalDNotImplementedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,7 @@ import org.servalproject.servaldna.BundleSecret;
|
||||
import org.servalproject.servaldna.ServalDHttpConnectionFactory;
|
||||
import org.servalproject.servaldna.ServalDInterfaceException;
|
||||
import org.servalproject.servaldna.ServalDFailureException;
|
||||
import org.servalproject.servaldna.ServalDNotImplementedException;
|
||||
|
||||
public class RhizomeCommon
|
||||
{
|
||||
@ -88,12 +89,15 @@ public class RhizomeCommon
|
||||
}
|
||||
if (!conn.getContentType().equals("application/json"))
|
||||
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + conn.getContentType());
|
||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
if (status.http_status_code >= 300) {
|
||||
JSONTokeniser json = new JSONTokeniser(new InputStreamReader(conn.getErrorStream(), "US-ASCII"));
|
||||
decodeRestfulStatus(status, json);
|
||||
return status;
|
||||
}
|
||||
throw new ServalDInterfaceException("unexpected HTTP response code: " + conn.getResponseCode());
|
||||
if (status.http_status_code == HttpURLConnection.HTTP_FORBIDDEN)
|
||||
return status;
|
||||
if (status.http_status_code == HttpURLConnection.HTTP_NOT_IMPLEMENTED)
|
||||
throw new ServalDNotImplementedException(status.http_status_message);
|
||||
throw new ServalDInterfaceException("unexpected HTTP response: " + status.http_status_code + " " + status.http_status_message);
|
||||
}
|
||||
|
||||
protected static ServalDInterfaceException unexpectedResponse(Status status)
|
||||
|
@ -28,6 +28,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.servalproject.servaldna.ServalDClient;
|
||||
import org.servalproject.servaldna.ServalDInterfaceException;
|
||||
import org.servalproject.servaldna.ServalDNotImplementedException;
|
||||
import org.servalproject.servaldna.ServerControl;
|
||||
import org.servalproject.servaldna.BundleId;
|
||||
import org.servalproject.servaldna.BundleSecret;
|
||||
@ -229,6 +230,9 @@ public class Rhizome {
|
||||
catch (RhizomeException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
catch (ServalDNotImplementedException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ static int insert_mime_part_end(struct http_request *hr)
|
||||
return 500;
|
||||
}
|
||||
if (r->manifest->is_journal)
|
||||
return http_request_rhizome_response(r, 403, "Insert not supported for journals", NULL);
|
||||
return http_request_rhizome_response(r, 501, "Insert not supported for journals", NULL);
|
||||
assert(r->manifest != NULL);
|
||||
}
|
||||
else if (r->u.insert.current_part == PART_PAYLOAD) {
|
||||
@ -892,10 +892,13 @@ static void render_manifest_headers(struct http_request *hr, strbuf sb)
|
||||
}
|
||||
rhizome_manifest *m = r->manifest;
|
||||
if (m) {
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Id: %s\r\n", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Version: %"PRIu64"\r\n", m->version);
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Filesize: %"PRIu64"\r\n", m->filesize);
|
||||
if (m->filesize != 0)
|
||||
if (m->has_id)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Id: %s\r\n", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
|
||||
if (m->version)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Version: %"PRIu64"\r\n", m->version);
|
||||
if (m->filesize != RHIZOME_SIZE_UNSET)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Filesize: %"PRIu64"\r\n", m->filesize);
|
||||
if (m->has_filehash)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Filehash: %s\r\n", alloca_tohex_rhizome_filehash_t(m->filehash));
|
||||
if (m->has_sender)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Sender: %s\r\n", alloca_tohex_sid_t(m->sender));
|
||||
@ -932,7 +935,9 @@ static void render_manifest_headers(struct http_request *hr, strbuf sb)
|
||||
rhizome_bytes_to_hex_upper(m->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Secret: %s\r\n", secret);
|
||||
}
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Rowid: %"PRIu64"\r\n", m->rowid);
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Inserttime: %"PRIu64"\r\n", m->inserttime);
|
||||
if (m->rowid)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Rowid: %"PRIu64"\r\n", m->rowid);
|
||||
if (m->inserttime)
|
||||
strbuf_sprintf(sb, "Serval-Rhizome-Bundle-Inserttime: %"PRIu64"\r\n", m->inserttime);
|
||||
}
|
||||
}
|
||||
|
@ -448,4 +448,19 @@ test_RhizomeInsertEmptyUpdate() {
|
||||
assert diff xempty.manifest empty.manifest
|
||||
}
|
||||
|
||||
doc_RhizomeInsertJournal="Java API insert Rhizome bundle does not support journals"
|
||||
setup_RhizomeInsertJournal() {
|
||||
setup
|
||||
echo 'File one' >file1
|
||||
echo 'tail=0' >file1.manifest
|
||||
}
|
||||
test_RhizomeInsertJournal() {
|
||||
executeJavaOk org.servalproject.test.Rhizome rhizome-insert '' file1.manifest file1 ifile1.manifest
|
||||
tfw_cat --stdout --stderr
|
||||
assertStdoutGrep ServalDNotImplementedException
|
||||
assertStdoutGrep --ignore-case "not supported.*journal"
|
||||
executeOk_servald rhizome list
|
||||
assert_rhizome_list
|
||||
}
|
||||
|
||||
runTests "$@"
|
||||
|
@ -800,8 +800,8 @@ test_RhizomeInsertJournal() {
|
||||
"http://$addr_localhost:$PORTA/restful/rhizome/insert"
|
||||
tfw_cat http.header http.body
|
||||
assertExitStatus == 0
|
||||
assertStdoutIs 403
|
||||
assertJq http.body 'contains({"http_status_code": 403})'
|
||||
assertStdoutIs 501
|
||||
assertJq http.body 'contains({"http_status_code": 501})'
|
||||
assertJqGrep --ignore-case http.body '.http_status_message' 'not supported.*journal'
|
||||
executeOk_servald rhizome list
|
||||
assert_rhizome_list
|
||||
|
Loading…
x
Reference in New Issue
Block a user