/*
 * Copyright (C) 2012 David Bordoley
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package restlib.example.echo;

import restlib.Request;
import restlib.Response;
import restlib.data.HttpDate;
import restlib.data.Status;
import restlib.server.FutureResponses;
import restlib.server.Resource;
import restlib.server.Route;

import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;

public final class EchoResource implements Resource {
    private final Route route;
    
    public static EchoResource newInstance(final Route route) {
        Preconditions.checkNotNull(route);
        return new EchoResource (route);
    }

    private EchoResource(final Route route) {
        this.route = route;   
    }

    public Route route() {
        return this.route;
    }

    public ListenableFuture<Response> handle(final Request request) {
        return FutureResponses.INFORMATIONAL_CONTINUE;
    }

    public ListenableFuture<Response> acceptMessage(final Request request, final Object message) {
        Preconditions.checkNotNull(request);
        Preconditions.checkNotNull(message);
        final String response =
                new StringBuilder()
                        .append(request)
                        .append(message.toString())
                        .toString();
        
        return Futures.immediateFuture(
                    Response.builder()
                        .setDate(HttpDate.create(System.currentTimeMillis()))
                        .setEntity(response) 
                        .setStatus(Status.SUCCESS_OK)
                        .setLocation(request.uri())
                        .build());
    }
}

@@ -703,16 +703,44 @@
 tpDate;%0A
+import restlib.data.Method;%0A
 import r
@@ -1487,54 +1487,567 @@
     
-return FutureResponses.INFORMATIONAL_CONTINUE;
+Preconditions.checkNotNull(request);%0A        %0A        if (request.method().equals(Method.POST) %7C%7C request.method().equals(Method.PUT)) %7B%0A            return FutureResponses.INFORMATIONAL_CONTINUE;%0A        %7D else %7B%0A            return Futures.immediateFuture(%0A                    Response.builder()%0A                    .setDate(HttpDate.create(System.currentTimeMillis()))%0A                    .setEntity(request.toString())%0A                    .setStatus(Status.SUCCESS_OK)%0A                    .setLocation(request.uri())%0A                    .build());%0A        %7D
 %0A   

Fix the echo example.