List of usage examples for io.netty.handler.codec.http HttpMethod PUT
HttpMethod PUT
To view the source code for io.netty.handler.codec.http HttpMethod PUT.
Click Source Link
From source file:org.vertx.java.core.http.impl.DefaultHttpServerRequest.java
License:Open Source License
@Override public HttpServerRequest expectMultiPart(boolean expect) { if (expect) { String contentType = request.headers().get(HttpHeaders.Names.CONTENT_TYPE); if (contentType != null) { HttpMethod method = request.getMethod(); String lowerCaseContentType = contentType.toLowerCase(); isURLEncoded = lowerCaseContentType .startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); if ((lowerCaseContentType.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA) || isURLEncoded) && (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH))) { decoder = new HttpPostRequestDecoder(new DataFactory(), request); }// w w w.j a v a 2 s .c o m } } else { decoder = null; } return this; }
From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestResponseHandler.java
License:Apache License
@Override protected boolean action(Channel channel, RestArgument ra, ACTIONS_TYPE act) { HttpTestRestR66Client.count.incrementAndGet(); boolean newMessage = false; switch (act) { case CreateTransfer: { // Continue with GetTransferInformation TransferRequestJsonPacket recv;// w ww .j av a 2 s . com try { recv = (TransferRequestJsonPacket) JsonPacket .createFromBuffer(JsonHandler.writeAsString(ra.getResults().get(0))); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return newMessage; } InformationJsonPacket node = new InformationJsonPacket(recv.getSpecialId(), false, recv.getRequested()); HttpTestRestR66Client.action(channel, HttpMethod.GET, RESTHANDLERS.Control.uri, node); newMessage = true; break; } case ExecuteBusiness: // End break; case ExportConfig: // no Import in automatic test break; case GetBandwidth: // End break; case GetInformation: // End break; case GetLog: // End break; case GetTransferInformation: { // Continue with Stop in StopOrCancelTransfer ObjectNode answer = (ObjectNode) ra.getResults().get(0); StopOrCancelJsonPacket node = new StopOrCancelJsonPacket(); node.setRequestUserPacket(); node.setStop(); node.setRequested(answer.path(DbTaskRunner.Columns.REQUESTED.name()).asText()); node.setRequester(answer.path(DbTaskRunner.Columns.REQUESTER.name()).asText()); node.setSpecialid(answer.path(DbTaskRunner.Columns.SPECIALID.name()).asLong()); HttpTestRestR66Client.action(channel, HttpMethod.PUT, RESTHANDLERS.Control.uri, node); newMessage = true; break; } case ImportConfig: // End break; case OPTIONS: break; case RestartTransfer: { // Continue with delete transfer RestartTransferJsonPacket recv; try { recv = (RestartTransferJsonPacket) JsonPacket .createFromBuffer(JsonHandler.writeAsString(ra.getResults().get(0))); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return newMessage; } try { HttpTestRestR66Client.deleteData(channel, recv.getRequested(), recv.getRequester(), recv.getSpecialid()); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } newMessage = true; break; } case SetBandwidth: { // Continue with GetBandwidth BandwidthJsonPacket recv; try { recv = (BandwidthJsonPacket) JsonPacket .createFromBuffer(JsonHandler.writeAsString(ra.getResults().get(0))); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return newMessage; } recv.setSetter(false); HttpTestRestR66Client.action(channel, HttpMethod.GET, RESTHANDLERS.Bandwidth.uri, recv); newMessage = true; break; } case ShutdownOrBlock: // End break; case StopOrCancelTransfer: { // Continue with RestartTransfer StopOrCancelJsonPacket recv; try { recv = (StopOrCancelJsonPacket) JsonPacket .createFromBuffer(JsonHandler.writeAsString(ra.getResults().get(0))); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return newMessage; } RestartTransferJsonPacket node = new RestartTransferJsonPacket(); node.setRequestUserPacket(); node.setRequested(recv.getRequested()); node.setRequester(recv.getRequester()); node.setSpecialid(recv.getSpecialid()); HttpTestRestR66Client.action(channel, HttpMethod.PUT, RESTHANDLERS.Control.uri, node); newMessage = true; break; } case GetStatus: break; default: break; } if (!newMessage) { WaarpSslUtility.closingSslChannel(channel); } return newMessage; }
From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java
License:Open Source License
/** * @param args//from w ww . j a v a 2 s.c om */ @SuppressWarnings("unused") public static void main(String[] args) { if (args.length > 2) { WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(WaarpLogLevel.DEBUG)); } else { WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(null)); } logger = WaarpLoggerFactory.getLogger(HttpTestRestR66Client.class); Configuration.configuration.setHOST_ID(hostid); if (args.length > 0) { NB = Integer.parseInt(args[0]); if (Configuration.configuration.getCLIENT_THREAD() < NB) { Configuration.configuration.setCLIENT_THREAD(NB + 1); } if (args.length > 1) { NBPERTHREAD = Integer.parseInt(args[1]); } } if (NB == 1 && NBPERTHREAD == 1) { DEBUG = true; } try { HttpTestR66PseudoMain.config = HttpTestR66PseudoMain.getTestConfiguration(); } catch (CryptoException e2) { // TODO Auto-generated catch block e2.printStackTrace(); return; } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); return; } if (HttpTestR66PseudoMain.config.REST_ADDRESS != null) { host = HttpTestR66PseudoMain.config.REST_ADDRESS; } String filename = keydesfilename; Configuration.configuration.setCryptoFile(filename); File keyfile = new File(filename); Des des = new Des(); try { des.setSecretKey(keyfile); } catch (CryptoException e) { logger.error("Unable to load CryptoKey from Config file"); return; } catch (IOException e) { logger.error("Unable to load CryptoKey from Config file"); return; } Configuration.configuration.setCryptoKey(des); HttpRestR66Handler.instantiateHandlers(HttpTestR66PseudoMain.config); // Configure the client. clientHelper = new HttpRestR66Client(baseURI, new HttpTestRestClientInitializer(null), Configuration.configuration.getCLIENT_THREAD(), Configuration.configuration.getTIMEOUTCON()); logger.warn("ClientHelper created"); try { try { long start = System.currentTimeMillis(); for (int i = 0; i < NBPERTHREAD; i++) { options(null); } long stop = System.currentTimeMillis(); long diff = stop - start == 0 ? 1 : stop - start; logger.warn("Options: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } count.set(0); long start = System.currentTimeMillis(); if (false) { for (RESTHANDLERS handler : HttpRestR66Handler.RESTHANDLERS.values()) { try { deleteData(handler); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } long stop = System.currentTimeMillis(); long diff = stop - start == 0 ? 1 : stop - start; if (false) { logger.warn("Delete: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); } count.set(0); start = System.currentTimeMillis(); for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) { if (methodHandler instanceof DataModelRestMethodHandler<?>) { RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath()); try { multiDataRequests(handler); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn("Create: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); count.set(0); start = System.currentTimeMillis(); for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) { if (methodHandler instanceof DataModelRestMethodHandler<?>) { RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath()); try { realAllData(handler); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn("ReadAll: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); count.set(0); start = System.currentTimeMillis(); for (int i = 0; i < NBPERTHREAD; i++) { try { multiDataRequests(RESTHANDLERS.DbTaskRunner); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn( "CreateMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); count.set(0); start = System.currentTimeMillis(); launchThreads(); stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn("CreateMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?" + count.get()); // Set usefull item first if (RestConfiguration.CRUD.UPDATE.isValid( HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) { String key = null, value = null; Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT); if (channel != null) { String buz = null; if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) { key = userAuthent; value = keyAuthent; // Need business buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>" + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>" + "<businessid>" + userAuthent + "</businessid></business>"; } else { // Need business buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>" + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>" + "<businessid>monadmin</businessid></business>"; } ObjectNode node = JsonHandler.createObjectNode(); node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz); logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri); RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null, JsonHandler.writeAsString(node)); try { future.await(); } catch (InterruptedException e) { } WaarpSslUtility.closingSslChannel(channel); } // Need Hostzz channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT); if (channel != null) { AbstractDbData dbData; dbData = new DbHostAuth(null, hostid, address, HttpTestR66PseudoMain.config.REST_PORT, false, hostkey.getBytes(), true, false); logger.warn("Send query: " + RESTHANDLERS.DbHostAuth.uri); RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.POST, host, RESTHANDLERS.DbHostAuth.uri, key, value, null, dbData.asJson()); try { future.await(); } catch (InterruptedException e) { } WaarpSslUtility.closingSslChannel(channel); } } // Other Command as actions count.set(0); start = System.currentTimeMillis(); for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) { if (methodHandler instanceof DataModelRestMethodHandler<?>) { RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath()); try { action(handler); } catch (HttpInvalidAuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } getStatus(); stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn( "Commands: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?" + count.get()); count.set(0); start = System.currentTimeMillis(); for (int i = 0; i < NBPERTHREAD; i++) { getStatus(); } stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn("GetStatusMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get()); count.set(0); isStatus = true; start = System.currentTimeMillis(); launchThreads(); stop = System.currentTimeMillis(); diff = stop - start == 0 ? 1 : stop - start; logger.warn("GetStatusMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?" + count.get()); // Clean if (RestConfiguration.CRUD.UPDATE.isValid( HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) { String key = null, value = null; Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT); if (channel != null) { if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) { key = userAuthent; value = keyAuthent; } // Reset business String buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>" + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid></business>"; ObjectNode node = JsonHandler.createObjectNode(); node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz); logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri); RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null, JsonHandler.writeAsString(node)); try { future.await(); } catch (InterruptedException e) { } WaarpSslUtility.closingSslChannel(channel); } // Remove Hostzz channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT); if (channel != null) { try { RestFuture future = deleteData(channel, RESTHANDLERS.DbHostAuth); try { future.await(); } catch (InterruptedException e) { } } catch (HttpInvalidAuthenticationException e1) { } WaarpSslUtility.closingSslChannel(channel); } // Shutdown channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT); if (channel != null) { ShutdownOrBlockJsonPacket shutd = new ShutdownOrBlockJsonPacket(); shutd.setRestartOrBlock(false); shutd.setShutdownOrBlock(true); shutd.setRequestUserPacket(LocalPacketFactory.SHUTDOWNPACKET); String pwd = "pwdhttp"; byte[] bpwd = FilesystemBasedDigest.passwdCrypt(pwd.getBytes(WaarpStringUtils.UTF8)); shutd.setKey(bpwd); logger.warn("Send query: " + RESTHANDLERS.Server.uri); RestFuture future = action(channel, HttpMethod.PUT, RESTHANDLERS.Server.uri, shutd); try { future.await(); } catch (InterruptedException e) { } WaarpSslUtility.closingSslChannel(channel); } } try { Thread.sleep(100); } catch (InterruptedException e1) { } } finally { logger.debug("ClientHelper closing"); clientHelper.closeAll(); logger.warn("ClientHelper closed"); } }
From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java
License:Open Source License
protected static RestFuture updateData(Channel channel, RestArgument arg) throws HttpInvalidAuthenticationException { logger.debug("Send query"); ObjectNode answer = arg.getAnswer(); String base = arg.getBaseUri(); String item = clientHelper.getPrimaryProperty(arg); RESTHANDLERS dbdata = clientHelper.getRestHandler(arg); String key = null, value = null; if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) { key = userAuthent;/*from w ww. java2s. co m*/ value = keyAuthent; } Map<String, String> args = null; if (base.equals(HttpRestR66Handler.RESTHANDLERS.DbTaskRunner.uri)) { args = new HashMap<String, String>(); args.put(DbTaskRunner.Columns.REQUESTER.name(), hostid); args.put(DbTaskRunner.Columns.REQUESTED.name(), hostid); args.put(Columns.OWNERREQ.name(), Configuration.configuration.getHOST_ID()); } // update answer.removeAll(); switch (dbdata) { case DbConfiguration: answer.put(DbConfiguration.Columns.READGLOBALLIMIT.name(), 0); break; case DbHostAuth: answer.put(DbHostAuth.Columns.PORT.name(), 100); break; case DbHostConfiguration: answer.put(DbHostConfiguration.Columns.OTHERS.name(), ""); break; case DbRule: answer.put(DbRule.Columns.MODETRANS.name(), 4); break; case DbTaskRunner: answer.put(DbTaskRunner.Columns.FILEINFO.name(), "New Fileinfo"); break; default: RestFuture future = channel.attr(HttpRestClientSimpleResponseHandler.RESTARGUMENT).get(); future.cancel(); WaarpSslUtility.closingSslChannel(channel); return future; } RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.PUT, host, base + "/" + item, key, value, args, JsonHandler.writeAsString(answer)); 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;// w w w. j av 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.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 a 2 s .c om 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 w w . ja v a 2 s . c om*/ 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.// w ww . ja v a2s . c om * * @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
protected void testStreamUpload(int size) throws IOException { //create a random file to be uploaded. File fname = tmpFolder.newFile(); RandomAccessFile randf = new RandomAccessFile(fname, "rw"); String contentStr = IntStream.range(0, size).mapToObj(value -> String.valueOf((int) (Math.random() * 1000))) .collect(Collectors.joining("")); randf.write(contentStr.getBytes(Charsets.UTF_8)); randf.close();//from w w w.j a va 2s. c om //test stream upload HttpURLConnection urlConn = request("/test/v1/stream/upload", HttpMethod.PUT); Files.copy(fname, urlConn.getOutputStream()); Assert.assertEquals(200, urlConn.getResponseCode()); String contentFromServer = getContent(urlConn); Assert.assertEquals(contentStr, contentFromServer); urlConn.disconnect(); }
From source file:org.wso2.carbon.mss.internal.router.HttpServerTest.java
License:Open Source License
public void testStreamUploadFailure() throws IOException { //create a random file to be uploaded. int size = 20 * 1024; File fname = tmpFolder.newFile(); RandomAccessFile randf = new RandomAccessFile(fname, "rw"); randf.setLength(size);/*w ww .java2 s. c o m*/ randf.close(); HttpURLConnection urlConn = request("/test/v1/stream/upload/fail", HttpMethod.PUT); Files.copy(fname, urlConn.getOutputStream()); Assert.assertEquals(500, urlConn.getResponseCode()); urlConn.disconnect(); }