|
| 1 | +package org.wso2.carbon.apimgt.rest.api.util.servlet.impl; |
| 2 | + |
| 3 | +import org.apache.commons.lang.StringUtils; |
| 4 | +import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet; |
| 5 | + |
| 6 | +import java.util.Collections; |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +public class CustomCXFNonSpringJaxrsServlet extends CXFNonSpringJaxrsServlet { |
| 11 | + |
| 12 | + static Map<String, String> systemPropMap = new HashMap(); |
| 13 | + |
| 14 | + static { |
| 15 | + systemPropMap.put("rest.api.admin.attachment.max.size", "10485760"); |
| 16 | + systemPropMap.put("rest.api.devportal.attachment.max.size", "10485760"); |
| 17 | + systemPropMap.put("rest.api.publisher.attachment.max.size", "10485760"); |
| 18 | + systemPropMap.put("rest.api.service.catalog.attachment.max.size", "10485760"); |
| 19 | + } |
| 20 | + |
| 21 | + protected static Map<String, String> parseMapSequence(String sequence) { |
| 22 | + if (sequence != null) { |
| 23 | + sequence = sequence.trim(); |
| 24 | + Map<String, String> map = new HashMap(); |
| 25 | + String[] pairs = StringUtils.split(sequence, " "); |
| 26 | + String[] arr = pairs; |
| 27 | + int len$ = pairs.length; |
| 28 | + |
| 29 | + for(int i = 0; i < len$; ++i) { |
| 30 | + String pair = arr[i]; |
| 31 | + String thePair = pair.trim(); |
| 32 | + if (!thePair.isEmpty()) { |
| 33 | + String[] value = StringUtils.split(thePair, "="); |
| 34 | + if (value.length == 2) { |
| 35 | + if (value[1].startsWith("{systemProperties")) { |
| 36 | + //resolve system property if exists or else set default value |
| 37 | + int begin = value[1].indexOf("'"); |
| 38 | + int end = value[1].lastIndexOf("'"); |
| 39 | + String key = value[1].substring(begin, end); |
| 40 | + String systemPropValue = System.getProperty(key); |
| 41 | + if (StringUtils.isNotEmpty(systemPropValue)) { |
| 42 | + map.put(value[0].trim(), systemPropValue); |
| 43 | + } else { |
| 44 | + map.put(value[0].trim(), systemPropMap.get(value[0])); |
| 45 | + } |
| 46 | + } else { |
| 47 | + map.put(value[0].trim(), value[1].trim()); |
| 48 | + } |
| 49 | + } else { |
| 50 | + map.put(thePair, ""); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + return map; |
| 56 | + } else { |
| 57 | + return Collections.emptyMap(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments