@@ -74,6 +74,7 @@ public class DefaultHttpBinding implements HttpBinding {
74
74
private boolean useReaderForPayload ;
75
75
private boolean eagerCheckContentAvailable ;
76
76
private boolean transferException ;
77
+ private boolean allowJavaSerializedObject ;
77
78
private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy ();
78
79
79
80
public DefaultHttpBinding () {
@@ -88,6 +89,7 @@ public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
88
89
public DefaultHttpBinding (HttpCommonEndpoint endpoint ) {
89
90
this .headerFilterStrategy = endpoint .getHeaderFilterStrategy ();
90
91
this .transferException = endpoint .isTransferException ();
92
+ this .allowJavaSerializedObject = endpoint .getComponent ().isAllowJavaSerializedObject ();
91
93
}
92
94
93
95
public void readRequest (HttpServletRequest request , HttpMessage message ) {
@@ -151,14 +153,18 @@ public void readRequest(HttpServletRequest request, HttpMessage message) {
151
153
152
154
// if content type is serialized java object, then de-serialize it to a Java object
153
155
if (request .getContentType () != null && HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT .equals (request .getContentType ())) {
154
- try {
155
- InputStream is = message .getExchange ().getContext ().getTypeConverter ().mandatoryConvertTo (InputStream .class , body );
156
- Object object = HttpHelper .deserializeJavaObjectFromStream (is , message .getExchange ().getContext ());
157
- if (object != null ) {
158
- message .setBody (object );
156
+ if (allowJavaSerializedObject || isTransferException ()) {
157
+ try {
158
+ InputStream is = message .getExchange ().getContext ().getTypeConverter ().mandatoryConvertTo (InputStream .class , body );
159
+ Object object = HttpHelper .deserializeJavaObjectFromStream (is , message .getExchange ().getContext ());
160
+ if (object != null ) {
161
+ message .setBody (object );
162
+ }
163
+ } catch (Exception e ) {
164
+ throw new RuntimeCamelException ("Cannot deserialize body to Java object" , e );
159
165
}
160
- } catch ( Exception e ) {
161
- throw new RuntimeCamelException ("Cannot deserialize body to Java object" , e );
166
+ } else {
167
+ throw new RuntimeCamelException ("Content-type " + HttpConstants . CONTENT_TYPE_JAVA_SERIALIZED_OBJECT + " is not allowed" );
162
168
}
163
169
}
164
170
@@ -358,13 +364,17 @@ protected void doWriteDirectResponse(Message message, HttpServletResponse respon
358
364
// if content type is serialized Java object, then serialize and write it to the response
359
365
String contentType = message .getHeader (Exchange .CONTENT_TYPE , String .class );
360
366
if (contentType != null && HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT .equals (contentType )) {
361
- try {
362
- Object object = message .getMandatoryBody (Serializable .class );
363
- HttpHelper .writeObjectToServletResponse (response , object );
364
- // object is written so return
365
- return ;
366
- } catch (InvalidPayloadException e ) {
367
- throw new IOException (e );
367
+ if (allowJavaSerializedObject || isTransferException ()) {
368
+ try {
369
+ Object object = message .getMandatoryBody (Serializable .class );
370
+ HttpHelper .writeObjectToServletResponse (response , object );
371
+ // object is written so return
372
+ return ;
373
+ } catch (InvalidPayloadException e ) {
374
+ throw new IOException (e );
375
+ }
376
+ } else {
377
+ throw new RuntimeCamelException ("Content-type " + HttpConstants .CONTENT_TYPE_JAVA_SERIALIZED_OBJECT + " is not allowed" );
368
378
}
369
379
}
370
380
0 commit comments