ATG REST module provides two input customizers out of the box.
1. JSONInputCustomizer
2. XMLInputCustomizer
This means that you can send the request parameters in JSON format or XML format and ATG REST is capable of handling it. In the current version of ATG, it doesn’t provide input customizers to parse the multipart form data. In this post I would explain you the steps involved in writing and configuring a multipart excel input customizer.
ATG REST input customizer static design
Write your input customizer class
To write a custom input customizer you should extend RestInputCustomizerImpl class provided by ATG REST.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package com.ourownjava.atg.rest; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import atg.rest.RestException; import atg.rest.input.RestInputCustomizerImpl; import atg.servlet.DynamoHttpServletRequest; import atg.servlet.DynamoHttpServletResponse; /** * @author ourownjava.com */ public class ExcelInputCustomizer extends RestInputCustomizerImpl { public ExcelInputCustomizer() { setFormat("vnd.ms-excel"); setAcceptableMimeTypes(new String[] { "application/vnd.ms-excel" }); } @Override public Class<?> getContainerClass() { return HSSFWorkbook.class; } @Override public Object parseString(final String paramString, final DynamoHttpServletRequest paramDynamoHttpServletRequest, final DynamoHttpServletResponse paramDynamoHttpServletResponse) throws RestException { try { return new HSSFWorkbook(new ByteArrayInputStream( paramString.getBytes("ISO-8859-1"))); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } throw new RuntimeException("something went wrong, check log!"); } @Override public Map<String, Object> convertToMap(final Object paramObject, final DynamoHttpServletRequest paramDynamoHttpServletRequest, final DynamoHttpServletResponse paramDynamoHttpServletResponse) throws RestException { final Map<String, Object> paramMap = new HashMap<String, Object>(2); paramMap.put("EXCEL_INPUT", paramObject); return paramMap; } @Override public Object instantiateObjectParameter(final Object paramObject, final DynamoHttpServletRequest paramDynamoHttpServletRequest, final DynamoHttpServletResponse paramDynamoHttpServletResponse) throws RestException { return paramObject; } @Override public boolean isValidTypeString(final String paramString) { return true; } @Override public String[] splitMultipleStringsAtCharacter(final String paramString, final char paramChar) { return new String[] { paramString }; } } |
Define a component for ExcelInputCustomizer class
Create ExcelInputCustomizer.properties file in location /info/atgblog/rest/input.
1 |
$class=/info/atgblog/rest/input/ExcelInputCustomizer |
Configure the input customizer
Open up the /atg/rest/Configuration.properties and add the ExcelInputCustomizer for excel mime type.
1 |
inputCustomizers+=vnd.ms-excel=/info/atgblog/rest/input/ExcelInputCustomizer |
How to write a program in ATG .