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 = httpConnector.newServalDHttpConnection(url);
httpConnection.connect(); httpConnection.connect();
if (!httpConnection.getContentType().equals("application/json")) if ("application/json".equals(httpConnection.getContentType())){
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + httpConnection.getContentType());
json = new JSONTokeniser( json = new JSONTokeniser(
(httpConnection.getResponseCode() >= 300) ? (httpConnection.getResponseCode() >= 300) ?
httpConnection.getErrorStream() : httpConnection.getInputStream()); httpConnection.getErrorStream() : httpConnection.getInputStream());
}
if (httpConnection.getResponseCode()!=200){ if (httpConnection.getResponseCode()!=200){
handleResponseError(); handleResponseError();
return; return;
} }
if (json == null)
throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + httpConnection.getContentType());
try{ try{
json.consume(JSONTokeniser.Token.START_OBJECT); json.consume(JSONTokeniser.Token.START_OBJECT);
// allow for extra optional fields // allow for extra optional fields

View File

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

View File

@ -44,6 +44,6 @@ public class BundleSecret extends AbstractId {
@Override @Override
public String getMimeType() { 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){ 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()); writer.print(value.toHex());
} }

View File

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

View File

@ -231,7 +231,7 @@ public class RhizomeCommon
case NEW: case NEW:
return null; return null;
case SAME: 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()); throw new ServalDInterfaceException("unexpected HTTP Content-Type: " + conn.getContentType());
RhizomeManifest manifest = RhizomeManifest.fromTextFormat(status.input_stream); RhizomeManifest manifest = RhizomeManifest.fromTextFormat(status.input_stream);
BundleExtra extra = bundleExtraFromHeaders(conn); BundleExtra extra = bundleExtraFromHeaders(conn);
@ -453,7 +453,7 @@ public class RhizomeCommon
decodeHeaderBundleStatus(status, conn); decodeHeaderBundleStatus(status, conn);
checkBundleStatus(status); 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); throw new ServalDInterfaceException("unexpected HTTP Content-Type " + status.contentType + " from " + status.url);
RhizomeManifest returned_manifest = RhizomeManifest.fromTextFormat(status.input_stream); RhizomeManifest returned_manifest = RhizomeManifest.fromTextFormat(status.input_stream);
BundleExtra extra = bundleExtraFromHeaders(conn); BundleExtra extra = bundleExtraFromHeaders(conn);

View File

@ -43,7 +43,7 @@ import org.servalproject.servaldna.BundleKey;
public class RhizomeManifest { public class RhizomeManifest {
public final static int TEXT_FORMAT_MAX_SIZE = 8192; 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) // Core fields used for routing and expiry (cannot be null)
public final BundleId id; public final BundleId id;