@Override
    public StubResponse provideStubResponseFor(final Request request) {
        synchronized(this) {
            if (this.configurable) {
                this.configurable = false;
                this.httpStubs = this.createHttpStubs();
            }

            if (this.recordRequests) {
                this.receivedRequests.add(request);
            }
        }
        
        for (final Iterator<HttpStub> it = this.httpStubs.descendingIterator(); it.hasNext(); ) {
            final HttpStub rule = it.next();
            if (rule.matches(request)) {
                final StringBuilder sb = new StringBuilder();
                sb.append("Following rule will be applied:\n");
                sb.append(rule);
                logger.debug(sb.toString());
                
                return rule.nextResponse(request);
            }
        }
        
        final StringBuilder sb = new StringBuilder();
        sb.append("No suitable rule found. Reason:\n");
        for (final HttpStub rule: this.httpStubs) {
            sb.append("The rule '");
            sb.append(rule);
            sb.append("' cannot be applied. Mismatch:\n");
            sb.append(rule.describeMismatch(request));
            sb.append("\n");
        }
        logger.info(sb.toString());
        
        return NO_RULE_FOUND_RESPONSE;
    }
@Override
    public StubResponse provideStubResponseFor(final Request request) {
        synchronized(this) {
            if (this.configurable) {
                this.configurable = false;
                this.httpStubs = this.createHttpStubs();
            }

            if (this.recordRequests) {
                this.receivedRequests.add(request);
            }
        }
        
        for (final Iterator<HttpStub> it = this.httpStubs.descendingIterator(); it.hasNext(); ) {
            final HttpStub rule = it.next();
            if (rule.matches(request)) {
                final StringBuilder sb = new StringBuilder();
                sb.append("Following rule will be applied:\n");
                sb.append(rule);
                logger.debug(sb.toString());
                
                return rule.nextResponse(request);
            }
        }
        
        final StringBuilder sb = new StringBuilder();
        sb.append("No suitable rule found. Reason:\n");
        for (final HttpStub rule: this.httpStubs) {
            sb.append("The rule '");
            sb.append(rule);
            sb.append("' cannot be applied. Mismatch:\n");
            sb.append(rule.describeMismatch(request));
            sb.append("\n");
        }
        logger.info(sb.toString());
        
        return NO_RULE_FOUND_RESPONSE;
    }
@ Override public StubResponse provideStubResponseFor ( final Request request ) { synchronized ( this ) { if ( this . configurable ) { this . configurable = false ; this . httpStubs = this . createHttpStubs ( ) ; } if ( this . recordRequests ) { this . receivedRequests . add ( request ) ; } } for ( final Iterator < HttpStub > it = this . httpStubs . descendingIterator ( ) ; it . hasNext ( ) ; ) { final HttpStub rule = it . next ( ) ; if ( rule . matches ( request ) ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Following rule will be applied:\n" ) ; sb . append ( rule ) ; logger . debug ( sb . toString ( ) ) ; return rule . nextResponse ( request ) ; } } final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "No suitable rule found. Reason:\n" ) ; for ( final HttpStub rule : this . httpStubs ) { sb . append ( "The rule '" ) ; sb . append ( rule ) ; sb . append ( "' cannot be applied. Mismatch:\n" ) ; sb . append ( rule . describeMismatch ( request ) ) ; sb . append ( "\n" ) ; } logger . info ( sb . toString ( ) ) ; return NO_RULE_FOUND_RESPONSE ; }
{@inheritDoc}
{