GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
what am i doing wrong?  XML
Forum Index -> General
Author Message
Anonymous



hello, i'm trying to make a little program and this web service should be perfect for me, so i've tryed to implement a java client for the service using AXIS but i'm getting this error:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Operation timed out: connect
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Opera
tion timed out: connect


and my code is:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

public class EjemploWS {
public EjemploWS() {}

public String ask() throws Exception {
String endpoint =
"http://ws.geonames.org/postalCodeSearch.jws";
Service service = new Service();
Call call = (Call)service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("postalCodeSearch");
call.addParameter("postalcode",
XMLType.XSD_STRING,ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);

String result = (String)call.invoke(new Object []
{"28933"});

return result;
}
}


What am i doing wrong??? Can somebody help me?

thanks
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

Hi

The geonames webserives follow the lightweight REST principle and you don't need a SOAP library to access it.
A simple java program will do the job : (with jdom.org for the xml parsing)

Code:
 	public static List<PostalCode> postalCodeSearch(String postalCode,
 			String placeName, String countryCode) throws Exception {
 		List<PostalCode> postalCodes = new ArrayList<PostalCode>();
 
 		String url = "http://ws.geonames.org/postalCodeSearch?";
 		if (postalCode != null) {
 			url = url + "postalcode=" + postalCode;
 		}
 		if (placeName != null) {
 			if (!url.endsWith("&")) {
 				url = url + "&";
 			}
 			url = url + "placename=" + URLEncoder.encode(placeName, "UTF8");
 		}
 		if (countryCode != null) {
 			if (!url.endsWith("&")) {
 				url = url + "&";
 			}
 			url = url + "country=" + countryCode;
 		}
 
 		URLConnection conn = new URL(url).openConnection();
 		conn.setRequestProperty("User-Agent", USER_AGENT);
 		SAXBuilder parser = new SAXBuilder();
 		Document doc = parser.build(conn.getInputStream());
 
 		Element root = doc.getRootElement();
 		for (Object obj : root.getChildren("code")) {
 			Element codeElement = (Element) obj;
 			PostalCode code = new PostalCode();
 			code.setPostalCode(codeElement.getChildText("postalcode"));
 			code.setPlaceName(codeElement.getChildText("name"));
 			code.setCountryCode(codeElement.getChildText("countryCode"));
 
 			code.setLatitude(Double
 					.parseDouble(codeElement.getChildText("lat")));
 			code.setLongitude(Double.parseDouble(codeElement
 					.getChildText("lng")));
 
 			postalCodes.add(code);
 		}
 
 		return postalCodes;
 	}
 

[WWW]
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team