List of usage examples for io.netty.handler.codec.http HttpMethod POST
HttpMethod POST
To view the source code for io.netty.handler.codec.http HttpMethod POST.
Click Source Link
From source file:io.selendroid.server.HandlerRegisteredTest.java
License:Apache License
@Test public void postClickHandlerRegistered() throws Exception { String url = "http://" + host + ":" + port + "/wd/hub/session/12345/element/815/click"; HttpResponse response = executeRequest(url, HttpMethod.POST); SelendroidAssert.assertResponseIsOk(response); JSONObject responseJSON = parseJsonResponse(response); assertEquals("0", responseJSON.getString("status")); assertEquals("sessionId#12345 elementId#815", responseJSON.getString("value")); }
From source file:io.selendroid.server.HandlerRegisteredTest.java
License:Apache License
@Test public void postStatusHandlerNotRegistered() throws Exception { String url = "http://" + host + ":" + port + "/wd/hub/session/1234567890/element"; HttpResponse response = executeRequest(url, HttpMethod.POST); SelendroidAssert.assertResponseIsResourceNotFound(response); }
From source file:io.selendroid.server.SelendroidSatusHandlerTest.java
License:Apache License
public void assertThatGetStatusHanlerIsNotRegisteredForPost() throws Exception { HttpResponse response = HttpClientUtil.executeRequest(URL, HttpMethod.POST); SelendroidAssert.assertResponseIsServerError(response); }
From source file:io.selendroid.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeRequest(String url, HttpMethod method) throws Exception { HttpRequestBase request = null;//w ww. j a v a 2 s . c om if (HttpMethod.GET.equals(method)) { request = new HttpGet(url); } else if (HttpMethod.POST.equals(method)) { request = new HttpPost(url); } else if (HttpMethod.DELETE.equals(method)) { request = new HttpDelete(url); } else { throw new RuntimeException("Provided HttpMethod not supported"); } return getHttpClient().execute(request); }
From source file:io.selendroid.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeCreateSessionRequest(int port, SelendroidCapabilities desiredCapabilities) throws Exception { String url = "http://localhost:" + port + "/wd/hub/session"; log.info("creating session by using url: " + url); JSONObject payload = new JSONObject(); payload.put("desiredCapabilities", new JSONObject(desiredCapabilities.asMap())); HttpResponse response = executeRequestWithPayload(url, port, HttpMethod.POST, payload.toString()); return response; }
From source file:io.selendroid.standalone.server.handler.ProxyToDeviceHandler.java
License:Apache License
private JSONObject proxyRequestToDevice(HttpRequest request, ActiveSession session, String url, String method) throws Exception { HttpResponse r;/*w ww . j a v a 2 s. com*/ if ("get".equalsIgnoreCase(method)) { log.fine("Proxy GET to the device: " + url); r = HttpClientUtil.executeRequest(url, HttpMethod.GET); } else if ("post".equalsIgnoreCase(method)) { JSONObject payload = getPayload(request); log.fine("Proxy POST to the device: " + url + ", payload:\n" + payload); r = HttpClientUtil.executeRequestWithPayload(url, session.getSelendroidServerPort(), HttpMethod.POST, payload.toString()); } else if ("delete".equalsIgnoreCase(method)) { log.fine("Proxy DELETE to the device: " + url); r = HttpClientUtil.executeRequest(url, HttpMethod.DELETE); } else { throw new SelendroidException("HTTP method not supported: " + method); } return HttpClientUtil.parseJsonResponse(r); }
From source file:io.selendroid.standalone.server.util.HttpClientUtil.java
License:Apache License
public static HttpResponse executeRequest(String url, HttpMethod method) throws Exception { HttpRequestBase request;//w w w .java 2 s. c o m if (HttpMethod.GET.equals(method)) { request = new HttpGet(url); } else if (HttpMethod.POST.equals(method)) { request = new HttpPost(url); } else if (HttpMethod.DELETE.equals(method)) { request = new HttpDelete(url); } else { throw new RuntimeException("Provided HttpMethod not supported: " + method); } return getHttpClient().execute(request); }
From source file:io.soliton.protobuf.json.HttpJsonRpcClient.java
License:Apache License
@Override public <O extends Message> ListenableFuture<O> encodeMethodCall(final ClientMethod<O> method, Message input) { clientLogger.logMethodCall(method);//from w w w.jav a 2 s . co m final JsonResponseFuture<O> responseFuture = handler.newProvisionalResponse(method); JsonObject request = new JsonRpcRequest(method.serviceName(), method.name(), new JsonPrimitive(responseFuture.requestId()), Messages.toJson(input)).toJson(); ByteBuf requestBuffer = Unpooled.buffer(); JsonWriter writer = new JsonWriter( new OutputStreamWriter(new ByteBufOutputStream(requestBuffer), Charsets.UTF_8)); GSON.toJson(request, writer); try { writer.flush(); } catch (IOException ioe) { // Deliberately ignored, as this doesn't involve any I/O } String host = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress(); QueryStringEncoder encoder = new QueryStringEncoder(rpcPath); encoder.addParam("pp", "0"); HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, encoder.toString(), requestBuffer); httpRequest.headers().set(HttpHeaders.Names.HOST, host); httpRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, JsonRpcProtocol.CONTENT_TYPE); httpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, requestBuffer.readableBytes()); channel.writeAndFlush(httpRequest).addListener(new GenericFutureListener<ChannelFuture>() { public void operationComplete(ChannelFuture future) { if (!future.isSuccess()) { clientLogger.logLinkError(method, future.cause()); handler.finish(responseFuture.requestId()); responseFuture.setException(future.cause()); } } }); return responseFuture; }
From source file:io.soliton.protobuf.json.JsonRpcServerHandler.java
License:Apache License
/** * In charge of validating all the transport-related aspects of the incoming * HTTP request./* w ww .j a v a 2 s .c o m*/ * <p/> * <p>The checks include:</p> * <p/> * <ul> * <li>that the request's path matches that of this handler;</li> * <li>that the request's method is {@code POST};</li> * <li>that the request's content-type is {@code application/json};</li> * </ul> * * @param request the received HTTP request * @return {@code null} if the request passes the transport checks, an error * to return to the client otherwise. * @throws URISyntaxException if the URI of the request cannot be parsed */ private JsonRpcError validateTransport(HttpRequest request) throws URISyntaxException, JsonRpcError { URI uri = new URI(request.getUri()); JsonRpcError error = null; if (!uri.getPath().equals(rpcPath)) { error = new JsonRpcError(HttpResponseStatus.NOT_FOUND, "Not Found"); } if (!request.getMethod().equals(HttpMethod.POST)) { error = new JsonRpcError(HttpResponseStatus.METHOD_NOT_ALLOWED, "Method not allowed"); } if (!request.headers().get(HttpHeaders.Names.CONTENT_TYPE).equals(JsonRpcProtocol.CONTENT_TYPE)) { error = new JsonRpcError(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported media type"); } return error; }
From source file:io.soliton.protobuf.quartz.QuartzClientHandler.java
License:Apache License
/** * {@inheritDoc}//w w w . j av a2s . co m */ @Override public HttpRequest convertRequest(Envelope request) { ByteBuf requestBuffer = Unpooled.buffer(request.getSerializedSize()); try { OutputStream outputStream = new ByteBufOutputStream(requestBuffer); request.writeTo(outputStream); outputStream.flush(); } catch (IOException e) { // deliberately ignored, as the underlying operation doesn't involve I/O } String host = ((InetSocketAddress) channel().remoteAddress()).getAddress().getHostAddress(); String uriPath = String.format("%s%s/%s", path, request.getService(), request.getMethod()); FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, new QueryStringEncoder(uriPath).toString(), requestBuffer); httpRequest.headers().set(HttpHeaders.Names.HOST, host); httpRequest.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE); httpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, requestBuffer.readableBytes()); httpRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, QuartzProtocol.CONTENT_TYPE); return httpRequest; }