Fix java resful client after recent changes to mime types

This commit is contained in:
Jeremy Lakeman 2018-01-03 17:51:47 +10:30
parent 988250a576
commit dc0c0f86d8
7 changed files with 15 additions and 13 deletions

View File

@ -64,18 +64,20 @@ public abstract class AbstractJsonList<T, E extends Exception> {
httpConnection = httpConnector.newServalDHttpConnection(url);
httpConnection.connect();
if (!httpConnection.getContentType().equals("application/json"))
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + httpConnection.getContentType());
json = new JSONTokeniser(
(httpConnection.getResponseCode() >= 300) ?
httpConnection.getErrorStream() : httpConnection.getInputStream());
if ("application/json".equals(httpConnection.getContentType())){
json = new JSONTokeniser(
(httpConnection.getResponseCode() >= 300) ?
httpConnection.getErrorStream() : httpConnection.getInputStream());
}
if (httpConnection.getResponseCode()!=200){
handleResponseError();
return;
}
if (json == null)
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + httpConnection.getContentType());
try{
json.consume(JSONTokeniser.Token.START_OBJECT);
// allow for extra optional fields

View File

@ -39,6 +39,6 @@ public class BundleId extends SigningKey {
@Override
public String getMimeType() {
return null;
return "rhizome/bid";
}
}

View File

@ -44,6 +44,6 @@ public class BundleSecret extends AbstractId {
@Override
public String getMimeType() {
return "rhizome/bundle-secret";
return "rhizome/bundlesecret";
}
}

View File

@ -101,7 +101,7 @@ public class PostHelper {
}
public void writeField(String name, AbstractId value){
writeHeading(name, null, value.getMimeType(), "hex");
writeHeading(name, null, value.getMimeType()+"; format=hex", null);
writer.print(value.toHex());
}

View File

@ -33,7 +33,7 @@ public class SubscriberId extends AbstractId {
@Override
public String getMimeType() {
return "serval-mesh/sid";
return "serval/sid";
}
public SubscriberId(String hex) throws InvalidHexException {

View File

@ -231,7 +231,7 @@ public class RhizomeCommon
case NEW:
return null;
case SAME:
if (!conn.getContentType().equals("rhizome-manifest/text"))
if (!RhizomeManifest.MIME_TYPE.equals(conn.getContentType()))
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + conn.getContentType());
RhizomeManifest manifest = RhizomeManifest.fromTextFormat(status.input_stream);
BundleExtra extra = bundleExtraFromHeaders(conn);
@ -453,7 +453,7 @@ public class RhizomeCommon
decodeHeaderBundleStatus(status, conn);
checkBundleStatus(status);
if (!status.contentType.equals("rhizome-manifest/text"))
if (!RhizomeManifest.MIME_TYPE.equals(status.contentType))
throw new ServalDInterfaceException("unexpected HTTP Content-Type " + status.contentType + " from " + status.url);
RhizomeManifest returned_manifest = RhizomeManifest.fromTextFormat(status.input_stream);
BundleExtra extra = bundleExtraFromHeaders(conn);

View File

@ -43,7 +43,7 @@ import org.servalproject.servaldna.BundleKey;
public class RhizomeManifest {
public final static int TEXT_FORMAT_MAX_SIZE = 8192;
public static final String MIME_TYPE = "rhizome/manifest; format=\"text+binarysig\"";
public static final String MIME_TYPE = "rhizome/manifest; format=text+binarysig";
// Core fields used for routing and expiry (cannot be null)
public final BundleId id;