32
32
import org .apache .camel .CamelExchangeException ;
33
33
import org .apache .camel .Exchange ;
34
34
import org .apache .camel .Message ;
35
+ import org .apache .camel .RuntimeCamelException ;
35
36
import org .apache .camel .component .file .GenericFile ;
36
37
import org .apache .camel .converter .stream .CachedOutputStream ;
37
38
import org .apache .camel .http .common .HttpConstants ;
@@ -280,7 +281,7 @@ protected static Map<String, String> extractResponseHeaders(Header[] responseHea
280
281
* @return the response either as a stream, or as a deserialized java object
281
282
* @throws IOException can be thrown
282
283
*/
283
- protected static Object extractResponseBody (HttpMethod method , Exchange exchange , boolean ignoreResponseBody ) throws IOException , ClassNotFoundException {
284
+ protected Object extractResponseBody (HttpMethod method , Exchange exchange , boolean ignoreResponseBody ) throws IOException , ClassNotFoundException {
284
285
InputStream is = method .getResponseBodyAsStream ();
285
286
if (is == null ) {
286
287
return null ;
@@ -304,7 +305,13 @@ protected static Object extractResponseBody(HttpMethod method, Exchange exchange
304
305
305
306
// if content type is a serialized java object then de-serialize it back to a Java object
306
307
if (contentType != null && contentType .equals (HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT )) {
307
- return HttpHelper .deserializeJavaObjectFromStream (is , exchange .getContext ());
308
+ // only deserialize java if allowed
309
+ if (getEndpoint ().getComponent ().isAllowJavaSerializedObject () || getEndpoint ().isTransferException ()) {
310
+ return HttpHelper .deserializeJavaObjectFromStream (is , exchange .getContext ());
311
+ } else {
312
+ // empty response
313
+ return null ;
314
+ }
308
315
} else {
309
316
InputStream response = null ;
310
317
if (!ignoreResponseBody ) {
@@ -418,6 +425,9 @@ protected RequestEntity createRequestEntity(Exchange exchange) throws CamelExcha
418
425
String contentType = ExchangeHelper .getContentType (exchange );
419
426
420
427
if (contentType != null && HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT .equals (contentType )) {
428
+ if (!getEndpoint ().getComponent ().isAllowJavaSerializedObject ()) {
429
+ throw new CamelExchangeException ("Content-type " + HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT + " is not allowed" , exchange );
430
+ }
421
431
// serialized java object
422
432
Serializable obj = in .getMandatoryBody (Serializable .class );
423
433
// write object to output stream
0 commit comments