Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You should be able to pass the HttpRequest to the REST method #730

Closed
RichardHightower opened this issue Jun 8, 2016 · 2 comments
Closed

Comments

@RichardHightower
Copy link
Member

You should be able to pass the HttpRequest to the REST method

RichardHightower pushed a commit that referenced this issue Jun 8, 2016
@RichardHightower
Copy link
Member Author

fixed

@RichardHightower
Copy link
Member Author

package io.advantageous.qbit.vertx.bugs;

import io.advantageous.qbit.annotation.RequestMapping;
import io.advantageous.qbit.annotation.RequestMethod;
import io.advantageous.qbit.annotation.RequestParam;
import io.advantageous.qbit.http.client.HttpClient;
import io.advantageous.qbit.http.client.HttpClientBuilder;
import io.advantageous.qbit.http.request.HttpRequest;
import io.advantageous.qbit.http.request.HttpRequestBuilder;
import io.advantageous.qbit.http.request.HttpTextResponse;
import io.advantageous.qbit.reactive.Callback;
import io.advantageous.qbit.server.EndpointServerBuilder;
import io.advantageous.qbit.server.ServiceEndpointServer;
import io.advantageous.qbit.util.PortUtils;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;

/**
 * Created by rick on 6/8/16.
 */
public class Bug730 {

    @Test
    public void test() {
        final int port = PortUtils.findOpenPortStartAt(8080);

        final ServiceEndpointServer serviceEndpointServer =
                EndpointServerBuilder.endpointServerBuilder().setUri("/")
                        .addService(new MyService()).setPort(port).build();

        serviceEndpointServer.startServerAndWait();

        final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();

        final HttpRequest httpRequest = HttpRequestBuilder.httpRequestBuilder().setUri("/reverse")
                .addParam("foo", "bar").addParam("reverseParam", "Rick Loves Java")
                .setFormPostAndCreateFormBody().build();

        final HttpTextResponse httpTextResponse = httpClient.sendRequestAndWait(httpRequest);

        assertEquals("\"was=Rick Loves Java\"", httpTextResponse.body());

        serviceEndpointServer.stop();
    }


    @RequestMapping("/")
    public static class MyService {
        @RequestMapping(value = "/reverse", method = RequestMethod.POST, code = 200)
        public void doPostReverse(final Callback<String> callback,
                                  final @RequestParam("reverseParam") String reverseParam,
                                  final HttpRequest request) {
            String retval = reverseParam != null ? new StringBuilder(reverseParam).reverse().toString() : "reverseParam was NULL";
            System.out.println("In: " + reverseParam + ", Out: " + retval);
            callback.resolve("was=" + request.getParam("reverseParam"));
        }
    }
}

That works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant