33
33
import javax .net .ssl .SSLContext ;
34
34
import javax .net .ssl .SSLException ;
35
35
import javax .ws .rs .core .Cookie ;
36
+ import javax .ws .rs .core .HttpHeaders ;
36
37
import javax .ws .rs .core .MediaType ;
37
38
import javax .ws .rs .core .MultivaluedMap ;
38
39
import javax .ws .rs .core .StreamingOutput ;
@@ -1722,9 +1723,9 @@ private void updateMimetype(ContentDescriptor descriptor, String mimetype) {
1722
1723
}
1723
1724
}
1724
1725
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 );
1728
1729
if (values != null ) {
1729
1730
String contentType = values .get (0 );
1730
1731
String mimetype = contentType .contains (";" ) ? contentType
@@ -1748,8 +1749,8 @@ private void updateLength(ContentDescriptor descriptor, long length) {
1748
1749
}
1749
1750
1750
1751
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 );
1753
1754
if (values != null ) {
1754
1755
return Long .valueOf (values .get (0 ));
1755
1756
}
@@ -3297,14 +3298,13 @@ public <R extends AbstractReadHandle, W extends AbstractWriteHandle> R postResou
3297
3298
@ Override
3298
3299
public <R extends AbstractReadHandle , W extends AbstractWriteHandle > R postResource (
3299
3300
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 ,
3301
3302
ResourceNotResendableException , ForbiddenUserException ,
3302
3303
FailedRequestException {
3303
- HandleImplementation outputBase = HandleAccessor .checkHandle (output ,
3304
- "read" );
3304
+ HandleImplementation outputBase = HandleAccessor .checkHandle (output , "read" );
3305
3305
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 ;
3308
3308
3309
3309
ClientResponse response = null ;
3310
3310
ClientResponse .Status status = null ;
@@ -3371,45 +3371,49 @@ public <R extends AbstractReadHandle, W extends AbstractWriteHandle> R postResou
3371
3371
@ Override
3372
3372
public void postBulkDocuments (
3373
3373
RequestLogger reqlog , DocumentWriteSet writeSet ,
3374
- ServerTransform transform , String transactionId )
3374
+ ServerTransform transform , Format defaultFormat , String transactionId )
3375
3375
throws ForbiddenUserException , FailedRequestException
3376
3376
{
3377
- postBulkDocuments (reqlog , writeSet , transform , transactionId , null );
3377
+ postBulkDocuments (reqlog , writeSet , transform , transactionId , defaultFormat , null );
3378
3378
}
3379
3379
3380
3380
@ Override
3381
3381
public <R extends AbstractReadHandle > R postBulkDocuments (
3382
3382
RequestLogger reqlog , DocumentWriteSet writeSet ,
3383
- ServerTransform transform , String transactionId , R output )
3383
+ ServerTransform transform , String transactionId , Format defaultFormat , R output )
3384
3384
throws ForbiddenUserException , FailedRequestException
3385
3385
{
3386
3386
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 > >>();
3388
3388
for ( DocumentWriteOperation write : writeSet ) {
3389
3389
HandleImplementation metadata =
3390
3390
HandleAccessor .checkHandle (write .getMetadata (), "write" );
3391
3391
HandleImplementation content =
3392
3392
HandleAccessor .checkHandle (write .getContent (), "write" );
3393
- MultivaluedMap headers = new MultivaluedMapImpl ();
3394
3393
if ( metadata != null ) {
3395
- headers .add ("Content-Type" , metadata .getMimetype ());
3394
+ MultivaluedMap headers = new MultivaluedMapImpl ();
3395
+ headers .add (HttpHeaders .CONTENT_TYPE , metadata .getMimetype ());
3396
3396
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" );
3400
3398
} else {
3401
3399
headers .add ("Content-Disposition" ,
3402
3400
ContentDisposition
3403
3401
.type ("attachment" )
3404
3402
.fileName (write .getUri ())
3405
- .build ().toString ()
3403
+ .build ().toString () +
3404
+ "; category=metadata"
3406
3405
);
3407
3406
}
3408
3407
headerList .add (headers );
3409
3408
writeHandles .add (write .getMetadata ());
3410
3409
}
3411
3410
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 );
3413
3417
headers .add ("Content-Disposition" ,
3414
3418
ContentDisposition
3415
3419
.type ("attachment" )
@@ -3427,7 +3431,7 @@ public <R extends AbstractReadHandle> R postBulkDocuments(
3427
3431
"documents" ,
3428
3432
params ,
3429
3433
(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 ]),
3431
3435
output );
3432
3436
}
3433
3437
@@ -3929,7 +3933,7 @@ private <W extends AbstractWriteHandle> boolean addParts(
3929
3933
3930
3934
private <W extends AbstractWriteHandle > boolean addParts (
3931
3935
MultiPart multiPart , RequestLogger reqlog , String [] mimetypes ,
3932
- W [] input , Map <String , List >[] headers ) {
3936
+ W [] input , Map <String , List < String > >[] headers ) {
3933
3937
if (mimetypes != null && mimetypes .length != input .length )
3934
3938
throw new IllegalArgumentException (
3935
3939
"Mismatch between count of mimetypes and input" );
@@ -3944,13 +3948,19 @@ private <W extends AbstractWriteHandle> boolean addParts(
3944
3948
AbstractWriteHandle handle = input [i ];
3945
3949
HandleImplementation handleBase = HandleAccessor .checkHandle (
3946
3950
handle , "write" );
3947
- Object value = handleBase .sendContent ();
3948
- String inputMimetype = (mimetypes != null ) ? mimetypes [i ]
3949
- : handleBase .getMimetype ();
3950
3951
3951
3952
if (!hasStreamingPart )
3952
3953
hasStreamingPart = !handleBase .isResendable ();
3953
3954
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
+
3954
3964
String [] typeParts = (inputMimetype != null && inputMimetype
3955
3965
.contains ("/" )) ? inputMimetype .split ("/" , 2 ) : null ;
3956
3966
@@ -4737,4 +4747,5 @@ public InputStream match(String[] docIds, String[] candidateRules, ServerTransfo
4737
4747
4738
4748
return entity ;
4739
4749
}
4750
+
4740
4751
}
0 commit comments