package com.firstoption.webservice.impl.example; /** * WebserviceConsumptionExample.java * * Uses the WS implementation to create a ticket * * This is part of an example implementation for connecting to the * IssueCentre WebService APIs for version 2.0 of IssueCentre and should * not be relied upon to be production worthy code. * * This application consumes the webservices for IssueCentre using * the "generate web client" feature of the eclipse IDE to create the * intermediate classes.It uses the getContracts method of Connection, * to list the contracts, uses the first contract returned to login to * IssueCentreby calling generateKey then uses the key to log a ticket * into IssueCentre by calling the createTicket method of the Ticket * webservice. * */ import java.io.IOException; import java.io.StringReader; import java.rmi.RemoteException; import org.jdom.Attribute; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; public class WebserviceConsumptionExample { public static String username = "yourIssueCentreUsername"; public static String password = "yourIssueCentrePassword"; public static void main(String[] args) { //Setup the webservice objects ConnectionProxy connection = new ConnectionProxy(); connection.setEndpoint("http://YourIssueCentreServer/issuecentre/Connection"); TicketsProxy tickets = new TicketsProxy(); tickets.setEndpoint("http://YourIssueCentreServer/issuecentre/Ticket"); try { //Call the getContracts method with the username and password and store the response in the xml variable String xml = connection.getContracts(username, password); //Parse the xml variable into a document object Document d = new SAXBuilder().build(new StringReader(xml)); if (d.getRootElement().getAttribute("error").getIntValue() == 0) { //select out the first contracts id attribute int contractId = d.getRootElement().getChild("contracts").getChild("contract").getAttribute("id").getIntValue(); //call the generateKey method with the selected contractId xml = connection.generateKey(username, password, contractId); //Parse the xml variable into a document object d = new SAXBuilder().build(new StringReader(xml)); if (d.getRootElement().getAttribute("error").getIntValue() == 0) { //Select out the text of the root element (As it contains the key) String key = d.getRootElement().getText(); //Setup up the createTicket parameters int company = 0; //Company code (Customers.getCompanies()) int contact = 0; //Contact code (Customers.getContacts()) int product = 0; //Product code (Contracts.getProducts()) int productVersion = 0; //Product Version code (Contracts.getProducts()) int ticketStatus = 0; //Ticket Status code (Contracts.getStatusTypes()) int priority = 0; //Priority code (Contracts.getPriorities()) int platform = 0; //Platform code (Contracts.getProducts()) int platformVersion = 0; //Platform version code (Contracts.getProducts()) int errorType = 0; //Error type code (Contracts.getErrorTypes()) int receivedBy = 0; //received by method (Contracts.getReceivedByMethods()) int timeSpent = 0; //Number of seconds spent recording this ticket (For reporting) String supplierRef = ""; //Stored in the supplier reference field String clientRef = ""; //Stored in the client reference field String internalNotes = ""; //Agent only visible notes String issue = ""; //Issue description String summary = ""; //Short summary of issue //call the createTicket method with all the parameters xml = tickets.createTicket(key, company, contact, product, productVersion, ticketStatus, priority, supplierRef, clientRef, internalNotes, platform, platformVersion, errorType, receivedBy, issue, timeSpent, summary); //parse the response d = new SAXBuilder().build(new StringReader(xml)); int errorCode = d.getRootElement().getAttribute("error").getIntValue(); if (errorCode != 0) { String errorDesc = d.getRootElement().getText(); //Return error description to user } else { //return success message to user } } else { String errorDesc = d.getRootElement().getText(); //Return error description to user } } else { String errorDesc = d.getRootElement().getText(); //Return error description to user } } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }