pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/apache/axis-axis2-java-core/commit/eb7db458e231106d4497ccf483dfa83a425cc5aa

AXIS2-6063 Add enableJSONOnly parameter to axis2.xml · apache/axis-axis2-java-core@eb7db45 · GitHub
Skip to content

Commit eb7db45

Browse files
AXIS2-6063 Add enableJSONOnly parameter to axis2.xml
1 parent 465b492 commit eb7db45

File tree

7 files changed

+42
-1
lines changed

7 files changed

+42
-1
lines changed

modules/kernel/conf/axis2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<parameter name="hotupdate">false</parameter>
2626
<parameter name="enableMTOM">false</parameter>
2727
<parameter name="enableSwA">false</parameter>
28+
<parameter name="enableJSONOnly">false</parameter>
2829

2930
<!--Uncomment if you want to enable file caching for attachments -->
3031
<!--parameter name="cacheAttachments">true</parameter>

modules/kernel/src/org/apache/axis2/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public class Constants extends org.apache.axis2.namespace.Constants {
333333

334334
public static interface Configuration {
335335
public static final String ENABLE_REST = "enableREST";
336+
public static final String ENABLE_JSON_ONLY = "enableJSONOnly";
336337
public static final String ENABLE_HTTP_CONTENT_NEGOTIATION = "httpContentNegotiation";
337338
public static final String ENABLE_REST_THROUGH_GET = "restThroughGet";
338339

modules/kernel/src/org/apache/axis2/kernel/http/HTTPConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class HTTPConstants {
3737
public static final String MEDIA_TYPE_APPLICATION_XML = "application/xml";
3838
public static final String MEDIA_TYPE_APPLICATION_SOAP_XML = "application/soap+xml";
3939
public static final String MEDIA_TYPE_APPLICATION_ECHO_XML = "application/echo+xml";
40+
public static final String MEDIA_TYPE_APPLICATION_JSON = "application/json";
4041

4142
/**
4243
* Field REQUEST_URI

modules/samples/json/resources/axis2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<parameter name="hotupdate">false</parameter>
2626
<parameter name="enableMTOM">false</parameter>
2727
<parameter name="enableSwA">false</parameter>
28+
<parameter name="enableJSONOnly">false</parameter>
2829

2930
<!--Uncomment if you want to enable file caching for attachments -->
3031
<!--parameter name="cacheAttachments">true</parameter>

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class AxisServlet extends HttpServlet {
105105
protected transient String contextRoot = null;
106106

107107
protected boolean disableREST = false;
108+
protected boolean enableJSONOnly = false;
108109
private static final String LIST_SERVICES_SUFFIX = "/services/listServices";
109110
private static final String LIST_FAULTY_SERVICES_SUFFIX = "/services/ListFaultyServices";
110111
private boolean closeReader = true;
@@ -153,7 +154,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
153154
MessageContext msgContext;
154155
OutputStream out = response.getOutputStream();
155156
String contentType = request.getContentType();
156-
if (!HTTPTransportUtils.isRESTRequest(contentType)) {
157+
if (enableJSONOnly && (contentType == null || contentType.isEmpty() || !HTTPTransportUtils.isJSONRequest(contentType))) {
158+
log.error("doPost() returning with no action taken, enableJSONOnly is true in the axis2.xml file and the content-type is not application/json: " + contentType);
159+
response.setContentType("application/json");
160+
showJSONOnlyErrorMessage(response);
161+
return;
162+
} else if (!HTTPTransportUtils.isRESTRequest(contentType)) {
157163
msgContext = createMessageContext(request, response);
158164
msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
159165
try {
@@ -354,6 +360,19 @@ protected void showRestDisabledErrorMessage(HttpServletResponse response) throws
354360
response.setStatus(HttpServletResponse.SC_ACCEPTED);
355361
}
356362

363+
/**
364+
* Private method that deals with disabling of SOAP and REST support.
365+
*
366+
* @param response
367+
* @throws IOException
368+
*/
369+
protected void showJSONOnlyErrorMessage(HttpServletResponse response) throws IOException {
370+
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
371+
PrintWriter writer = new PrintWriter(response.getOutputStream());
372+
writer.println("{ \"status\": \"error\",\"message\":\"content-type of application/json is mandatory\"}");
373+
writer.flush();
374+
}
375+
357376
/**
358377
* Close the builders.
359378
*

modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,23 @@ public static boolean isRESTRequest(String contentType) {
325325
contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) > -1);
326326
}
327327

328+
/**
329+
* This will match for content types that will be regarded as JSON
330+
* This contains,
331+
* 1. application/json
332+
* <p/>
333+
* If the request does not contain a content type, this will return false.
334+
*
335+
* @param contentType content type to check
336+
* @return Boolean
337+
*/
338+
public static boolean isJSONRequest(String contentType) {
339+
if (contentType == null || contentType.isEmpty()) {
340+
return false;
341+
}
342+
return (contentType.toLowerCase().indexOf(HTTPConstants.MEDIA_TYPE_APPLICATION_JSON) != -1);
343+
}
344+
328345
public static EndpointReference[] getEPRsForService(ConfigurationContext configurationContext,
329346
TransportInDescription trpInDesc, String serviceName, String ip, int port) throws AxisFault {
330347

modules/webapp/conf/axis2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<parameter name="hotupdate">false</parameter>
2626
<parameter name="enableMTOM">false</parameter>
2727
<parameter name="enableSwA">false</parameter>
28+
<parameter name="enableJSONOnly">false</parameter>
2829

2930
<!--Uncomment if you want to enable file caching for attachments -->
3031
<!--parameter name="cacheAttachments">true</parameter>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy