This article show you how to use Apache HttpClient to send HTTP GET/POST request. 1. Send HTTP GET Request HttpClient to send a HTTP GET request to get the Google’s search result. String url = "http://www.google.com/search?q=httpClient"; HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); // add… Continue Reading
http httpclient java networkIn this example, we will show you how to login a website via standard Java HttpsURLConnection. This technique should be working in most of the login form. Tools & Java Library used in this example Google Chrome Browser – Network tab to analyze HTTP request and response header fields. jsoup… Continue Reading
java network loginProblem Developing a search form with the Spring MVC framework. /WEB-INF/pages/tools/webserver.jsp – Spring mvc + form tag <form:form method="post" commandName="searchForm" action="${pageContext.request.contextPath}/tools/webserver/" class="navbar-form pull-left" id="search-form"> Type a website : <form:input path="domainName" type="text" width="165px" placeholder="example – google.com" /> <button type="submit" class="btn btn-top-margin">Search</button> </form:form> Spring Controller @Controller @RequestMapping(value = "/tools", method = RequestMethod.GET)… Continue Reading
spring mvcA funny Java example to create an ASCII art graphic. The concept is simple, get the image’s rgb color in “integer mode”, later, replace the color’s integer with ascii text. P.S This example is credit to this post and this post. ASCIIArt.java package com.mkyong; import java.awt.Font; import java.awt.Graphics; import… Continue Reading
ascii image javaNote This question is from JNP forum, asking how to calculate the depth of the entire XML document. To get the depth of a XML, just loop the node recursively, and compare the level, that’s all.Here is a DOM parser example to count and show the deepest level of an… Continue Reading
dom xmlHere’s my journey to install “New Relic for PHP” to monitor my WordPress’s blog performance. Below is my server environment : Operating system CentOS 6.x 64-bit, VPS with root access cPanel 11.x Apache version 2.x PHP version 5.3.13 WordPress 3.5.1 P.S The New Relic is a web application performance tool.… Continue Reading
newrelicUsing Spring Data MongoDB 1.2.1.RELEASE and Spring core 3.2.2.RELEASE, while system is starting, it hits some weird spring-asm IncompatibleClassChangeError errors : java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class pom.xml <properties> <spring.version>3.2.2.RELEASE</spring.version> <springdata.version>1.2.1.RELEASE</springdata.version> </properties> <dependencies> <!– Spring Core –> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> … Continue Reading
spring-dataA comma-separated values (CSV) file is just a normal plain-text file, store data in column by column, and split it by a separator (e.g comma “,”). For example : US,United States MY,Malaysia In this tutorial, we show you how to read, parse and print out the values from a csv… Continue Reading
cvs javaIn this article, we show you how to use the Locale class to play around the list of countries. P.S Tested with JDK 1.6 1. List of Countries The Locale.getISOCountries() will return a list of all 2-letter country codes defined in ISO 3166. ListCountry.java package com.webmitta.model; import java.util.Locale; … Continue Reading
java localeIn this tutorial, we show you how to backup and restore MongoDB with the commands : mongoexport and mongoimport. 1. Backup database with mongoexport Few examples to show you how to use the mongoexport to back up the database. Review some of the common use options. $ mongoexport Export MongoDB… Continue Reading
backup export import mongodbIn MongoDB, you can use GridFS to store binary files. In this tutorial, we show you how to use Spring Data’s GridFsTemplate to store / read image in / from MongoDB. 1. GridFS – Save example (Spring config in Annotation) Gat an image file and save it into MongoDB. SpringMongoConfig.java… Continue Reading
binary data gridfs mongodb spring-dataThe HttpURLConnection‘s follow redirect is just an indicator, in fact it won’t help you to do the “real” http redirection, you still need to handle it manually. URL obj = new URL(url); HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); conn.setInstanceFollowRedirects(true); //you still need to handle redirect manully. HttpURLConnection.setFollowRedirects(true); 1. Java Http Redirect… Continue Reading
http java networkThe JDK source code is packaged in a src.jar, and should be in the JDK/Home folder. However, some JDK versions in Mac OSX didn’t include the source code or Javadoc. Try find it : sudo find / -name src.jar If you couldn’t find the src.jar, then get it from Apple… Continue Reading
jdk mac source codeThis example shows you how to get the Http response header values in Java. 1. Get response header from url “mkyong.com” URL obj = new URL("http://mkyong.com"); URLConnection conn = obj.openConnection(); Map<String, List<String>> map = conn.getHeaderFields(); 2. Get key’s (“Server”) value from the headers. Map<String, List<String>> map = conn.getHeaderFields(); List<String> server… Continue Reading
http javaThis guide shows you how to enable authentication in MongoDB. The authentication is disabled by default. To configure it, you must first add a user to the “admin” database. > show dbs admin #add single user to this database testdb Note Users with normal access in “admin” database, HAVE read… Continue Reading
authentication mongodb