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:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java
License:Open Source License
protected static RestFuture createData(Channel channel, RESTHANDLERS data) throws HttpInvalidAuthenticationException { logger.debug("Send query"); AbstractDbData dbData = getItem(data); if (dbData == null) { RestFuture future = channel.attr(HttpRestClientSimpleResponseHandler.RESTARGUMENT).get(); future.cancel();/*ww w. j av a 2s .co m*/ WaarpSslUtility.closingSslChannel(channel); return future; } String key = null, value = null; if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) { key = userAuthent; value = keyAuthent; } Map<String, String> args = null; RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.POST, host, data.uri, key, value, args, dbData.asJson()); logger.debug("Query sent"); return future; }
From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java
License:Open Source License
protected static RestFuture action(Channel channel, RESTHANDLERS data) throws HttpInvalidAuthenticationException { logger.warn("Send query: " + data); JsonPacket packet = null;/* ww w .ja v a 2 s . c o m*/ HttpMethod method = null; switch (data) { case Bandwidth: { BandwidthJsonPacket node = new BandwidthJsonPacket(); node.setReadglobal(0); node.setReadsession(0); node.setSetter(true); node.setRequestUserPacket(); packet = node; method = HttpMethod.PUT; break; } case Business: { BusinessRequestJsonPacket node = new BusinessRequestJsonPacket(); node.setClassName(TestExecJavaTask.class.getName()); node.setArguments("business 100 other arguments 0"); node.setRequestUserPacket(); node.setToApplied(true); packet = node; method = HttpMethod.GET; break; } case Config: { ConfigExportJsonPacket node = new ConfigExportJsonPacket(); node.setHost(true); node.setRule(true); node.setBusiness(true); node.setAlias(true); node.setRoles(true); node.setRequestUserPacket(); packet = node; method = HttpMethod.GET; break; } case Information: { InformationJsonPacket node = new InformationJsonPacket( (byte) InformationPacket.ASKENUM.ASKLIST.ordinal(), "rule4", "test*"); packet = node; method = HttpMethod.GET; break; } case Log: { LogJsonPacket node = new LogJsonPacket(); node.setStop(new Date()); node.setRequestUserPacket(); packet = node; method = HttpMethod.GET; break; } case Server: { ShutdownOrBlockJsonPacket node = new ShutdownOrBlockJsonPacket(); node.setRestartOrBlock(true); node.setShutdownOrBlock(false); String pwd = "pwdhttp"; byte[] bpwd = FilesystemBasedDigest.passwdCrypt(pwd.getBytes(WaarpStringUtils.UTF8)); node.setKey(bpwd); node.setRequestUserPacket(LocalPacketFactory.BLOCKREQUESTPACKET); packet = node; method = HttpMethod.PUT; break; } case Control: { TransferRequestJsonPacket node = new TransferRequestJsonPacket(); node.setRequestUserPacket(); node.setRulename("rule4"); node.setRank(0); node.setBlocksize(65536); node.setFileInformation("file info"); node.setFilename("filename"); node.setMode(2); node.setSpecialId(DbConstant.ILLEGALVALUE); node.setRequested(hostid); node.setStart(new Date()); node.setOriginalSize(123L); node.setRequestUserPacket(); packet = node; method = HttpMethod.POST; break; } default: break; } return action(channel, method, data.uri, packet); }
From source file:org.waarp.openr66.proxy.protocol.http.adminssl.HttpSslHandler.java
License:Open Source License
private void checkAuthent(ChannelHandlerContext ctx) { newSession = true;/*from w w w . j a v a 2s . c o m*/ if (request.method() == HttpMethod.GET) { String logon = Logon(); logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), ""); responseContent.append(logon); clearSession(); writeResponse(ctx); return; } else if (request.method() == HttpMethod.POST) { getParams(); if (params == null) { String logon = Logon(); logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), Messages.getString("HttpSslHandler.EmptyLogin")); responseContent.append(logon); clearSession(); writeResponse(ctx); return; } } boolean getMenu = false; if (params.containsKey("Logon")) { String name = null, password = null; List<String> values = null; if (!params.isEmpty()) { // get values if (params.containsKey("name")) { values = params.get("name"); if (values != null) { name = values.get(0); if (name == null || name.isEmpty()) { getMenu = true; } } } else { getMenu = true; } // search the nb param if ((!getMenu) && params.containsKey("passwd")) { values = params.get("passwd"); if (values != null) { password = values.get(0); if (password == null || password.isEmpty()) { getMenu = true; } else { getMenu = false; } } else { getMenu = true; } } else { getMenu = true; } } else { getMenu = true; } if (!getMenu) { logger.debug("Name=" + name + " vs " + name.equals(Configuration.configuration.getADMINNAME()) + " Passwd vs " + Arrays.equals(password.getBytes(WaarpStringUtils.UTF8), Configuration.configuration.getSERVERADMINKEY())); if (name.equals(Configuration.configuration.getADMINNAME()) && Arrays.equals(password.getBytes(WaarpStringUtils.UTF8), Configuration.configuration.getSERVERADMINKEY())) { authentHttp.getAuth().specialNoSessionAuth(true, Configuration.configuration.getHOST_ID()); authentHttp.setStatus(70); } else { getMenu = true; } if (!authentHttp.isAuthenticated()) { authentHttp.setStatus(71); logger.debug("Still not authenticated: {}", authentHttp); getMenu = true; } } } else { getMenu = true; } if (getMenu) { String logon = Logon(); logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), Messages.getString("HttpSslHandler.BadLogin")); responseContent.append(logon); clearSession(); writeResponse(ctx); } else { String index = index(); responseContent.append(index); clearSession(); admin = new DefaultCookie(R66SESSION + Configuration.configuration.getHOST_ID(), Configuration.configuration.getHOST_ID() + Long.toHexString(random.nextLong())); sessions.put(admin.value(), this.authentHttp); authentHttp.setStatus(72); logger.debug("CreateSession: " + uriRequest + ":{}", admin); writeResponse(ctx); } }
From source file:org.wildfly.security.ssl.TestingOcspServer.java
License:Open Source License
public void start() throws Exception { Assert.assertNull("OCSP server already started", ocspServer); ocspServer = new OcspServer(); ocspServer.setConfFile(TestingOcspServer.class.getResource("ocsp-responder.xml").getFile()); securityFactory.setSignerFactoryRegister(new SignerFactoryRegisterImpl()); ocspServer.setSecurityFactory(securityFactory); ocspServer.init();//from w ww. j ava 2 s .co m HttpOcspServlet servlet = new HttpOcspServlet(); servlet.setServer(ocspServer); server = new ClientAndServer(port); server.when(request().withMethod("POST").withPath("/ocsp"), Times.unlimited()).respond(request -> { ByteBuf buffer = Unpooled.wrappedBuffer(request.getBody().getRawBytes()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.POST, request.getPath().getValue(), buffer); for (Header header : request.getHeaderList()) { for (NottableString value : header.getValues()) { nettyRequest.headers().add(header.getName().getValue(), value.getValue()); } } FullHttpResponse nettyResponse; try { nettyResponse = servlet.service(nettyRequest, new ServletURI(request.getPath().getValue()), null, SslReverseProxyMode.NONE); } catch (Exception e) { throw new RuntimeException(e); } HttpResponse response = response().withStatusCode(nettyResponse.status().code()) .withBody(nettyResponse.content().array()); for (Map.Entry<String, String> header : nettyResponse.headers()) { response.withHeader(header.getKey(), header.getValue()); } return response; }); }
From source file:org.wisdom.engine.server.WisdomHandler.java
License:Apache License
private void handleHttpRequest(ChannelHandlerContext ctx, HttpObject req) { if (req instanceof HttpRequest) { request = (HttpRequest) req;/*w ww. j a v a2 s .com*/ context = new ContextFromNetty(accessor, ctx, request); switch (handshake(ctx)) { case HANDSHAKE_UNSUPPORTED: CommonResponses.sendUnsupportedWebSocketVersionResponse(ctx.channel()); return; case HANDSHAKE_ERROR: CommonResponses.sendWebSocketHandshakeErrorResponse(ctx.channel()); return; case HANDSHAKE_OK: // Handshake ok, just return return; case NO_HANDSHAKE: default: // No handshake attempted, continue. break; } } if (req instanceof HttpContent) { // Only valid for put and post. if (request.getMethod().equals(HttpMethod.POST) || request.getMethod().equals(HttpMethod.PUT)) { if (decoder == null) { decoder = new HttpPostRequestDecoder(DATA_FACTORY, request); } context.decodeContent(request, (HttpContent) req, decoder); } } if (req instanceof LastHttpContent) { // End of transmission. boolean isAsync = dispatch(context, ctx); if (!isAsync) { cleanup(); } } }
From source file:org.wso2.carbon.analytics.test.osgi.util.TestUtil.java
License:Open Source License
public TestUtil(URI baseURI, String path, Boolean auth, Boolean keepAlive, String methodType, String contentType, String userName, String password) { try {/*from w ww. java2 s . co m*/ URL url = baseURI.resolve(path).toURL(); boundary = "---------------------------" + currentTimeMillis(); logger.error(url.toString()); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Accept-Charset", CHARSET); connection.setRequestMethod(methodType); setHeader("HTTP_METHOD", methodType); if (keepAlive) { connection.setRequestProperty("Connection", "Keep-Alive"); } if (contentType != null) { if (contentType.equals("multipart/form-data")) { setHeader("Content-Type", "multipart/form-data; boundary=" + boundary); } else { setHeader("Content-Type", contentType); } } connection.setUseCaches(false); connection.setDoInput(true); if (auth) { connection.setRequestProperty("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString((userName + ":" + password).getBytes())); } if (methodType.equals(HttpMethod.POST.name()) || methodType.equals(HttpMethod.PUT.name()) || methodType.equals(HttpMethod.DELETE.name())) { connection.setDoOutput(true); outputStream = connection.getOutputStream(); writer = new PrintWriter(new OutputStreamWriter(outputStream, CHARSET), true); } } catch (IOException e) { handleException("IOException occurred while running the HttpsSourceTestCaseForSSL", e); } }
From source file:org.wso2.carbon.mss.internal.router.HttpResourceModel.java
License:Open Source License
/** * Fetches the HttpMethod from annotations and returns String representation of HttpMethod. * Return emptyString if not present.//from w w w . j a va 2s . co m * * @param method Method handling the http request. * @return String representation of HttpMethod from annotations or emptyString as a default. */ private Set<HttpMethod> getHttpMethods(Method method) { Set<HttpMethod> httpMethods = Sets.newHashSet(); if (method.isAnnotationPresent(GET.class)) { httpMethods.add(HttpMethod.GET); } if (method.isAnnotationPresent(PUT.class)) { httpMethods.add(HttpMethod.PUT); } if (method.isAnnotationPresent(POST.class)) { httpMethods.add(HttpMethod.POST); } if (method.isAnnotationPresent(DELETE.class)) { httpMethods.add(HttpMethod.DELETE); } return ImmutableSet.copyOf(httpMethods); }
From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java
License:Open Source License
@Test public void testNonExistingEndPoints() throws IOException { HttpURLConnection urlConn = request("/test/v1/users", HttpMethod.POST); writeContent(urlConn, "data"); Assert.assertEquals(404, urlConn.getResponseCode()); urlConn.disconnect();/*from w w w .j a v a 2 s . co m*/ }
From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java
License:Open Source License
@Test public void testPostWithData() throws IOException { HttpURLConnection urlConn = request("/test/v1/facebook/1/message", HttpMethod.POST); writeContent(urlConn, "Hello, World"); Assert.assertEquals(200, urlConn.getResponseCode()); String content = getContent(urlConn); Map<String, String> map = GSON.fromJson(content, STRING_MAP_TYPE); Assert.assertEquals(1, map.size());//w ww. java2s .c o m Assert.assertEquals("Handled post in tweets end-point, id: 1. Content: Hello, World", map.get("result")); urlConn.disconnect(); }
From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java
License:Open Source License
public void testChunkResponse() throws IOException { HttpURLConnection urlConn = request("/test/v1/chunk", HttpMethod.POST); try {/* www. ja va 2s .c o m*/ writeContent(urlConn, "Testing message"); String response = getContent(urlConn); Assert.assertEquals("Testing message", response); } finally { urlConn.disconnect(); } }