import
java.io.BufferedReader;
import
java.io.BufferedWriter;
import java.io.File;
import
java.io.FileWriter;
import
java.io.IOException;
import
java.io.InputStream;
import
java.io.InputStreamReader;
import
java.net.MalformedURLException;
import java.net.URL;
import
java.net.HttpURLConnection;
public class Test {
public static void main(String[]
args) {
BufferedWriter bw = null;
BufferedReader br = null;
String inputLine;
try {
//If you are
behind a proxy you should set the following settings.
//You can look my
other post to learn your own proxy infos
// System.setProperty("http.proxyHost",
"your proxy host");
// System.setProperty("http.proxyPort",
"your proxy port");
URL url = new URL("http://lesstalkmorecode.blogspot.com.tr/");
HttpURLConnection conn =
(HttpURLConnection) url.openConnection();
conn.setReadTimeout(10*1000);
conn.setConnectTimeout(5*1000);
InputStream in =
conn.getInputStream();
br = new BufferedReader(new
InputStreamReader(in));
String fileName = "/users/content.html";
File file = new File(fileName);
if (!file.exists())
file.createNewFile();
FileWriter fw = new
FileWriter(file.getAbsoluteFile());
bw = new
BufferedWriter(fw);
while ((inputLine =
br.readLine()) != null)
bw.write(inputLine);
} catch
(MalformedURLException e) {
//log
} catch (IOException e) {
//log
} finally {
try {
if(bw != null)
bw.close();
if(br != null)
br.close();
} catch (IOException e) {
//log
}
}
}
}
|
Tuesday
Get URL content
View your proxy settings
- Open Google Chrome enter below address in the bar:
- chrome://net-internals/#proxy
- Open cmd, write >> ipconfig /all
- See >> Windows IP Configuration >> Primary Dns Suffix
- Open Internet Explorer
- Internet Options >> Connections >> LAN Settings
- See from the pop-up address bar
- Open Mozilla Firefox enter below address in the bar:
- about:preferences#advanced
Address already in use: bind /127.0.0.1:9999
BUG:
While i'm trying to start JBOSS, i got following error.
Address already in use: bind /127.0.0.1:9999
FIX:
Open command prompt, then try netstat -aon.You will see the detail.
To kill the process try taskkill /f /pid PID.
While i'm trying to start JBOSS, i got following error.
Address already in use: bind /127.0.0.1:9999
FIX:
Open command prompt, then try netstat -aon.You will see the detail.
To kill the process try taskkill /f /pid PID.
Change Eclipse Theme
Restart eclipse.Then you can change theme:
Open Eclipse Menu -> Window -> Preference -> General -> Appearance
You can change background color:
Open Eclipse Menu -> Window -> Preference -> General -> Appearance -> Color Theme
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
BUG:
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
FIX:
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
FIX:
Download jaxws-rt-2.1.4.jar and copy
it under WEB-INF/lib
|
java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
BUG:
java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
FIX:
java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
FIX:
Download resolver.jar and copy it
under WEB-INF/lib
https://mvnrepository.com/artifact/com.sun.org.apache.xml.internal/resolver/20050927
|
Friday
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
BUG:
I was getting below error. I tried slf4j-api-1.7.5.jar, slf4j-api-1.6.1.jar but it didn't fix.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
FIX:
Use slf4j-jdk14 in addition to slf4j-api.
I was getting below error. I tried slf4j-api-1.7.5.jar, slf4j-api-1.6.1.jar but it didn't fix.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
FIX:
Use slf4j-jdk14 in addition to slf4j-api.
Download slf4j-jdk14-1.7.5.jar:
https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14/1.7.5
|
For maven:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.5</version>
</dependency>
|
Tuesday
JSON.simple (a simple Java library) example
In the output section you can find the details of the example.
- Download
json-simple-1.1.jar
|
For maven:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
|
OUTPUT:
--------------------createJsonText--------------------
{"PARAMETERS":[{"1":"Json 1. value"},{"2":"Json 2. value"},{"3":"Json 3. value"}],"ID":"ABCD"}
--------------------parseJsonText--------------------
ID: ABCD
PARAMETERS in order: 1. value = Json 1. value
PARAMETERS in order: 2. value = Json 2. value
PARAMETERS in order: 3. value = Json 3. value
|
import
org.json.simple.JSONArray;
import
org.json.simple.JSONObject;
import
org.json.simple.parser.JSONParser;
import
org.json.simple.parser.ParseException;
public class Test {
public static void main(String[]
args) throws ParseException {
Test t = new Test();
String jsonString =
t.createJsonText();
t.parseJsonText(jsonString);
}
@SuppressWarnings("unchecked")
public String
createJsonText(){
System.out.println("--------------------createJsonText--------------------");
JSONArray ja = new JSONArray();
for(int i = 1 ; i
< 4 ; i++) {
JSONObject paramsObj = new JSONObject();
paramsObj.put(i, "Json
" + i + ". value");
ja.add(paramsObj);
}
JSONObject mainObj = new JSONObject();
mainObj.put("ID", "ABCD");
mainObj.put("PARAMETERS", ja);
String jsonString =
mainObj.toJSONString();
System.out.println(jsonString);
return jsonString;
}
public void
parseJsonText(String jsonString) throws
ParseException {
System.out.println("--------------------parseJsonText--------------------");
JSONParser parser = new JSONParser();
JSONObject jo = (JSONObject)
parser.parse(jsonString);
System.out.println("ID:
" + (String) jo.get("ID"));
JSONArray msg1 = (JSONArray) jo.get("PARAMETERS");
if(msg1 != null) {
for (int i = 0; i < msg1.size(); i++) {
JSONObject jsonobject = (JSONObject) msg1.get(i);
System.out.println("PARAMETERS
in order: " + (i+1) + ". value = " + (String)jsonobject.get(""+(i+1)));
}
}
}
}
|
Friday
Check if a web service is accessible? Ping a host for availability.
This summary is not available. Please
click here to view the post.
Subscribe to:
Posts (Atom)