Advertisement
Guest User

Comunio WebService Beispiel

a guest
Sep 16th, 2011
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package de.comunio.webservice.example;
  2.  
  3. import java.rmi.RemoteException;
  4. import java.util.HashMap;
  5.  
  6. import javax.xml.namespace.QName;
  7. import javax.xml.rpc.Call;
  8. import javax.xml.rpc.ServiceException;
  9.  
  10. import org.apache.axis.client.Service;
  11.  
  12. public class ComunioBeispiel {
  13.  
  14.     /**
  15.      * @param args
  16.      * @throws RemoteException
  17.      * @throws ServiceException
  18.      */
  19.     public static void main(String[] args) throws RemoteException, ServiceException {
  20.  
  21.         // Folgender Code beruft sich auf das Beispiel von
  22.         // http://axis.apache.org/axis/java/user-guide.html#ConsumingWebServicesWithAxis
  23.  
  24.         // Adresse des Comunio Webservice
  25.         String endpoint = "http://www.comunio.de/soapservice.php";
  26.  
  27.         Service service = new Service();
  28.         Call call = (Call) service.createCall();
  29.  
  30.         call.setTargetEndpointAddress(endpoint);
  31.  
  32.         // Methode angeben
  33.         call.setOperationName(new QName("getplayerbyid"));
  34.  
  35.         // ID von Mario Gomez
  36.         int playerID = 30517;
  37.  
  38.         // Aufruf oben spezifizierter Methode mit der ID von Gomez
  39.         // Man erhält eine HashMap (String -> Object)
  40.         @SuppressWarnings("unchecked")
  41.         HashMap<String, Object> map = (HashMap<String, Object>) call
  42.                 .invoke(new Object[] { playerID });
  43.  
  44.         // Oder einzelne Attribute auslesen
  45.         String name         = (String) map.get("name");
  46.         String position     = (String) map.get("position");
  47.         String statusInfo   = (String) map.get("status_info");
  48.         String status       = (String) map.get("status");
  49.         int marktwert       = (Integer) map.get("quote");
  50.         int punkte          = (Integer) map.get("points");
  51.  
  52.         // Ausgabe auf der Console
  53.         System.out.println("ID: " + playerID);
  54.         System.out.println("Name: " + name);
  55.         System.out.println("Position: " + position);
  56.         System.out.println("Status: " + status + " (" + statusInfo.trim() + ")");
  57.         System.out.println("Marktwert: " + marktwert);
  58.         System.out.println("Punkte: " + punkte + "\n");
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement