Skip to content

Commit d35bec0

Browse files
Better fix for AXIS2-5971 AxisServlet.processURLRequest uses content-type header instead of accept
1 parent 468c178 commit d35bec0

File tree

1 file changed

+17
-4
lines changed
  • modules/transport/http/src/main/java/org/apache/axis2/transport/http

1 file changed

+17
-4
lines changed

modules/transport/http/src/main/java/org/apache/axis2/transport/http/AxisServlet.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,26 @@ public void processURLRequest() throws IOException, ServletException {
900900
try {
901901
// AXIS2-5971, content-type is not present on some
902902
// types of REST requests that have no body and in
903-
// those cases use the 'accept' header if defined
903+
// those cases use the 'accept' header if defined.
904+
// On a null content-type it will default to application/x-www-form-urlencoded.
904905
final String accept = request.getHeader(HttpHeaders.ACCEPT);
905906
final String contentType = request.getContentType();
906-
if (contentType == null && accept != null) {
907-
RESTUtil.processURLRequest(messageContext, response.getOutputStream(), accept);
908-
} else {
907+
if (contentType != null) {
909908
RESTUtil.processURLRequest(messageContext, response.getOutputStream(), contentType);
909+
} else if (accept != null && !accept.isEmpty()) {
910+
// TODO: not easy to parse without adding code or libs, and needs to match
911+
// a MessageFormatter we support. Curl by default sends */* . Example from FireFox:
912+
// text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
913+
if (accept.indexOf(HTTPConstants.MEDIA_TYPE_APPLICATION_XML) != -1) {
914+
log.debug("processURLRequest() will default to this content type found as one of the values in accept header: " + HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
915+
RESTUtil.processURLRequest(messageContext, response.getOutputStream(), HTTPConstants.MEDIA_TYPE_APPLICATION_XML);
916+
} else {
917+
log.debug("AxisServlet.processURLRequest() found null contentType with an Accept header: "+accept+" , that we could not match a content-type, will use default contentType: application/x-www-form-urlencoded");
918+
RESTUtil.processURLRequest(messageContext, response.getOutputStream(), null);
919+
}
920+
} else {
921+
log.debug("AxisServlet.processURLRequest() found null contentType and null Accept header, will use default contentType: application/x-www-form-urlencoded");
922+
RESTUtil.processURLRequest(messageContext, response.getOutputStream(), null);
910923
}
911924
this.checkResponseWritten();
912925
} catch (AxisFault e) {

0 commit comments

Comments
 (0)