Skip to content

Commit

Permalink
Add Spring support for legacy application/x-jsimpledb-transaction MIM…
Browse files Browse the repository at this point in the history
…E type.
  • Loading branch information
archiecobbs committed Oct 28, 2017
1 parent 3f31a25 commit e6f708a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,7 @@
Version Next

- Added Spring support for legacy application/x-jsimpledb-transaction MIME type

Version 4.0.1 Released October 23, 2017 Version 4.0.1 Released October 23, 2017


- Added support for import/export of POJO's (issue #24) - Added support for import/export of POJO's (issue #24)
Expand Down
Expand Up @@ -55,7 +55,18 @@ public class JObjectHttpMessageConverter extends AbstractHttpMessageConverter<JO
* @throws IllegalArgumentException if {@code jdb} is null * @throws IllegalArgumentException if {@code jdb} is null
*/ */
public JObjectHttpMessageConverter(Permazen jdb) { public JObjectHttpMessageConverter(Permazen jdb) {
super(SnapshotJTransactionHttpMessageConverter.MIME_TYPE); this(jdb, SnapshotJTransactionHttpMessageConverter.MIME_TYPE, SnapshotJTransactionHttpMessageConverter.LEGACY_MIME_TYPE);
}

/**
* Constructor.
*
* @param jdb {@link Permazen} instance
* @param supportedMediaTypes supported media types
* @throws IllegalArgumentException if {@code jdb} is null
*/
public JObjectHttpMessageConverter(Permazen jdb, MediaType... supportedMediaTypes) {
super(supportedMediaTypes);
Preconditions.checkArgument(jdb != null, "null jdb"); Preconditions.checkArgument(jdb != null, "null jdb");
this.jdb = jdb; this.jdb = jdb;
} }
Expand Down Expand Up @@ -98,7 +109,7 @@ protected boolean supports(Class<?> target) {
@Override @Override
protected MediaType getDefaultContentType(JObject jobj) { protected MediaType getDefaultContentType(JObject jobj) {
Preconditions.checkArgument(jobj != null, "null jobj"); Preconditions.checkArgument(jobj != null, "null jobj");
return new MediaType(SnapshotJTransactionHttpMessageConverter.MIME_TYPE, return new MediaType(this.getSupportedMediaTypes().get(0),
Collections.<String, String>singletonMap(ROOT_OBJECT_ID_PARAMETER_NAME, jobj.getObjId().toString())); Collections.<String, String>singletonMap(ROOT_OBJECT_ID_PARAMETER_NAME, jobj.getObjId().toString()));
} }


Expand All @@ -111,8 +122,6 @@ protected JObject readInternal(Class<? extends JObject> type, HttpInputMessage i


// Get the root object's ID // Get the root object's ID
final MediaType mediaType = input.getHeaders().getContentType(); final MediaType mediaType = input.getHeaders().getContentType();
if (!SnapshotJTransactionHttpMessageConverter.MIME_TYPE.includes(mediaType))
throw new HttpMessageNotReadableException("invalid Content-Type `" + mediaType + "'");
final String objId = mediaType.getParameter(ROOT_OBJECT_ID_PARAMETER_NAME); final String objId = mediaType.getParameter(ROOT_OBJECT_ID_PARAMETER_NAME);
if (objId == null) { if (objId == null) {
throw new HttpMessageNotReadableException("required parameter `" + ROOT_OBJECT_ID_PARAMETER_NAME throw new HttpMessageNotReadableException("required parameter `" + ROOT_OBJECT_ID_PARAMETER_NAME
Expand Down
Expand Up @@ -47,6 +47,8 @@ public class SnapshotJTransactionHttpMessageConverter extends AbstractHttpMessag
*/ */
public static final MediaType MIME_TYPE = new MediaType("application", "x-permazen-transaction"); public static final MediaType MIME_TYPE = new MediaType("application", "x-permazen-transaction");


static final MediaType LEGACY_MIME_TYPE = new MediaType("application", "x-jsimpledb-transaction");

private final Permazen jdb; private final Permazen jdb;


private Class<?>[] validationGroups; private Class<?>[] validationGroups;
Expand All @@ -57,7 +59,17 @@ public class SnapshotJTransactionHttpMessageConverter extends AbstractHttpMessag
* @param jdb {@link Permazen} instance defining the convertible types * @param jdb {@link Permazen} instance defining the convertible types
*/ */
public SnapshotJTransactionHttpMessageConverter(Permazen jdb) { public SnapshotJTransactionHttpMessageConverter(Permazen jdb) {
super(MIME_TYPE); this(jdb, MIME_TYPE, LEGACY_MIME_TYPE);
}

/**
* Constructor.
*
* @param jdb {@link Permazen} instance defining the convertible types
* @param supportedMediaTypes supported media types
*/
public SnapshotJTransactionHttpMessageConverter(Permazen jdb, MediaType... supportedMediaTypes) {
super(supportedMediaTypes);
Preconditions.checkArgument(jdb != null, "null jdb"); Preconditions.checkArgument(jdb != null, "null jdb");
this.jdb = jdb; this.jdb = jdb;
} }
Expand Down

0 comments on commit e6f708a

Please sign in to comment.