Search in sources :

Example 1 with XmlElement

use of org.xmlpull.v1.builder.XmlElement in project airavata by apache.

the class SimpleWSClient method sendSOAPMessage.

/**
 * @param wclient
 * @param args
 * @param opName
 * @return The output
 * @throws ComponentRegistryException
 */
public WSIFMessage sendSOAPMessage(WSIFClient wclient, Object[][] args, String opName) throws ComponentRegistryException {
    WSIFPort port = wclient.getPort();
    WSIFOperation operation = port.createOperation(opName);
    WSIFMessage outputMessage = operation.createOutputMessage();
    WSIFMessage faultMessage = operation.createFaultMessage();
    String messageName = operation.createInputMessage().getName();
    XmlElement inputMsgElem = builder.newFragment(this.requestNS, messageName);
    for (int i = 0; i < args.length; i++) {
        createMessage((String) args[i][0], args[i][1], inputMsgElem);
    }
    WSIFMessageElement inputMessage = new WSIFMessageElement(inputMsgElem);
    boolean success = operation.executeRequestResponseOperation(inputMessage, outputMessage, faultMessage);
    if (success) {
        logger.debug("" + outputMessage);
        return outputMessage;
    } else {
        throw new ComponentRegistryException("Excpetion at server " + faultMessage);
    }
}
Also used : WSIFMessageElement(xsul.wsif.impl.WSIFMessageElement) WSIFOperation(xsul.wsif.WSIFOperation) WSIFPort(xsul.wsif.WSIFPort) XmlElement(org.xmlpull.v1.builder.XmlElement) ComponentRegistryException(org.apache.airavata.workflow.model.component.ComponentRegistryException) WSIFMessage(xsul.wsif.WSIFMessage)

Example 2 with XmlElement

use of org.xmlpull.v1.builder.XmlElement in project airavata by apache.

the class GFacServiceCreator method createService.

/**
 * @param serviceQName
 * @return The WSDL definitions of the service created.
 * @throws WorkflowException
 */
public WsdlDefinitions createService(String serviceQName) throws WorkflowException {
    logger.debug(serviceQName);
    try {
        WSIFMessage inputMessage = this.gFacOperation.createInputMessage();
        WSIFMessage outputMessage = this.gFacOperation.createOutputMessage();
        WSIFMessage faultMessage = this.gFacOperation.createFaultMessage();
        inputMessage.setObjectPart(SERVICE_QNAME_PART, serviceQName);
        inputMessage.setObjectPart(SECURITY_PART, SECURITY_NONE);
        logger.debug("inputMessage: " + inputMessage);
        boolean success = this.gFacOperation.executeRequestResponseOperation(inputMessage, outputMessage, faultMessage);
        if (!success) {
            // An implementation of WSIFMessage, WSIFMessageElement,
            // implements toString(), which serialize the message XML.
            String message = "Failed to create a service: " + faultMessage.toString();
            throw new WorkflowException(message);
        }
        String wsdl = (String) outputMessage.getObjectPart(WSDL_PART);
        logger.debug("WSDL: " + wsdl);
        XmlElement definitionsElement = XMLUtil.stringToXmlElement3(wsdl);
        this.serviceDefinitions = new WsdlDefinitions(definitionsElement);
        return this.serviceDefinitions;
    } catch (RuntimeException e) {
        String message = "Failed to create a service";
        throw new WorkflowException(message, e);
    }
}
Also used : WsdlDefinitions(xsul.wsdl.WsdlDefinitions) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) XmlElement(org.xmlpull.v1.builder.XmlElement) WSIFMessage(xsul.wsif.WSIFMessage)

Example 3 with XmlElement

use of org.xmlpull.v1.builder.XmlElement in project airavata by apache.

the class GFacRegistryClient method findArrayValue.

private static ArrayList<String> findArrayValue(String name, WSIFMessageElement response) {
    XmlElement param = response.element(null, name);
    if (param != null) {
        Iterable it = param.elements(null, "value");
        if (it != null) {
            ArrayList<String> values = new ArrayList<String>();
            Iterator arrayValues = it.iterator();
            while (arrayValues.hasNext()) {
                values.add(((XmlElement) arrayValues.next()).requiredTextContent());
            }
            return values;
        }
    }
    return null;
}
Also used : Iterable(org.xmlpull.v1.builder.Iterable) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XmlElement(org.xmlpull.v1.builder.XmlElement)

Example 4 with XmlElement

use of org.xmlpull.v1.builder.XmlElement in project airavata by apache.

the class SimpleWSClient method createMessage.

private void createMessage(String paramName, Object value, XmlElement inputMsgElem) throws ComponentRegistryException {
    XmlElement paramsElem = builder.newFragment(this.requestNS, paramName);
    if (value instanceof String) {
        paramsElem.addChild(value);
    } else if (value instanceof Collection) {
        Collection list = (Collection) value;
        Iterator arrayValues = list.iterator();
        while (arrayValues.hasNext()) {
            XmlElement item = builder.newFragment("value");
            item.addChild(arrayValues.next());
            paramsElem.addChild(item);
        }
    } else if (value instanceof ArrayList) {
        Collection list = (Collection) value;
        Iterator arrayValues = list.iterator();
        while (arrayValues.hasNext()) {
            XmlElement item = builder.newFragment("value");
            item.addChild(arrayValues.next());
            paramsElem.addChild(item);
        }
    } else if (value instanceof String[]) {
        String[] list = (String[]) value;
        for (int i = 0; i < list.length; i++) {
            XmlElement item = builder.newFragment("value");
            item.addChild(list[i]);
            paramsElem.addChild(item);
        }
    } else {
        throw new ComponentRegistryException("Simple WS Client can not handle the value of type " + value);
    }
    inputMsgElem.addElement(paramsElem);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) XmlElement(org.xmlpull.v1.builder.XmlElement) Collection(java.util.Collection) ComponentRegistryException(org.apache.airavata.workflow.model.component.ComponentRegistryException)

Aggregations

XmlElement (org.xmlpull.v1.builder.XmlElement)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 ComponentRegistryException (org.apache.airavata.workflow.model.component.ComponentRegistryException)2 WSIFMessage (xsul.wsif.WSIFMessage)2 Collection (java.util.Collection)1 WorkflowException (org.apache.airavata.workflow.model.exceptions.WorkflowException)1 Iterable (org.xmlpull.v1.builder.Iterable)1 WsdlDefinitions (xsul.wsdl.WsdlDefinitions)1 WSIFOperation (xsul.wsif.WSIFOperation)1 WSIFPort (xsul.wsif.WSIFPort)1 WSIFMessageElement (xsul.wsif.impl.WSIFMessageElement)1