@Override public String getHttpMethod() { return clientRequest.getHttpMethod(); }
@Override public String getHttpMethod() { return clientRequest.getHttpMethod(); }
protected HttpURLConnection createConnection(ClientRequest request) throws Exception { String uri = request.getUri(); String httpMethod = request.getHttpMethod(); HttpURLConnection connection = (HttpURLConnection) new URL(uri).openConnection(); connection.setRequestMethod(httpMethod); return connection; }
HttpMethod getHttpMethod() { final String httpMethod = clientRequest.getHttpMethod(); return HttpMethod.valueOf(httpMethod); }
protected HttpURLConnection createConnection(ClientRequest request) throws Exception { String uri = request.getUri(); String httpMethod = request.getHttpMethod(); HttpURLConnection connection = (HttpURLConnection) new URL(uri).openConnection(); connection.setRequestMethod(httpMethod); return connection; }
RestfulHttpMethod getHttpMethod() { final String httpMethod = clientRequest.getHttpMethod(); return RestfulHttpMethod.valueOf(httpMethod); }
/** * Used when following links ( * {@link RestfulClient#follow(LinkRepresentation)}). */ public ClientRequestConfigurer configureArgs(final JsonRepresentation requestArgs) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } getHttpMethod().setUpArgs(this, requestArgs); return this; }
/** * Used when following links ( * {@link RestfulClient#follow(LinkRepresentation)}). */ public ClientRequestConfigurer configureArgs(final JsonRepresentation requestArgs) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } getHttpMethod().setUpArgs(this, requestArgs); return this; }
/** * Used when creating a request with arguments to execute. * * <p> * Typical flow is: * <ul> * <li> {@link RestfulClient#createRequest(RestfulHttpMethod, String)} * <li> {@link RestfulRequest#withArg(RequestParameter, Object)} for each arg * <li> {@link RestfulRequest#execute()} - which calls this method. * </ul> */ public ClientRequestConfigurer configureArgs(final Map<RequestParameter<?>, Object> args) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } final JsonRepresentation argsAsMap = JsonRepresentation.newMap(); for (final RequestParameter<?> requestParam : args.keySet()) { put(args, requestParam, argsAsMap); } getHttpMethod().setUpArgs(this, argsAsMap); return this; }
private byte[] writeRequestEntity(ClientRequest clientRequest) { if (clientRequest.getBody() != null && !clientRequest.getFormParameters().isEmpty()) throw new RuntimeException("You cannot send both form parameters and an entity body"); if (!clientRequest.getFormParameters().isEmpty()) { throw new UnsupportedOperationException("InProcessClientExecutpr doesn't support form parameters yet"); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (clientRequest.getBody() != null) { if ("GET".equals(clientRequest.getHttpMethod())) throw new RuntimeException("A GET request cannot have a body."); try { clientRequest.writeRequestBody(clientRequest.getHeadersAsObjects(), baos); } catch (IOException e) { throw new RuntimeException(e); } } return baos.toByteArray(); }
private byte[] writeRequestEntity(ClientRequest clientRequest) { if (clientRequest.getBody() != null && !clientRequest.getFormParameters().isEmpty()) throw new RuntimeException("You cannot send both form parameters and an entity body"); if (!clientRequest.getFormParameters().isEmpty()) { throw new UnsupportedOperationException("InProcessClientExecutpr doesn't support form parameters yet"); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (clientRequest.getBody() != null) { if ("GET".equals(clientRequest.getHttpMethod())) throw new RuntimeException("A GET request cannot have a body."); try { clientRequest.writeRequestBody(clientRequest.getHeadersAsObjects(), baos); } catch (IOException e) { throw new RuntimeException(e); } } return baos.toByteArray(); }
/** * Used when creating a request with arguments to execute. * * <p> * Typical flow is: * <ul> * <li> {@link RestfulClient#createRequest(HttpMethod, String)} * <li> {@link RestfulRequest#withArg(RequestParameter, Object)} for each arg * <li> {@link RestfulRequest#execute()} - which calls this method. * </ul> */ public ClientRequestConfigurer configureArgs(final Map<RequestParameter<?>, Object> args) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } final JsonRepresentation argsAsMap = JsonRepresentation.newMap(); for (final RequestParameter<?> requestParam : args.keySet()) { put(args, requestParam, argsAsMap); } getHttpMethod().setUpArgs(this, argsAsMap); return this; }
@Override public ClientResponse execute(final ClientExecutionContext ctx) throws Exception { final ClientRequest request = ctx.getRequest(); // ETags can only be used on GET requests, so if it's anything else proceed normally if (!request.getHttpMethod().equals(HttpMethod.GET)) { return ctx.proceed(); } // Load the etag for the request from the cache final String etag = getETag(request); if (etag != null) { request.header(HttpHeaders.IF_NONE_MATCH, etag); } // Get the response and save the etag value final ClientResponse response = ctx.proceed(); cacheIfPossible(request, response); return response; }
public ClientResponse execute(ClientRequest request) throws Exception { MockHttpRequest mockHttpRequest = MockHttpRequest.create(request.getHttpMethod(), new URI(request.getUri()), baseUri); final MockHttpResponse mockResponse = new MockHttpResponse(); mockHttpRequest.setAsynchronousContext(new SynchronousExecutionContext((SynchronousDispatcher)dispatcher, mockHttpRequest, mockResponse)); loadHttpMethod(request, mockHttpRequest); dispatcher.invoke(mockHttpRequest, mockResponse); return createResponse(request, mockResponse); }
public ClientResponse execute(ClientRequest request) throws Exception { MockHttpRequest mockHttpRequest = MockHttpRequest.create(request.getHttpMethod(), new URI(request.getUri()), baseUri); final MockHttpResponse mockResponse = new MockHttpResponse(); mockHttpRequest.setAsynchronousContext(new SynchronousExecutionContext((SynchronousDispatcher)dispatcher, mockHttpRequest, mockResponse)); loadHttpMethod(request, mockHttpRequest); dispatcher.invoke(mockHttpRequest, mockResponse); return createResponse(request, mockResponse); }
final HttpRequestBase httpMethod = createHttpMethod(uri, request.getHttpMethod()); try
final HttpRequestBase httpMethod = createHttpMethod(uri, request.getHttpMethod()); try
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }
@Ignore("TODO") @Test public void follow_get() throws Exception { final LinkRepresentation link = jsonRepresentation.getLink("aLink"); final String href = link.getHref(); // when context.checking(new Expectations() { { one(mockExecutor).createRequest(with(any(UriBuilderImpl.class))); will(returnValue(mockClientRequest)); one(mockExecutor).execute(mockClientRequest); will(returnValue(mockClientResponse)); one(mockClientRequest).accept(MediaType.APPLICATION_JSON_TYPE); atLeast(1).of(mockClientRequest).setHttpMethod("GET"); allowing(mockClientRequest).getHttpMethod(); will(returnValue("GET")); one(mockClientRequest).execute(); will(returnValue(mockClientResponse)); one(mockClientResponse).setReturnType(String.class); allowing(mockClientResponse); final MultiValueMap result = new MultiValueMap(); result.put("Content-Type", "application/json"); allowing(mockClientResponse).getMetadata(); will(returnValue(result)); } }); final RestfulResponse<JsonRepresentation> response = client.follow(link); // then }