Search in sources :

Example 1 with JettyRoute

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);
    }
}
Also used : JettyRoute(com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 2 with JettyRoute

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, "")));
}
Also used : MetadataElement(com.adaptris.core.MetadataElement) JettyRoute(com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute) Test(org.junit.Test)

Aggregations

JettyRoute (com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute)2 CoreException (com.adaptris.core.CoreException)1 MetadataElement (com.adaptris.core.MetadataElement)1 ServiceException (com.adaptris.core.ServiceException)1 Test (org.junit.Test)1