Search in sources :

Example 1 with EndsWith

use of io.atlasmap.v2.EndsWith in project atlasmap by atlasmap.

the class StringComplexFieldActionsTest method testEndsWith.

@Test
public void testEndsWith() {
    EndsWith action = new EndsWith();
    action.setString("");
    assertFalse(StringComplexFieldActions.endsWith(action, null));
    assertTrue(StringComplexFieldActions.endsWith(action, ""));
    assertTrue(StringComplexFieldActions.endsWith(action, "foo"));
    action.setString("bar");
    assertFalse(StringComplexFieldActions.endsWith(action, null));
    assertFalse(StringComplexFieldActions.endsWith(action, ""));
    assertFalse(StringComplexFieldActions.endsWith(action, "foo"));
    assertTrue(StringComplexFieldActions.endsWith(action, "foobar"));
    assertFalse(StringComplexFieldActions.endsWith(action, "barfoo"));
}
Also used : EndsWith(io.atlasmap.v2.EndsWith) Test(org.junit.Test)

Example 2 with EndsWith

use of io.atlasmap.v2.EndsWith 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;
}
Also used : DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) AtlasMappingFormat(io.atlasmap.core.AtlasMappingService.AtlasMappingFormat) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader)

Aggregations

AtlasMappingFormat (io.atlasmap.core.AtlasMappingService.AtlasMappingFormat)1 DefaultAtlasContextFactory (io.atlasmap.core.DefaultAtlasContextFactory)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 EndsWith (io.atlasmap.v2.EndsWith)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Test (org.junit.Test)1