mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-06-21 00:05:13 +00:00
Fix java resful client after recent changes to mime types
This commit is contained in:
@ -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(
|
||||||
|
(httpConnection.getResponseCode() >= 300) ?
|
||||||
json = new JSONTokeniser(
|
httpConnection.getErrorStream() : httpConnection.getInputStream());
|
||||||
(httpConnection.getResponseCode() >= 300) ?
|
}
|
||||||
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
|
||||||
|
@ -39,6 +39,6 @@ public class BundleId extends SigningKey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMimeType() {
|
public String getMimeType() {
|
||||||
return null;
|
return "rhizome/bid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,6 @@ public class BundleSecret extends AbstractId {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMimeType() {
|
public String getMimeType() {
|
||||||
return "rhizome/bundle-secret";
|
return "rhizome/bundlesecret";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user