import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMElement; import org.apache.axis2.AxisFault; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.databinding.types.Token; import org.wso2.repos.wso2.people.jonathan.flickr_wsdl.*; import javax.xml.namespace.QName; import java.rmi.RemoteException; import java.util.Iterator; import java.net.URL; public class Main { private static String key = "7e26c32c4caabf63b3bbd7f1d99aecb9"; private static String host = "api.flickr.com"; private static String port = "80"; public static void main(String[] args) throws Exception { String user_ID = args[0]; FlickrServiceStub flickrServiceStub = getStub(host, port); PeopleGetInfo peopleGetInfo = new PeopleGetInfo(); peopleGetInfo.setApi_key(key); peopleGetInfo.setUser_id(user_ID); System.out.println("User ID: " + user_ID); try { Rsp response = flickrServiceStub.flickrPeopleGetInfo(peopleGetInfo); StatType statType = response.getStat(); Token token = statType.getValue(); if (token.equals(StatType._ok)) { OMElement[] elements = response.getExtraElement(); for (int i = 0; i < elements.length; i++) { OMElement user = elements[i]; System.out.println("The Information of the following user was retrived"); OMAttribute omAttribute = user.getAttribute(new QName("id")); System.out.println("The ID of the person is : " + omAttribute.getAttributeValue() + ""); OMElement username = user.getFirstChildWithName(new QName("username")); System.out.println("The name of the person is : " + username.getText() + ""); OMElement realname = user.getFirstChildWithName(new QName("realname")); System.out.println("The real name of the person is : " + realname.getText() + ""); OMElement location = user.getFirstChildWithName(new QName("location")); System.out.println("The location of the person is : " + location.getText() + ""); OMElement photosurl = user.getFirstChildWithName(new QName("photosurl")); System.out.println("The photosurl is : " + photosurl.getText() + ""); OMElement profileurl = user.getFirstChildWithName(new QName("profileurl")); System.out.println("The profileurl is : " + profileurl.getText() + ""); System.out.println("Details of photos taken"); OMElement photos = user.getFirstChildWithName(new QName("photos")); OMElement firstdate = photos.getFirstChildWithName(new QName("firstdate")); System.out.println("The First photo was taken on : " + firstdate.getText() + ""); OMElement firstdatetaken = photos.getFirstChildWithName(new QName("firstdatetaken")); System.out.println("The firstdatetaken was taken on : " + firstdatetaken.getText() + ""); OMElement count = photos.getFirstChildWithName(new QName("count")); System.out.println("The number of photos : " + count.getText()); } } else { System.out.println("Got an error: " + processPeopleError(response.getErr())); } } catch (RemoteException e) { System.out.println(e.getMessage()); } } private static FlickrServiceStub getStub(String host, String port) throws AxisFault { FlickrServiceStub flickrServiceStub = null; ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null , null); String address = "http://" + host + ":" + port + "/services/rest/"; flickrServiceStub = new FlickrServiceStub(configurationContext, address); return flickrServiceStub; } private static String processPeopleError(Err_type0 error) { String output; output = "An error occuerd, while invoking the service."; String code = error.getCode(); if ("1".equals(code)) { output = output + "The user id passed did not match a Flickr user."; } else if ("100".equals(code)) { output = output + "The API key passed was not valid or has expired."; } else if ("105".equals(code)) { output = output + "The requested service is temporarily unavailable."; } else if ("111".equals(code)) { output = output + "The requested response format was not found."; } else if ("112".equals(code)) { output = output + "The requested method was not found."; } return output; } }