use of com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute in project interlok by adaptris.
the class JettyRoutingService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
String method = msg.getMetadataValue(HTTP_METHOD);
String uri = msg.getMetadataValue(JETTY_URI);
boolean matched = false;
for (JettyRouteSpec route : routes) {
JettyRoute m = route.build(method, uri);
if (m.matches()) {
log.trace("[{}][{}], matched by {}", method, uri, route);
msg.setMetadata(m.metadata());
msg.setNextServiceId(route.getServiceId());
matched = true;
break;
}
}
if (!matched) {
log.debug("No Matches from configured routes, using {}", getDefaultServiceId());
msg.setNextServiceId(getDefaultServiceId());
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute in project interlok by adaptris.
the class JettyRouteSpecTest method testMatch_WithCondition.
@Test
public void testMatch_WithCondition() throws Exception {
JettyRouteSpec spec = LifecycleHelper.initAndStart(new JettyRouteSpec().withCondition(new JettyRouteCondition().withMetadataKeys(RECORD_ID).withMethod("POST").withUrlPattern(REGEX_WITH_GROUP)).withServiceId(NEXT_SERVICE_ID));
assertNotNull(spec.build("GET", URI));
JettyRoute match = spec.build("POST", URI);
assertTrue(match.matches());
assertTrue(match.metadata().contains(new MetadataElement(RECORD_ID, "")));
}
Aggregations