List of usage examples for org.apache.http.params CoreProtocolPNames USE_EXPECT_CONTINUE
String USE_EXPECT_CONTINUE
To view the source code for org.apache.http.params CoreProtocolPNames USE_EXPECT_CONTINUE.
Click Source Link
From source file:com.cloudhopper.sxmp.SubmitMain.java
static public void main(String[] args) throws Exception { String url = "http://localhost:9080/api/sxmp/1.0"; // create a submit request SubmitRequest submit = new SubmitRequest(); submit.setAccount(new Account("customer1", "password1")); submit.setDeliveryReport(Boolean.TRUE); MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404"); submit.setSourceAddress(sourceAddr); submit.setOperatorId(24);/*from w w w .j a v a 2 s. c om*/ MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+14155551212"); submit.setDestinationAddress(destAddr); submit.setText( "Test abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijbcdefghij", TextEncoding.UTF_8); //submit.setText("Hello World"); // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); long totalStart = System.currentTimeMillis(); int count = 1; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(submit)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:com.cloudhopper.sxmp.demo.SubmitMain.java
static public void main(String[] args) throws Exception { String url = "http://127.0.0.1:8080/api/sxmp/1.0"; String phone = "+14155551212"; int operator = 1; if (args.length > 0) url = args[0];/* w w w . j av a 2 s . c o m*/ if (args.length > 1) phone = args[1]; if (args.length > 2) operator = Integer.parseInt(args[2]); // create a submit request SubmitRequest submit = new SubmitRequest(); submit.setAccount(new Account("customer1", "password1")); submit.setDeliveryReport(Boolean.TRUE); MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404"); submit.setSourceAddress(sourceAddr); submit.setOperatorId(operator); submit.setPriority(Priority.URGENT); MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, phone); submit.setDestinationAddress(destAddr); submit.setText("Hello World"); // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); long totalStart = System.currentTimeMillis(); int count = 1; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(submit)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:com.cloudhopper.sxmp.DeliverMain.java
static public void main(String[] args) throws Exception { // create a deliver request DeliverRequest deliver = new DeliverRequest(); deliver.setAccount(new Account("customer1", "password1")); deliver.setOperatorId(2);/*www. j a v a 2 s. co m*/ MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+13135551212"); deliver.setSourceAddress(sourceAddr); MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.NETWORK, "55555"); deliver.setDestinationAddress(destAddr); deliver.setText( "This is a new message that I want to send that's a little larger than normal &!#@%20*()$#@!~"); // target url //String url = "http://localhost:9080/api/sxmp/1.0"; //String url = "http://lyn-stratus-001/api/sxmp/1.0"; //String url = "http://localhost:9080/api/sxmp/1.0"; //String strURL = "http://sfd-twtr-gw.cloudhopper.com/api/sxmp/1.0"; String url = "http://lyn-stratus-lab5:9080/api/sxmp/1.0"; // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); // convert request into a byte array //byte[] data = SxmpWriter.createByteArray(submit); //logger.debug(StringUtil.toHexString(data)); long totalStart = System.currentTimeMillis(); int count = 5000; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(deliver)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:net.vexelon.mobileops.MTLClient.java
/** * Initialize Http Client/* w ww.j av a 2s . c o m*/ */ private void initHttpClient() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.TRUE); params.setParameter(CoreProtocolPNames.USER_AGENT, HTTP_USER_AGENT); //params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8); httpClient = new DefaultHttpClient(params); httpCookieStore = new BasicCookieStore(); httpClient.setCookieStore(httpCookieStore); }
From source file:com.cloudhopper.sxmp.SxmpSender.java
static public Response send(String url, Request request, boolean shouldParseResponse) throws UnsupportedEncodingException, SxmpErrorException, IOException, SxmpParsingException, SAXException, ParserConfigurationException { // convert request into xml String requestXml = SxmpWriter.createString(request); String responseXml = null;//from w w w . j a v a 2s .com HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); long start = System.currentTimeMillis(); long stop = 0; logger.debug("Request XML:\n" + requestXml); // execute request try { HttpPost post = new HttpPost(url); StringEntity entity = new StringEntity(requestXml); // write old or new encoding? if (request.getVersion().equals(SxmpParser.VERSION_1_1)) { // v1.1 is utf-8 entity.setContentType("text/xml; charset=\"utf-8\""); } else { // v1.0 was 8859-1, though that's technically wrong // unspecified XML must be encoded in UTF-8 // maintained this way for backward compatibility entity.setContentType("text/xml; charset=\"iso-8859-1\""); } post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); // execute request (will throw exception if fails) responseXml = client.execute(post, responseHandler); stop = System.currentTimeMillis(); } finally { // clean up all resources client.getConnectionManager().shutdown(); } logger.debug("Response XML:\n" + responseXml); logger.debug("Response Time: " + (stop - start) + " ms"); // deliver responses sometimes aren't parseable since its acceptable // for delivery responses to merely return "OK" and an HTTP 200 error if (!shouldParseResponse) { return null; } else { // convert response xml into an object SxmpParser parser = new SxmpParser(SxmpParser.VERSION_1_0); // v1.0 data remains in ISO-8859-1, and responses are v1.0 ByteArrayInputStream bais = new ByteArrayInputStream(responseXml.getBytes("ISO-8859-1")); Operation op = parser.parse(bais); if (!(op instanceof Response)) { throw new SxmpErrorException(SxmpErrorCode.OPTYPE_MISMATCH, "Unexpected response class type parsed"); } return (Response) op; } }
From source file:org.sonatype.nexus.testsuite.deploy.nexus176.Nexus176DeployToInvalidRepoIT.java
@Test public void wagonDeployTest() throws Exception { Gav gav = new Gav(this.getTestId(), "simpleArtifact", "1.0.0", null, "xml", 0, new Date().getTime(), "Simple Test Artifact", false, null, false, null); // file to deploy File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension()); // url to upload to String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content"; // the method we are calling HttpPost filePost = new HttpPost(uploadURL); filePost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy); if (status != HttpStatus.SC_NOT_FOUND) { Assert.fail("Upload attempt should have returned a 400, it returned: " + status); }//from w w w .j a v a 2s . c o m boolean fileWasUploaded = true; try { // download it downloadArtifact(gav, "./target/downloaded-jars"); } catch (FileNotFoundException e) { fileWasUploaded = false; } Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded); }
From source file:org.openhab.binding.rwesmarthome.internal.communicator.util.HttpComponentsHelper.java
/** * prepare for the https connection// ww w . ja v a 2s . c o m * call this in the constructor of the class that does the connection if * it's used multiple times */ private void setup() { SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1)); params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf8"); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // set the user credentials for our site "example.com" credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT), new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere")); clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); context = new BasicHttpContext(); context.setAttribute("http.auth.credentials-provider", credentialsProvider); }
From source file:com.geeksville.location.LeonardoUpload.java
/** * Upload a flight to Leonardo//from w w w . ja v a 2 s. c o m * * @param username * @param password * @param postURL * @param shortFilename * @param igcFile * we will take care of closing this stram * @return null for success, otherwise a string description of the problem * @throws IOException */ public static String upload(String username, String password, String postURL, int competitionClass, String shortFilename, String igcFile, int connectionTimeout, int operationTimeout) throws IOException { // Strip off extension (leonado docs say they don't want it int i = shortFilename.lastIndexOf('.'); if (i >= 1) shortFilename = shortFilename.substring(0, i); String sCompetitionClass = String.valueOf(competitionClass); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeout); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, operationTimeout); HttpClient httpclient = new DefaultHttpClient(httpParameters); httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); HttpPost httppost = new HttpPost(postURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("user", username)); nameValuePairs.add(new BasicNameValuePair("pass", password)); nameValuePairs.add(new BasicNameValuePair("igcfn", shortFilename)); nameValuePairs.add(new BasicNameValuePair("Klasse", sCompetitionClass)); nameValuePairs.add(new BasicNameValuePair("IGCigcIGC", igcFile)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); String resp = EntityUtils.toString(entity); // An error looks like: // <html><body>problem<br>This is not a valid .igc // file</body></html> // Check for success if (resp.contains("flight scored")) resp = null; else { int bodLoc = resp.indexOf("<body>"); if (bodLoc >= 0) resp = resp.substring(bodLoc + 6); int probLoc = resp.indexOf("problem"); if (probLoc >= 0) resp = resp.substring(probLoc + 7); if (resp.startsWith("<br>")) resp = resp.substring(4); int markLoc = resp.indexOf('<'); if (markLoc >= 0) resp = resp.substring(0, markLoc); resp = resp.trim(); } return resp; }
From source file:com.extradea.framework.images.workers.DownloadWorker.java
public DownloadWorker() { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, 5000); client = new DefaultHttpClient(httpParams); client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); }