Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Weather Web Service

http://ws.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP

http://ws.cdyne.com//WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416

--------------------------------------------------------------------



--------------------------------------------------------------------------

import java.net.*;
import java.io.*;

public class PostHTTPPost {

public static void main(String[] args) {

try {
//Create socket
String hostname = "ws.cdyne.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
//System.out.println("Connected");

String postdata = "ZIP" + "=" + URLEncoder.encode("55416", "UTF-8");
//System.out.println("length: " + postdata.length());

// Send header
String path = "//WeatherWS/Weather.asmx/GetCityWeatherByZIP";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF8"));
bw.write("POST " + path + " HTTP/1.0\r\n");
bw.write("Content-Length: " + postdata.length() + "\r\n");
bw.write("Content-Type: application/x-www-form-urlencoded\r\n");
bw.write("\r\n");

// Send POST data string
bw.write(postdata);
bw.flush();

// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);

//wr.close();
//br.close();

} catch (Exception e) {
//System.out.println("Usage: java TestHost www.igbmc.fr");
e.printStackTrace();
}
}
}

---------------------------------------------------------------------------

import java.net.*;
import java.io.*;

public class PostHTTPGet {

public static void main(String[] args) {

try {
//Create socket
String hostname = "ws.cdyne.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
//System.out.println("Connected");


//Send data
OutputStream theOutput = sock.getOutputStream();
PrintWriter pw = new PrintWriter(theOutput, false);
String file = "/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416";
pw.println("GET " + file + " HTTP/1.0");
//pw.println("Accept: text/plain, text/html, text/*");
pw.println();
pw.flush();

//wr.write("GET /WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416 HTTP/1.1\r\n");
//wr.write("Host: ws.cdyne.com\r\n");


// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);

//wr.close();
//br.close();

} catch (Exception e) {
//System.out.println("Usage: java TestHost www.igbmc.fr");
e.printStackTrace();
}
}
}

-------------------------------------------------------------------------------

import java.net.*;
import java.io.*;

public class PostHTTPSOAP11 {

public static void main(String[] args) {

try {
//Create socket
String hostname = "ws.cdyne.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
//System.out.println("Connected");

String xmldata = "" +
" "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"" +
"" +
"55416" +
"
" +
"
" +
"
";
//System.out.println("length: " + postdata.length());

// Send header
String path = "//WeatherWS/Weather.asmx";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF8"));
bw.write("POST " + path + " HTTP/1.0\r\n");
bw.write("Host: ws.cdyne.com\r\n");
bw.write("Content-Length: " + xmldata.length() + "\r\n");
bw.write("Content-Type: text/xml; charset=utf-8\r\n");
bw.write("\r\n");

// Send data
bw.write(xmldata);
bw.flush();

// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);

//wr.close();
//br.close();

} catch (Exception e) {
//System.out.println("Usage: java TestHost www.igbmc.fr");
e.printStackTrace();
}
}
}

Make Yahoo! Web Service REST Calls

http://developer.yahoo.com/java/howto-reqRestJava.html

Lire le source de pages web

http://www.enseignement.polytechnique.fr/informatique/profs/Laurent.Viennot/majReseau/2006-2007/td2/index.html


import java.net.*;
import java.io.*;

public class PostHTTPGet {

public static void main(String[] args) {

try {
//Create socket
String hostname = "ws.cdyne.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
//System.out.println("Connected");


//Send data
OutputStream theOutput = sock.getOutputStream();
PrintWriter pw = new PrintWriter(theOutput, false);
String file = "/";
pw.println("GET " + file + " HTTP/1.0");
//pw.println("Accept: text/plain, text/html, text/*");
pw.println();
pw.flush();

//wr.write("GET /WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416 HTTP/1.1\r\n");
//wr.write("Host: ws.cdyne.com\r\n");


// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);

//wr.close();
//br.close();

} catch (Exception e) {
//System.out.println("Usage: java TestHost www.igbmc.fr");
e.printStackTrace();
}
}
}

Install Java on Ubuntu 8.10 (Intrepid Ibex)


There are several ways of installing Java on the Ubuntu operating system. One of the easiest ways is to make use of apt-get command in Ubuntu. Before the command can be executed, a few steps needs to be followed.

Setup Repository

The apt-get command makes use of a source configuration file, which contains a list of the repositories the package manager should query to retrieve the correct package. The source configuration file is known as sources.list and is situated in the /etc/apt/sources.list location. The following command can be used to edit the source file to ensure the multiverse repository is included.

Code:


sudo gedit /etc/apt/sources.list

Ensure that the following two sources are added to the configuration file:

After the configuration file is updated, the package repository needs to updated with the following command:

Code:


sudo apt-get update


Install Java Package

After the package repository was successfully updated, the Sun Java packages can be installed on the Ubuntu system. The Sun Java packages consist of Java 5 and Java 6 packages. Depending on the version that is required, the list of packages specified below can be installed.

Java 5
The Java 5 packages available is listed as follows:

  • sun-java5-bin
  • sun-java5-fonts
  • sun-java5-plugin
  • sun-java5-demo
  • sun-java5-jdk
  • sun-java5-source
  • sun-java5-doc
  • sun-java5-jre
  • sun-java5-src

Java 6
The Java 6 packages available is listed as follows:

  • sun-java6-bin
  • sun-java6-javadb
  • sun-java6-plugin
  • sun-java6-demo
  • sun-java6-jdk
  • sun-java6-source
  • sun-java6-doc
  • sun-java6-jre
  • sun-java6-src
  • sun-java6-fonts
  • sun-java6-jre-headless

To install Java version 6, the following command needs to be executed:

Code:


sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin


Verify Java Installation

To verify that the correct version of java is installed the following command can be used:

Code:


java -version

This command will print the current version of java that is active. Should there be more than one version of Java be installed on the operating system, the following command can be used to list the available java versions:

Code:


update-java-alternatives -l

This command list all the available Java runtime environments on the Ubuntu system. To change from one version to another, the following command can be used:

Code:


sudo update-java-alternatives -s JRE Version

Example:
sudo update-java-alternatives -s java-6-sun


Source: http://www.javadesign.info/SystemsHardware/OS/Ubuntu/install-java-on-ubuntu


echo $JAVA_HOME

gedit /etc/csh.login
source /etc/csh.login