3333import javax .net .ssl .SSLContext ;
3434import javax .net .ssl .SSLException ;
3535import javax .ws .rs .core .Cookie ;
36+ import javax .ws .rs .core .HttpHeaders ;
3637import javax .ws .rs .core .MediaType ;
3738import javax .ws .rs .core .MultivaluedMap ;
3839import javax .ws .rs .core .StreamingOutput ;
@@ -1722,9 +1723,9 @@ private void updateMimetype(ContentDescriptor descriptor, String mimetype) {
17221723 }
17231724 }
17241725
1725- private String getHeaderMimetype (MultivaluedMap <String , String > headers ) {
1726- if (headers .containsKey ("Content-Type" )) {
1727- List <String > values = headers .get ("Content-Type" );
1726+ private String getHeaderMimetype (Map <String , List < String > > headers ) {
1727+ if (headers .containsKey (HttpHeaders . CONTENT_TYPE )) {
1728+ List <String > values = headers .get (HttpHeaders . CONTENT_TYPE );
17281729 if (values != null ) {
17291730 String contentType = values .get (0 );
17301731 String mimetype = contentType .contains (";" ) ? contentType
@@ -1748,8 +1749,8 @@ private void updateLength(ContentDescriptor descriptor, long length) {
17481749 }
17491750
17501751 private long getHeaderLength (MultivaluedMap <String , String > headers ) {
1751- if (headers .containsKey ("Content-Length" )) {
1752- List <String > values = headers .get ("Content-Length" );
1752+ if (headers .containsKey (HttpHeaders . CONTENT_LENGTH )) {
1753+ List <String > values = headers .get (HttpHeaders . CONTENT_LENGTH );
17531754 if (values != null ) {
17541755 return Long .valueOf (values .get (0 ));
17551756 }
@@ -3297,14 +3298,13 @@ public <R extends AbstractReadHandle, W extends AbstractWriteHandle> R postResou
32973298 @ Override
32983299 public <R extends AbstractReadHandle , W extends AbstractWriteHandle > R postResource (
32993300 RequestLogger reqlog , String path , RequestParameters params ,
3300- W [] input , Map <String , List >[] headers , R output ) throws ResourceNotFoundException ,
3301+ W [] input , Map <String , List < String > >[] headers , R output ) throws ResourceNotFoundException ,
33013302 ResourceNotResendableException , ForbiddenUserException ,
33023303 FailedRequestException {
3303- HandleImplementation outputBase = HandleAccessor .checkHandle (output ,
3304- "read" );
3304+ HandleImplementation outputBase = HandleAccessor .checkHandle (output , "read" );
33053305
3306- String outputMimetype = outputBase .getMimetype ();
3307- Class as = outputBase .receiveAs ();
3306+ String outputMimetype = outputBase != null ? outputBase .getMimetype () : null ;
3307+ Class as = outputBase != null ? outputBase .receiveAs () : null ;
33083308
33093309 ClientResponse response = null ;
33103310 ClientResponse .Status status = null ;
@@ -3371,45 +3371,49 @@ public <R extends AbstractReadHandle, W extends AbstractWriteHandle> R postResou
33713371 @ Override
33723372 public void postBulkDocuments (
33733373 RequestLogger reqlog , DocumentWriteSet writeSet ,
3374- ServerTransform transform , String transactionId )
3374+ ServerTransform transform , Format defaultFormat , String transactionId )
33753375 throws ForbiddenUserException , FailedRequestException
33763376 {
3377- postBulkDocuments (reqlog , writeSet , transform , transactionId , null );
3377+ postBulkDocuments (reqlog , writeSet , transform , transactionId , defaultFormat , null );
33783378 }
33793379
33803380 @ Override
33813381 public <R extends AbstractReadHandle > R postBulkDocuments (
33823382 RequestLogger reqlog , DocumentWriteSet writeSet ,
3383- ServerTransform transform , String transactionId , R output )
3383+ ServerTransform transform , String transactionId , Format defaultFormat , R output )
33843384 throws ForbiddenUserException , FailedRequestException
33853385 {
33863386 ArrayList <AbstractWriteHandle > writeHandles = new ArrayList <AbstractWriteHandle >();
3387- ArrayList <Map <String , List >> headerList = new ArrayList <Map <String , List >>();
3387+ ArrayList <Map <String , List < String >>> headerList = new ArrayList <Map <String , List < String > >>();
33883388 for ( DocumentWriteOperation write : writeSet ) {
33893389 HandleImplementation metadata =
33903390 HandleAccessor .checkHandle (write .getMetadata (), "write" );
33913391 HandleImplementation content =
33923392 HandleAccessor .checkHandle (write .getContent (), "write" );
3393- MultivaluedMap headers = new MultivaluedMapImpl ();
33943393 if ( metadata != null ) {
3395- headers .add ("Content-Type" , metadata .getMimetype ());
3394+ MultivaluedMap headers = new MultivaluedMapImpl ();
3395+ headers .add (HttpHeaders .CONTENT_TYPE , metadata .getMimetype ());
33963396 if ( write .getOperationType () == DocumentWriteOperation .OperationType .METADATA_DEFAULT ) {
3397- headers .add ("Content-Disposition" ,
3398- ContentDisposition .type ("inline" ).build ().toString ()
3399- );
3397+ headers .add ("Content-Disposition" , "inline; category=metadata" );
34003398 } else {
34013399 headers .add ("Content-Disposition" ,
34023400 ContentDisposition
34033401 .type ("attachment" )
34043402 .fileName (write .getUri ())
3405- .build ().toString ()
3403+ .build ().toString () +
3404+ "; category=metadata"
34063405 );
34073406 }
34083407 headerList .add (headers );
34093408 writeHandles .add (write .getMetadata ());
34103409 }
34113410 if ( content != null ) {
3412- headers .add ("Content-Type" , content .getMimetype ());
3411+ MultivaluedMap headers = new MultivaluedMapImpl ();
3412+ String mimeType = content .getMimetype ();
3413+ if ( mimeType == null && defaultFormat != null ) {
3414+ mimeType = defaultFormat .getDefaultMimetype ();
3415+ }
3416+ headers .add (HttpHeaders .CONTENT_TYPE , mimeType );
34133417 headers .add ("Content-Disposition" ,
34143418 ContentDisposition
34153419 .type ("attachment" )
@@ -3427,7 +3431,7 @@ public <R extends AbstractReadHandle> R postBulkDocuments(
34273431 "documents" ,
34283432 params ,
34293433 (AbstractWriteHandle []) writeHandles .toArray (new AbstractWriteHandle [0 ]),
3430- (Map <String , List >[]) headerList .toArray (new HashMap [0 ]),
3434+ (Map <String , List < String > >[]) headerList .toArray (new HashMap [0 ]),
34313435 output );
34323436 }
34333437
@@ -3929,7 +3933,7 @@ private <W extends AbstractWriteHandle> boolean addParts(
39293933
39303934 private <W extends AbstractWriteHandle > boolean addParts (
39313935 MultiPart multiPart , RequestLogger reqlog , String [] mimetypes ,
3932- W [] input , Map <String , List >[] headers ) {
3936+ W [] input , Map <String , List < String > >[] headers ) {
39333937 if (mimetypes != null && mimetypes .length != input .length )
39343938 throw new IllegalArgumentException (
39353939 "Mismatch between count of mimetypes and input" );
@@ -3944,13 +3948,19 @@ private <W extends AbstractWriteHandle> boolean addParts(
39443948 AbstractWriteHandle handle = input [i ];
39453949 HandleImplementation handleBase = HandleAccessor .checkHandle (
39463950 handle , "write" );
3947- Object value = handleBase .sendContent ();
3948- String inputMimetype = (mimetypes != null ) ? mimetypes [i ]
3949- : handleBase .getMimetype ();
39503951
39513952 if (!hasStreamingPart )
39523953 hasStreamingPart = !handleBase .isResendable ();
39533954
3955+ Object value = handleBase .sendContent ();
3956+
3957+ String inputMimetype = null ;
3958+ if ( mimetypes != null ) inputMimetype = mimetypes [i ];
3959+ if ( inputMimetype == null && headers != null ) {
3960+ inputMimetype = getHeaderMimetype (headers [i ]);
3961+ }
3962+ if ( inputMimetype == null ) inputMimetype = handleBase .getMimetype ();
3963+
39543964 String [] typeParts = (inputMimetype != null && inputMimetype
39553965 .contains ("/" )) ? inputMimetype .split ("/" , 2 ) : null ;
39563966
@@ -4737,4 +4747,5 @@ public InputStream match(String[] docIds, String[] candidateRules, ServerTransfo
47374747
47384748 return entity ;
47394749 }
4750+
47404751}
0 commit comments