}
@Override
public CORSConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
CORSConfiguration corsConfiguration = corsConfigurationFactory.createCORSConfiguration();
/**
* <corsConfiguration>
* <allowCredentials>true</allowCredentials>
*
* <maxAge>100</maxAge>
*
* <allowOrigins>
* <origin>http://www.sfly.com</origin>
* </allowOrigins>
*
* <allowMethods>
* <method>PUT</method>
* <method>POST</method>
* </allowMethods>
*
* <allowHeaders>
* <header>X-custom-1</header>
* <header>X-custom-2</header>
* </allowHeaders>
*
* <exposeHeaders>
* <header>X-custom-1</header>
* <header>X-custom-2</header>
* </exposeHeaders>
*
* </corsConfiguration>
**/
HeaderElementType headerType = null;
while(reader.hasNext()) {
QName elementName = null;
int event = reader.getEventType();
switch (event) {
case START_ELEMENT:
elementName = reader.getName();
if (ALLOW_CREDENTIALS_QNAME.equals(elementName)) {
String value = reader.getElementText();
corsConfiguration.setAllowCredentials(Boolean.parseBoolean(value));
} else if (MAX_AGE_QNAME.equals(elementName)) {
String value = reader.getElementText();
corsConfiguration.setMaxAge(Integer.parseInt(value));
} else if (ORIGIN_QNAME.equals(elementName)) {
String value = reader.getElementText();
corsConfiguration.getAllowOrigins().add(value);
} else if (METHOD_QNAME.equals(elementName)) {
String value = reader.getElementText();
corsConfiguration.getAllowMethods().add(value);
} else if (ALLOW_HEADERS_QNAME.equals(elementName)) {
headerType = HeaderElementType.ALLOWHEADERS;
} else if (EXPOSE_HEADERS_QNAME.equals(elementName)) {
headerType = HeaderElementType.EXPOSEHEADERS;
} else if (HEADER_QNAME.equals(elementName)) {
if(headerType != null) {
String value = reader.getElementText();
if(headerType == HeaderElementType.ALLOWHEADERS) {
corsConfiguration.getAllowHeaders().add(value);
} else {
corsConfiguration.getExposeHeaders().add(value);
}
}
}
break;