use of io.atlasmap.core.AtlasMappingService.AtlasMappingFormat in project atlasmap by atlasmap.
the class AtlasEndpoint method getOrCreateAtlasContext.
private AtlasContext getOrCreateAtlasContext(Message incomingMessage) throws Exception {
String path = getResourceUri();
ObjectHelper.notNull(path, "mappingUri");
AtlasMappingFormat mappingFormat = path.toLowerCase().endsWith("json") ? AtlasMappingFormat.JSON : AtlasMappingFormat.XML;
Reader reader;
String content = incomingMessage.getHeader(AtlasConstants.ATLAS_MAPPING, String.class);
if (content != null) {
// use content from header
reader = new StringReader(content);
if (log.isDebugEnabled()) {
log.debug("Atlas mapping content read from header {} for endpoint {}", AtlasConstants.ATLAS_MAPPING, getEndpointUri());
}
// remove the header to avoid it being propagated in the routing
incomingMessage.removeHeader(AtlasConstants.ATLAS_MAPPING);
AtlasMapping mapping = ((DefaultAtlasContextFactory) getOrCreateAtlasContextFactory()).getMappingService().loadMapping(reader, mappingFormat);
return ((DefaultAtlasContextFactory) getOrCreateAtlasContextFactory()).createContext(mapping);
} else if (getAtlasContext() != null) {
// no mapping specified in header, and found an existing context
return getAtlasContext();
}
// No mapping in header, and no existing context. Create new one from resourceUri
if (log.isDebugEnabled()) {
log.debug("Atlas mapping content read from resourceUri: {} for endpoint {}", new Object[] { path, getEndpointUri() });
}
reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
AtlasMapping mapping = ((DefaultAtlasContextFactory) getOrCreateAtlasContextFactory()).getMappingService().loadMapping(reader, mappingFormat);
atlasContext = ((DefaultAtlasContextFactory) getOrCreateAtlasContextFactory()).createContext(mapping);
return atlasContext;
}
use of io.atlasmap.core.AtlasMappingService.AtlasMappingFormat in project atlasmap by atlasmap.
the class AtlasMappingServiceTest method testLoadMappingStringAtlasMappingFormat.
@Test
public void testLoadMappingStringAtlasMappingFormat() throws AtlasValidationException {
String filename = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "atlasmapping.xml";
AtlasMappingFormat format = AtlasMappingFormat.XML;
assertNotNull(format.value());
assertNotNull(AtlasMappingFormat.valueOf("XML"));
AtlasMapping atlasMapping = atlasMappingService.loadMapping(filename, format);
assertNotNull(atlasMapping);
}
Aggregations