OLINGO-1316: allowing multipart/mixed as contentType for batch requests

This commit is contained in:
Ramesh Reddy 2018-11-20 12:05:54 -06:00
parent fd481c11d8
commit df332b3384
3 changed files with 49 additions and 8 deletions

View File

@ -51,6 +51,7 @@ import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
import org.apache.olingo.server.api.uri.UriResourceRef;
import org.apache.olingo.server.api.uri.UriResourceSingleton;
import org.apache.olingo.server.api.uri.UriResourceValue;
import org.apache.olingo.server.api.uri.queryoption.FormatOption;
import org.apache.olingo.server.core.requests.ActionRequest;
import org.apache.olingo.server.core.requests.BatchRequest;
import org.apache.olingo.server.core.requests.DataRequest;
@ -79,11 +80,9 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
}
public void execute(ODataRequest odRequest, ODataResponse odResponse) {
ContentType contentType = ContentType.JSON;
FormatOption formatOption = null;
ODataException oDataException = null;
try {
contentType = ContentNegotiator.doContentNegotiation(null,
odRequest, this.customContentSupport, RepresentationType.ERROR);
String path = odRequest.getRawODataPath();
String query = odRequest.getRawQueryPath();
if(path.indexOf("$entity") != -1) {
@ -92,16 +91,24 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
.parseUri(path, query, null, odRequest.getRawBaseUri());
contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
odRequest, this.customContentSupport, RepresentationType.ERROR);
formatOption = uriInfo.getFormatOption();
internalExecute(uriInfo, odRequest, odResponse);
}
return;
} catch(ODataLibraryException e) {
handleException(e, contentType, odRequest, odResponse);
oDataException = e;
} catch(ODataApplicationException e) {
handleException(e, contentType, odRequest, odResponse);
oDataException = e;
}
ContentType contentType = ContentType.JSON;
try {
contentType = ContentNegotiator.doContentNegotiation(formatOption,
odRequest, this.customContentSupport, RepresentationType.ERROR);
} catch (ContentNegotiatorException e) {
// ignore, default to JSON
}
handleException(oDataException, contentType, odRequest, odResponse);
}
protected void handleException(ODataException e, ContentType contentType,

View File

@ -63,6 +63,7 @@ public class TripPinServiceTest {
private static String baseURL;
private static DefaultHttpClient http = new DefaultHttpClient();
private static final int TOMCAT_PORT = 9900;
private static final String CRLF = "\r\n";
@BeforeClass
public static void beforeTest() throws Exception {
@ -808,4 +809,29 @@ public class TripPinServiceTest {
HttpResponse response = httpSend(request, 412);
EntityUtils.consumeQuietly(response.getEntity());
}
@Test
public void batchAccept() throws Exception {
final String batchtUrl = baseURL + "/$batch";
final String content = ""
+ "--batch_12345" + CRLF
+ "Content-Type: application/http" + CRLF
+ "Content-Transfer-Encoding: binary" + CRLF
+ CRLF
+ "GET Airlines('FM') HTTP/1.1" + CRLF
+ CRLF
+ CRLF
+ "--batch_12345--";
HttpPost request = new HttpPost(batchtUrl);
StringEntity stringEntity = new StringEntity(content);
stringEntity.setContentType("multipart/mixed;boundary=batch_12345");
request.setEntity(stringEntity);
// multipart/mixed should work as an Accept value
request.setHeader("Accept", "multipart/mixed");
HttpResponse response = httpSend(request, 202);
EntityUtils.consumeQuietly(response.getEntity());
}
}

View File

@ -55,6 +55,7 @@ public class ContentNegotiatorTest {
static final private String ACCEPT_CASE_WILDCARD1 = "*/*";
static final private String ACCEPT_CASE_WILDCARD2 = "application/*";
static final private String ACCEPT_CASE_JSON_IEEE754 = ACCEPT_CASE_JSON + ";IEEE754Compatible=true";
static final private String ACCEPT_CASE_MULTIPART_MIXED = ContentType.MULTIPART_MIXED.toContentTypeString();
//@formatter:off (Eclipse formatter)
//CHECKSTYLE:OFF (Maven checkstyle)
@ -335,4 +336,11 @@ public class ContentNegotiatorTest {
assertTrue(ContentNegotiator.isSupported(ContentType.create("a/b"),
createCustomContentTypeSupport("a/b"), RepresentationType.BINARY));
}
@Test
public void checBatchkSupport() throws Exception {
testContentNegotiation(new String[] { ACCEPT_CASE_MULTIPART_MIXED, null, ACCEPT_CASE_MULTIPART_MIXED, null },
RepresentationType.BATCH);
}
}