/** * Retrieve all entries from service. * * @return All entries of type Entry from the service. * @exception FailureFaultException If an error communication with the service occurs. */ public Entry[] retrieve() throws FailureFaultException { final String method = "retrieve"; OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace namespace = factory.createOMNamespace(SERVICE, method); // Create a request OMElement request = factory.createOMElement("RetrieveRequest", namespace); // Configure connection Options options = new Options(); options.setTo(new EndpointReference(url.toString())); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setAction(method); // Create a client try { ServiceClient client = new ServiceClient(); client.setOptions(options); // Try send request and receive response, could throw AxisFault OMElement response = client.sendReceive(request); // Debug printDebug("RESPONSE", response); // Parse and return result Entry[] result = XMLUtil.parseScores(response); return result; } catch (AxisFault e) { throw new FailureFaultException("Exception from service: ", e); } }
/** * Sends multiple entries of type Entry to the service. * * @param entries The entries to send. * @return The responses. * @exception FailureFaultException If an error communication with the service occurs. */ public String[] store(Entry[] entries) throws FailureFaultException { final String method = "store"; // Create a request OMElement request = XMLUtil.createScoreElements("StoreRequest", method, entries); // Print debug if system property "debug.messages" is set. printDebug("REQUEST", request); // Configure connection Options options = new Options(); options.setTo(new EndpointReference(url.toString())); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setAction(method); // Create a client try { ServiceClient client = new ServiceClient(); client.setOptions(options); // Could throw AxisFault OMElement response = client.sendReceive(request); // Debug printDebug("RESPONSE", response); // Return possible results from elements of type: // <xsd:element name="StoreResponse" type="tns:StoreResponseType"/> // StoreResponseType = <xsd:simpleType name="StoreResponseType"/> ArrayList<String> resultList = new ArrayList<String>(); @SuppressWarnings("unchecked") // Doesn't support generics Iterator<OMElement> elementIterator = response.getChildElements(); while (elementIterator.hasNext()) { OMElement ge = elementIterator.next(); @SuppressWarnings("unchecked") // Doesn't support generics Iterator<OMElement> it = ge.getChildElements(); String responseText = it.next().getText(); resultList.add(responseText); } String[] result = new String[resultList.size()]; resultList.toArray(result); return result; } catch (AxisFault e) { throw new FailureFaultException("Exception from service: ", e); } }