You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by re...@apache.org on 2015/03/19 14:43:46 UTC
[18/35] incubator-taverna-common-activities git commit: package names
changed to org.apache.taverna.*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/AddXMLSplitterEdit.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/AddXMLSplitterEdit.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/AddXMLSplitterEdit.java
new file mode 100644
index 0000000..77fb5d4
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/AddXMLSplitterEdit.java
@@ -0,0 +1,289 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.taverna.activities.wsdl.WSDLActivity;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.EventForwardingOutputPort;
+import net.sf.taverna.t2.workflowmodel.EventHandlingInputPort;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorOutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class AddXMLSplitterEdit implements Edit<Dataflow> {
+
+ private final Edits edits;
+ private final Activity<?> activity;
+ private final String portName;
+ private final boolean isInput;
+ private CompoundEdit compoundEdit1 = null;
+ private Edit<?> linkUpEdit;
+ private final Dataflow dataflow;
+ private boolean applied = false;
+
+ public AddXMLSplitterEdit(Dataflow dataflow, Activity<?> activity,
+ String portName, boolean isInput, Edits edits) {
+ this.dataflow = dataflow;
+ this.activity = activity;
+ this.portName = portName;
+ this.isInput = isInput;
+ this.edits = edits;
+ }
+
+ @Override
+ public Dataflow doEdit() throws EditException {
+ if (applied) throw new EditException("Edit has already been applied!");
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+
+ Activity<JsonNode> splitter = null;
+ String sourcePortName = "";
+ Processor sourceProcessor = null;
+ Activity<?> sourceActivity = null;
+
+ String sinkPortName = "";
+ Processor sinkProcessor = null;
+ Activity<?> sinkActivity = null;
+
+
+ Processor activityProcessor = findProcessorForActivity(dataflow,
+ activity);
+ if (activityProcessor == null) {
+ throw new EditException(
+ "Cannot find the processor that the activity belongs to");
+ }
+
+
+ String displayName = portName;
+ if (portName.equals("parameters")) {
+ displayName = isInput ? "input" : "output";
+ }
+ String processorName = activityProcessor.getLocalName();
+ String candidateName;
+ if (displayName.startsWith(processorName)) {
+ // No need to make GetRequest_GetRequestResponse
+ candidateName = displayName;
+ } else {
+ // Combine with processor name
+ String displayProcessorName;
+ if (activity instanceof XMLOutputSplitterActivity || activity instanceof XMLInputSplitterActivity) {
+ // For splitters on splitters - avoid adding up blah_bluh_blih_more_stuff
+ String[] processorNameSplit = processorName.replace("_input", "").replace("_output", "").split("_");
+ displayProcessorName = processorNameSplit[processorNameSplit.length-1];
+ } else {
+ displayProcessorName = activityProcessor.getLocalName();
+ }
+ candidateName = displayProcessorName + "_" + displayName;
+ }
+ String name = Tools.uniqueProcessorName(candidateName, dataflow);
+ Processor splitterProcessor = edits.createProcessor(name);
+
+ try {
+ if (activity instanceof XMLInputSplitterActivity) {
+ if (!isInput) {
+ throw new EditException(
+ "Can only add an input splitter to another input splitter");
+ }
+ TypeDescriptor descriptor = ((XMLInputSplitterActivity) activity)
+ .getTypeDescriptorForInputPort(portName);
+ if (descriptor instanceof ArrayTypeDescriptor && !((ArrayTypeDescriptor)descriptor).isWrapped()) {
+ descriptor=((ArrayTypeDescriptor)descriptor).getElementType();
+ }
+
+ JsonNode bean = XMLSplitterConfigurationBeanBuilder
+ .buildBeanForInput(descriptor);
+ splitter = new XMLInputSplitterActivity();
+ editList.add(edits.getConfigureActivityEdit(splitter, bean));
+
+ } else if (activity instanceof XMLOutputSplitterActivity) {
+ if (isInput) {
+ throw new EditException(
+ "Can only add an output splitter to another output splitter");
+ }
+ TypeDescriptor descriptor = ((XMLOutputSplitterActivity) activity)
+ .getTypeDescriptorForOutputPort(portName);
+
+ if (descriptor instanceof ArrayTypeDescriptor && !((ArrayTypeDescriptor)descriptor).isWrapped()) {
+ descriptor=((ArrayTypeDescriptor)descriptor).getElementType();
+ }
+
+ JsonNode bean = XMLSplitterConfigurationBeanBuilder
+ .buildBeanForOutput(descriptor);
+ splitter = new XMLOutputSplitterActivity();
+ editList.add(edits.getConfigureActivityEdit(splitter, bean));
+
+ } else if (activity instanceof WSDLActivity) {
+ if (isInput) {
+ TypeDescriptor descriptor = ((WSDLActivity) activity)
+ .getTypeDescriptorForInputPort(portName);
+ JsonNode bean = XMLSplitterConfigurationBeanBuilder
+ .buildBeanForInput(descriptor);
+ splitter = new XMLInputSplitterActivity();
+ editList
+ .add(edits.getConfigureActivityEdit(splitter, bean));
+ } else {
+ TypeDescriptor descriptor = ((WSDLActivity) activity)
+ .getTypeDescriptorForOutputPort(portName);
+ JsonNode bean = XMLSplitterConfigurationBeanBuilder
+ .buildBeanForOutput(descriptor);
+ splitter = new XMLOutputSplitterActivity();
+ editList
+ .add(edits.getConfigureActivityEdit(splitter, bean));
+ }
+ } else {
+ throw new EditException(
+ "The activity type is not suitable for adding xml processing processors");
+ }
+ } catch (Exception e) {
+ throw new EditException(
+ "An error occured whilst tyring to add an XMLSplitter to the activity:"
+ + activity, e);
+ }
+
+ if (isInput) {
+ sourcePortName = "output";
+ sinkPortName = portName;
+ sinkProcessor = activityProcessor;
+ sinkActivity = activity;
+ sourceProcessor = splitterProcessor;
+ sourceActivity = splitter;
+ }
+ else {
+ sourcePortName = portName;
+ sinkPortName = "input";
+ sinkProcessor = splitterProcessor;
+ sinkActivity = splitter;
+ sourceProcessor = activityProcessor;
+ sourceActivity = activity;
+ }
+
+ editList.add(edits.getDefaultDispatchStackEdit(splitterProcessor));
+ editList.add(edits.getAddActivityEdit(splitterProcessor, splitter));
+// editList.add(edits
+// .getMapProcessorPortsForActivityEdit(splitterProcessor));
+ editList.add(edits.getAddProcessorEdit(dataflow, splitterProcessor));
+
+ compoundEdit1 = new CompoundEdit(editList);
+ compoundEdit1.doEdit();
+
+ List<Edit<?>> linkUpEditList = new ArrayList<Edit<?>>();
+
+ EventForwardingOutputPort source = getSourcePort(sourceProcessor, sourceActivity,
+ sourcePortName, linkUpEditList);
+ EventHandlingInputPort sink = getSinkPort(sinkProcessor, sinkActivity, sinkPortName, linkUpEditList);
+
+ if (source == null)
+ throw new EditException(
+ "Unable to find the source port when linking up "
+ + sourcePortName + " to " + sinkPortName);
+ if (sink == null)
+ throw new EditException(
+ "Unable to find the sink port when linking up "
+ + sourcePortName + " to " + sinkPortName);
+
+ linkUpEditList.add(net.sf.taverna.t2.workflowmodel.utils.Tools.getCreateAndConnectDatalinkEdit(dataflow, source, sink, edits));
+
+ linkUpEdit = new CompoundEdit(linkUpEditList);
+ linkUpEdit.doEdit();
+ applied = true;
+ return dataflow;
+ }
+
+ private EventHandlingInputPort getSinkPort(Processor processor, Activity<?> activity,
+ String portName, List<Edit<?>> editList) {
+ InputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools.getActivityInputPort(activity, portName);
+ //check if processor port exists
+ EventHandlingInputPort input = net.sf.taverna.t2.workflowmodel.utils.Tools.getProcessorInputPort(processor, activity, activityPort);
+ if (input == null) {
+ //port doesn't exist so create a processor port and map it
+ ProcessorInputPort processorInputPort =
+ edits.createProcessorInputPort(processor, activityPort.getName(), activityPort.getDepth());
+ editList.add(edits.getAddProcessorInputPortEdit(processor, processorInputPort));
+ editList.add(edits.getAddActivityInputPortMappingEdit(activity, activityPort.getName(), activityPort.getName()));
+ input = processorInputPort;
+ }
+ return input;
+ }
+
+ private EventForwardingOutputPort getSourcePort(Processor processor, Activity<?> activity,
+ String portName, List<Edit<?>> editList) {
+ OutputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools.getActivityOutputPort(activity, portName);
+ //check if processor port exists
+ EventForwardingOutputPort output = net.sf.taverna.t2.workflowmodel.utils.Tools.getProcessorOutputPort(processor, activity, activityPort);
+ if (output == null) {
+ //port doesn't exist so create a processor port and map it
+ ProcessorOutputPort processorOutputPort =
+ edits.createProcessorOutputPort(processor, activityPort.getName(), activityPort.getDepth(), activityPort.getGranularDepth());
+ editList.add(edits.getAddProcessorOutputPortEdit(processor, processorOutputPort));
+ editList.add(edits.getAddActivityOutputPortMappingEdit(activity, activityPort.getName(), activityPort.getName()));
+ output = processorOutputPort;
+ }
+ return output;
+ }
+
+ @Override
+ public void undo() {
+ if (!applied) {
+ throw new RuntimeException(
+ "Attempt to undo edit that was never applied");
+ }
+ if (linkUpEdit.isApplied())
+ linkUpEdit.undo();
+ if (compoundEdit1.isApplied())
+ compoundEdit1.undo();
+ applied = false;
+ }
+
+ @Override
+ public boolean isApplied() {
+ return applied;
+ }
+
+ private Processor findProcessorForActivity(Dataflow dataflow,
+ Activity<?> activity) {
+ for (Processor p : dataflow.getProcessors()) {
+ for (Activity<?> a : p.getActivityList()) {
+ if (a == activity)
+ return p;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Object getSubject() {
+ return dataflow;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivity.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivity.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivity.java
new file mode 100644
index 0000000..a4752d4
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivity.java
@@ -0,0 +1,193 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.taverna.activities.wsdl.InputPortTypeDescriptorActivity;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
+import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.xmlsplitter.XMLInputSplitter;
+import org.apache.taverna.wsdl.xmlsplitter.XMLSplitterSerialisationHelper;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+/**
+ * An activity that replicates the behaviour of the Taverna 1 XMLInputSplitters.
+ *
+ * @author Stuart Owen
+ *
+ */
+public class XMLInputSplitterActivity extends AbstractAsynchronousActivity<JsonNode> implements InputPortTypeDescriptorActivity {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/xml-splitter/in";
+
+ JsonNode configBean;
+ TypeDescriptor typeDescriptor;
+
+ @Override
+ public void configure(JsonNode configBean) throws ActivityConfigurationException {
+ this.configBean = configBean;
+
+ String wrappedType = configBean.get("wrappedType").textValue();
+ Element element;
+ try {
+ element = new SAXBuilder().build(new StringReader(wrappedType)).getRootElement();
+ } catch (JDOMException e) {
+ throw new ActivityConfigurationException("Error reading xml for XMLInputSplitter",e);
+ } catch (IOException e) {
+ throw new ActivityConfigurationException("Error reading xml for XMLInputSplitter",e);
+ }
+ typeDescriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
+
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return configBean;
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ ReferenceService referenceService = callback.getContext().getReferenceService();
+ XMLInputSplitter splitter = createSplitter();
+ Map<String,Object> inputMap = buildInputMap(data,referenceService);
+ Map<String,String> outputMap = splitter.execute(inputMap);
+ callback.receiveResult(createOutputData(outputMap,referenceService), new int[0]);
+ }
+ catch(Exception e) {
+ callback.fail("Error in XMLInputSplitterActivity",e);
+ }
+ }
+
+ private Map<String, T2Reference> createOutputData(
+ Map<String, String> outputMap,ReferenceService referenceService) throws ReferenceServiceException {
+ Map<String,T2Reference> result = new HashMap<String, T2Reference>();
+ for (String outputName : outputMap.keySet()) {
+ String xmlOut = outputMap.get(outputName);
+ result.put(outputName, referenceService.register(xmlOut, 0, true, callback.getContext()));
+ }
+ return result;
+ }
+
+ private XMLInputSplitter createSplitter() {
+ List<String> inputNames = new ArrayList<String>();
+ List<String> inputTypes = new ArrayList<String>();
+ List<String> outputNames = new ArrayList<String>();
+
+ //FIXME: need to use the definition beans for now to get the mimetype. Need to use the actual InputPort once the mimetype becomes available again.
+ if (configBean.has("inputPorts")) {
+// for (JsonNode inputPort : configBean.get("inputPorts")) {
+ for (Iterator<JsonNode> iter = configBean.get("inputPorts").iterator();iter.hasNext();) {
+ JsonNode inputPort = iter.next();
+ inputNames.add(inputPort.get("name").textValue());
+ inputTypes.add(inputPort.get("mimeType").textValue());
+ }
+ }
+
+ for (OutputPort outputPorts : getOutputPorts()) {
+ outputNames.add(outputPorts.getName());
+ }
+
+ return new XMLInputSplitter(typeDescriptor,inputNames.toArray(new String[]{}),inputTypes.toArray(new String[]{}),outputNames.toArray(new String[]{}));
+ }
+
+ private Map<String,Object> buildInputMap(Map<String, T2Reference> data,ReferenceService referenceService) throws ReferenceServiceException {
+ Map<String,Object> result = new HashMap<String, Object>();
+ for (String inputName : data.keySet()) {
+ T2Reference id = data.get(inputName);
+ result.put(inputName, referenceService.renderIdentifier(id,String.class, callback.getContext()));
+
+ }
+ return result;
+ }
+ });
+
+ }
+
+ /**
+ * Returns a TypeDescriptor for the given port name. If the port cannot be found, or is not based upon a complex type, then null is returned.
+ * @param portName
+ * @return
+ */
+ @Override
+ public TypeDescriptor getTypeDescriptorForInputPort(String portName) {
+ TypeDescriptor result = null;
+ if (typeDescriptor instanceof ComplexTypeDescriptor) {
+ for (TypeDescriptor desc : ((ComplexTypeDescriptor)typeDescriptor).getElements()) {
+ if (desc.getName().equals(portName)) {
+ result = desc;
+ break;
+ }
+ }
+ }
+ else if (typeDescriptor instanceof ArrayTypeDescriptor) {
+ TypeDescriptor desc = ((ArrayTypeDescriptor)typeDescriptor).getElementType();
+
+ if (typeDescriptor.getName().equals(portName)) {
+ result = desc;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ */
+ public Map<String, TypeDescriptor> getTypeDescriptorsForInputPorts()
+ throws UnknownOperationException, IOException {
+ Map<String, TypeDescriptor> descriptors = new HashMap<String, TypeDescriptor>();
+ if (typeDescriptor instanceof ComplexTypeDescriptor) {
+ for (TypeDescriptor desc : ((ComplexTypeDescriptor)typeDescriptor).getElements()) {
+ descriptors.put(desc.getName(), desc);
+ }
+ }
+ else if (typeDescriptor instanceof ArrayTypeDescriptor) {
+ TypeDescriptor desc = ((ArrayTypeDescriptor)typeDescriptor).getElementType();
+ descriptors.put(typeDescriptor.getName(), desc);
+ }
+ return descriptors;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivityFactory.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivityFactory.java
new file mode 100644
index 0000000..34fbbff
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterActivityFactory.java
@@ -0,0 +1,100 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Iterator;
+
+/**
+ * An {@link ActivityFactory} for creating <code>XMLInputSplitterActivity</code>.
+ *
+ * @author David Withers
+ */
+public class XMLInputSplitterActivityFactory implements ActivityFactory {
+
+ private Edits edits;
+
+ @Override
+ public XMLInputSplitterActivity createActivity() {
+ return new XMLInputSplitterActivity();
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(XMLInputSplitterActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/xml-splitter.schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ Set<ActivityInputPort> inputPorts = new HashSet<>();
+ if (configuration.has("inputPorts")) {
+// for (JsonNode inputPort : configuration.get("inputPorts")) {
+ for (Iterator<JsonNode> iter = configuration.get("inputPorts").iterator();iter.hasNext();) {
+ JsonNode inputPort = iter.next();
+ inputPorts.add(edits.createActivityInputPort(inputPort.get("name").textValue(),
+ inputPort.get("depth").intValue(), false, null, String.class));
+ }
+ }
+ return inputPorts;
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ Set<ActivityOutputPort> outputPorts = new HashSet<>();
+ if (configuration.has("outputPorts")) {
+// for (JsonNode outputPort : configuration.get("outputPorts")) {
+ for (Iterator<JsonNode> iter = configuration.get("outputPorts").iterator();iter.hasNext();) {
+ JsonNode outputPort = iter.next();
+ outputPorts.add(edits.createActivityOutputPort(outputPort.get("name").textValue(),
+ outputPort.get("depth").intValue(), outputPort.get("granularDepth").intValue()));
+ }
+ }
+ return outputPorts;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterHealthChecker.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterHealthChecker.java
new file mode 100644
index 0000000..7b26fbf
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLInputSplitterHealthChecker.java
@@ -0,0 +1,64 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+import org.apache.taverna.wsdl.xmlsplitter.XMLSplitterSerialisationHelper;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+public class XMLInputSplitterHealthChecker implements HealthChecker<XMLInputSplitterActivity> {
+
+ public boolean canVisit(Object subject) {
+ return subject!=null && subject instanceof XMLInputSplitterActivity;
+ }
+
+ public VisitReport visit(XMLInputSplitterActivity activity, List<Object> ancestors) {
+ Element element;
+ try {
+ String wrappedType = activity.getConfiguration().get("wrappedType").textValue();
+ element = new SAXBuilder().build(new StringReader(wrappedType)).getRootElement();
+ } catch (JDOMException | IOException e) {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Error reading wrapped type", HealthCheck.INVALID_CONFIGURATION, Status.SEVERE);
+ }
+ TypeDescriptor typeDescriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
+ if (typeDescriptor==null) {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Unknown datatype for port", HealthCheck.NULL_DATATYPE, Status.SEVERE);
+ }
+ else {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Recognized datatype", HealthCheck.NO_PROBLEM, Status.OK);
+ }
+ }
+
+ public boolean isTimeConsuming() {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivity.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivity.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivity.java
new file mode 100644
index 0000000..d505f2b
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivity.java
@@ -0,0 +1,210 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.taverna.activities.wsdl.OutputPortTypeDescriptorActivity;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
+import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+import org.apache.taverna.wsdl.parser.UnknownOperationException;
+import org.apache.taverna.wsdl.xmlsplitter.XMLOutputSplitter;
+import org.apache.taverna.wsdl.xmlsplitter.XMLSplitterSerialisationHelper;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Iterator;
+
+/**
+ * An activity that replicates the behaviour of the Taverna 1 XMLOutputSplitter.
+ *
+ * @author Stuart Owen
+ *
+ */
+public class XMLOutputSplitterActivity extends
+ AbstractAsynchronousActivity<JsonNode> implements
+ OutputPortTypeDescriptorActivity {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/xml-splitter/out";
+
+ JsonNode configBean;
+ TypeDescriptor typeDescriptor;
+
+ @Override
+ public void configure(JsonNode configBean)
+ throws ActivityConfigurationException {
+ this.configBean = configBean;
+
+ try {
+ String wrappedType = configBean.get("wrappedType").textValue();
+ Element element = new SAXBuilder().build(new StringReader(wrappedType)).getRootElement();
+ typeDescriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
+ } catch (JDOMException | IOException e) {
+ throw new ActivityConfigurationException(e);
+ }
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ public void run() {
+ try {
+ ReferenceService referenceService = callback.getContext()
+ .getReferenceService();
+ XMLOutputSplitter splitter = createSplitter();
+ Map<String, String> inputMap = buildInputMap(data,
+ referenceService);
+ Map<String, Object> outputMap = splitter.execute(inputMap);
+ callback.receiveResult(createOutputData(outputMap,
+ referenceService), new int[0]);
+ } catch (Exception e) {
+ callback.fail("Error in XMLInputSplitterActivity", e);
+ }
+ }
+
+ private Map<String, T2Reference> createOutputData(
+ Map<String, Object> outputMap,
+ ReferenceService referenceService)
+ throws ReferenceServiceException {
+ Map<String, T2Reference> result = new HashMap<String, T2Reference>();
+ for (String outputName : outputMap.keySet()) {
+ Object output = outputMap.get(outputName);
+ // TODO check if the output can be anything other than
+ // String or List
+ if (output instanceof List) {
+ result.put(outputName, referenceService.register(
+ output, 1, true, callback.getContext()));
+ } else {
+ result.put(outputName, referenceService.register(
+ output, 0, true, callback.getContext()));
+ }
+ }
+ return result;
+ }
+
+ private XMLOutputSplitter createSplitter() {
+ List<String> inputNames = new ArrayList<String>();
+ List<String> outputTypes = new ArrayList<String>();
+ List<String> outputNames = new ArrayList<String>();
+
+ // FIXME: need to use the definition beans for now to get the
+ // mimetype. Need to use the actual InputPort once the mimetype
+ // becomes available again.
+ if (configBean.has("outputPorts")) {
+// for (JsonNode outputPort : configBean.get("outputPorts")) {
+ for (Iterator<JsonNode> iter = configBean.get("outputPorts").iterator();iter.hasNext();) {
+ JsonNode outputPort = iter.next();
+ outputNames.add(outputPort.get("name").textValue());
+ outputTypes.add(outputPort.get("mimeType").textValue());
+ }
+ }
+
+ for (InputPort outputPorts : getInputPorts()) {
+ inputNames.add(outputPorts.getName());
+ }
+
+ return new XMLOutputSplitter(typeDescriptor, outputNames
+ .toArray(new String[] {}), outputTypes
+ .toArray(new String[] {}), inputNames
+ .toArray(new String[] {}));
+ }
+
+ private Map<String, String> buildInputMap(
+ Map<String, T2Reference> data,
+ ReferenceService referenceService)
+ throws ReferenceServiceException {
+ Map<String, String> result = new HashMap<String, String>();
+ for (String inputName : data.keySet()) {
+ T2Reference id = data.get(inputName);
+ result.put(inputName, (String) referenceService
+ .renderIdentifier(id, String.class, callback
+ .getContext()));
+
+ }
+ return result;
+ }
+ });
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return configBean;
+ }
+
+ public TypeDescriptor getTypeDescriptorForOutputPort(String portName) {
+ TypeDescriptor result = null;
+ if (typeDescriptor instanceof ComplexTypeDescriptor) {
+ for (TypeDescriptor desc : ((ComplexTypeDescriptor) typeDescriptor)
+ .getElements()) {
+ if (desc.getName().equals(portName)) {
+ result = desc;
+ break;
+ }
+ }
+ }
+ else if (typeDescriptor instanceof ArrayTypeDescriptor) {
+ TypeDescriptor desc = ((ArrayTypeDescriptor)typeDescriptor).getElementType();
+
+ if (typeDescriptor.getName().equals(portName)) {
+ result = desc;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ */
+ @Override
+ public Map<String, TypeDescriptor> getTypeDescriptorsForOutputPorts()
+ throws UnknownOperationException, IOException {
+ Map<String, TypeDescriptor> descriptors = new HashMap<String, TypeDescriptor>();
+ if (typeDescriptor instanceof ComplexTypeDescriptor) {
+ for (TypeDescriptor desc : ((ComplexTypeDescriptor) typeDescriptor)
+ .getElements()) {
+ descriptors.put(desc.getName(), desc);
+ }
+ }
+ else if (typeDescriptor instanceof ArrayTypeDescriptor) {
+ TypeDescriptor desc = ((ArrayTypeDescriptor)typeDescriptor).getElementType();
+ descriptors.put(typeDescriptor.getName(), desc);
+ }
+ return descriptors;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivityFactory.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivityFactory.java
new file mode 100644
index 0000000..3d3a646
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterActivityFactory.java
@@ -0,0 +1,100 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Iterator;
+
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+/**
+ * An {@link ActivityFactory} for creating <code>XMLOutputSplitterActivity</code>.
+ *
+ * @author David Withers
+ */
+public class XMLOutputSplitterActivityFactory implements ActivityFactory {
+
+ private Edits edits;
+
+ @Override
+ public XMLOutputSplitterActivity createActivity() {
+ return new XMLOutputSplitterActivity();
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(XMLOutputSplitterActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/xml-splitter.schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ Set<ActivityInputPort> inputPorts = new HashSet<>();
+ if (configuration.has("inputPorts")) {
+// for (JsonNode inputPort : configuration.get("inputPorts")) {
+ for (Iterator<JsonNode> iter = configuration.get("inputPorts").iterator();iter.hasNext();) {
+ JsonNode inputPort = iter.next();
+ inputPorts.add(edits.createActivityInputPort(inputPort.get("name").textValue(),
+ inputPort.get("depth").intValue(), false, null, String.class));
+ }
+ }
+ return inputPorts;
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ Set<ActivityOutputPort> outputPorts = new HashSet<>();
+ if (configuration.has("outputPorts")) {
+// for (JsonNode outputPort : configuration.get("outputPorts")) {
+ for (Iterator<JsonNode> iter = configuration.get("outputPorts").iterator();iter.hasNext();) {
+ JsonNode outputPort = iter.next();
+ outputPorts.add(edits.createActivityOutputPort(outputPort.get("name").textValue(),
+ outputPort.get("depth").intValue(), outputPort.get("granularDepth").intValue()));
+ }
+ }
+ return outputPorts;
+ }
+
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterHealthChecker.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterHealthChecker.java
new file mode 100644
index 0000000..3e0910b
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLOutputSplitterHealthChecker.java
@@ -0,0 +1,64 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+import org.apache.taverna.wsdl.xmlsplitter.XMLSplitterSerialisationHelper;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+public class XMLOutputSplitterHealthChecker implements HealthChecker<XMLOutputSplitterActivity> {
+
+ public boolean canVisit(Object subject) {
+ return subject!=null && subject instanceof XMLOutputSplitterActivity;
+ }
+
+ public VisitReport visit(XMLOutputSplitterActivity activity, List<Object> ancestors) {
+ Element element;
+ try {
+ String wrappedType = activity.getConfiguration().get("wrappedType").textValue();
+ element = new SAXBuilder().build(new StringReader(wrappedType)).getRootElement();
+ } catch (JDOMException | IOException e) {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Error reading wrapped type", HealthCheck.INVALID_CONFIGURATION, Status.SEVERE);
+ }
+ TypeDescriptor typeDescriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
+ if (typeDescriptor==null) {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Unknown datatype for port", HealthCheck.NULL_DATATYPE, Status.SEVERE);
+ }
+ else {
+ return new VisitReport(HealthCheck.getInstance(), activity, "Recognized datatype", HealthCheck.NO_PROBLEM, Status.OK);
+ }
+ }
+
+ public boolean isTimeConsuming() {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBean.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBean.java
new file mode 100644
index 0000000..e91a60c
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBean.java
@@ -0,0 +1,41 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import org.jdom.Element;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityPortsDefinitionBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+@ConfigurationBean(uri = "http://ns.taverna.org.uk/2010/activity/xml-splitter#Config")
+public class XMLSplitterConfigurationBean extends ActivityPortsDefinitionBean {
+ Element wrappedTypeXML;
+
+ public Element getWrappedTypeXML() {
+ return wrappedTypeXML;
+ }
+
+ @ConfigurationProperty(name = "wrappedType", label = "Wrapped Type XML")
+ public void setWrappedTypeXML(Element wrappedTypeXML) {
+ this.wrappedTypeXML = wrappedTypeXML;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBeanBuilder.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBeanBuilder.java b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBeanBuilder.java
new file mode 100644
index 0000000..0930669
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/org/apache/taverna/activities/wsdl/xmlsplitter/XMLSplitterConfigurationBeanBuilder.java
@@ -0,0 +1,203 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.activities.wsdl.xmlsplitter;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.taverna.wsdl.parser.ArrayTypeDescriptor;
+import org.apache.taverna.wsdl.parser.BaseTypeDescriptor;
+import org.apache.taverna.wsdl.parser.ComplexTypeDescriptor;
+import org.apache.taverna.wsdl.parser.TypeDescriptor;
+import org.apache.taverna.wsdl.xmlsplitter.XMLSplitterSerialisationHelper;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.output.XMLOutputter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * A helper class to facilitate in building an XMLSplitter configuration bean
+ * from the type descriptor XML, including setting up the ports.
+ *
+ * @author Stuart Owen
+ *
+ */
+public class XMLSplitterConfigurationBeanBuilder {
+
+ private static final JsonNodeFactory JSON_NODE_FACTORY = JsonNodeFactory.instance;
+
+ public static JsonNode buildBeanForInput(TypeDescriptor descriptor) throws JDOMException, IOException {
+ Element element = XMLSplitterSerialisationHelper.typeDescriptorToExtensionXML(descriptor);
+ return buildBeanForInput(element);
+ }
+
+ public static JsonNode buildBeanForOutput(TypeDescriptor descriptor) throws JDOMException, IOException {
+ Element element = XMLSplitterSerialisationHelper.typeDescriptorToExtensionXML(descriptor);
+ return buildBeanForOutput(element);
+ }
+
+ public static JsonNode buildBeanForInput(Element element) throws JDOMException, IOException {
+ ObjectNode bean = JSON_NODE_FACTORY.objectNode();
+ ArrayNode inputDefinitions = bean.arrayNode();
+ bean.put("inputPorts", inputDefinitions);
+ ArrayNode outputDefinitions = bean.arrayNode();
+ bean.put("outputPorts", outputDefinitions);
+
+ TypeDescriptor descriptor = XMLSplitterSerialisationHelper
+ .extensionXMLToTypeDescriptor(element);
+ ObjectNode outBean = outputDefinitions.addObject();
+ outBean.put("name", "output");
+ outBean.put("mimeType", "'text/xml'");
+ outBean.put("depth", 0);
+ outBean.put("granularDepth", 0);
+
+ if (descriptor instanceof ComplexTypeDescriptor) {
+ List<TypeDescriptor> elements = ((ComplexTypeDescriptor) descriptor).getElements();
+ String[] names = new String[elements.size()];
+ Class<?>[] types = new Class<?>[elements.size()];
+ TypeDescriptor.retrieveSignature(elements, names, types);
+ for (int i = 0; i < names.length; i++) {
+ ObjectNode portBean = inputDefinitions.addObject();
+ portBean.put("name", names[i]);
+ portBean.put("mimeType", TypeDescriptor.translateJavaType(types[i]));
+ portBean.put("depth", depthForDescriptor(elements.get(i)));
+ }
+
+ List<TypeDescriptor> attributes = ((ComplexTypeDescriptor) descriptor).getAttributes();
+ String[] elementNames = Arrays.copyOf(names, names.length);
+ Arrays.sort(elementNames);
+ String[] attributeNames = new String[attributes.size()];
+ Class<?>[] attributeTypes = new Class<?>[attributes.size()];
+ TypeDescriptor.retrieveSignature(attributes, attributeNames, attributeTypes);
+ for (int i = 0; i < attributeNames.length; i++) {
+ ObjectNode portBean = inputDefinitions.addObject();
+ if (Arrays.binarySearch(elementNames, attributeNames[i]) < 0) {
+ portBean.put("name", attributeNames[i]);
+ } else {
+ portBean.put("name", "1" + attributeNames[i]);
+ }
+ portBean.put("mimeType", TypeDescriptor.translateJavaType(attributeTypes[i]));
+ portBean.put("depth", depthForDescriptor(attributes.get(i)));
+ }
+ } else if (descriptor instanceof ArrayTypeDescriptor) {
+ ObjectNode portBean = inputDefinitions.addObject();
+ portBean.put("name", descriptor.getName());
+
+ if (((ArrayTypeDescriptor) descriptor).getElementType() instanceof BaseTypeDescriptor) {
+ portBean.put("mimeType", "l('text/plain')");
+ } else {
+ portBean.put("mimeType", "l('text/xml')");
+ }
+ portBean.put("depth", 1);
+ }
+
+ String wrappedType = new XMLOutputter().outputString(element);
+ bean.put("wrappedType", wrappedType);
+
+ return bean;
+ }
+
+
+ private static int depthForDescriptor(TypeDescriptor desc) {
+ if (desc instanceof ArrayTypeDescriptor && (!((ArrayTypeDescriptor)desc).isWrapped() || ((ArrayTypeDescriptor)desc).getElementType() instanceof BaseTypeDescriptor)) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
+ public static JsonNode buildBeanForOutput(Element element)
+ throws JDOMException, IOException {
+ ObjectNode bean = JSON_NODE_FACTORY.objectNode();
+ ArrayNode inputDefinitions = bean.arrayNode();
+ bean.put("inputPorts", inputDefinitions);
+ ArrayNode outputDefinitions = bean.arrayNode();
+ bean.put("outputPorts", outputDefinitions);
+
+ TypeDescriptor descriptor = XMLSplitterSerialisationHelper
+ .extensionXMLToTypeDescriptor(element);
+
+ ObjectNode inBean = inputDefinitions.addObject();
+ inBean.put("name", "input");
+ inBean.put("mimeType", "'text/xml'");
+ inBean.put("depth", 0);
+
+ if (descriptor instanceof ComplexTypeDescriptor) {
+ List<TypeDescriptor> elements = ((ComplexTypeDescriptor) descriptor).getElements();
+ String[] names = new String[elements.size()];
+ Class<?>[] types = new Class<?>[elements.size()];
+ TypeDescriptor.retrieveSignature(elements, names, types);
+ for (int i = 0; i < names.length; i++) {
+ ObjectNode portBean = outputDefinitions.addObject();
+ portBean.put("name", names[i]);
+ portBean.put("mimeType", TypeDescriptor.translateJavaType(types[i]));
+ int depth = depthForDescriptor(elements.get(i));
+ portBean.put("depth", depth);
+ portBean.put("granularDepth", depth);
+ }
+
+
+ List<TypeDescriptor> attributes = ((ComplexTypeDescriptor) descriptor).getAttributes();
+ String[] elementNames = Arrays.copyOf(names, names.length);
+ Arrays.sort(elementNames);
+ String[] attributeNames = new String[attributes.size()];
+ Class<?>[] attributeTypes = new Class<?>[attributes.size()];
+ TypeDescriptor.retrieveSignature(attributes, attributeNames, attributeTypes);
+ for (int i = 0; i < attributeNames.length; i++) {
+ ObjectNode portBean = outputDefinitions.addObject();
+ if (Arrays.binarySearch(elementNames, attributeNames[i]) < 0) {
+ portBean.put("name", attributeNames[i]);
+ } else {
+ portBean.put("name", "1" + attributeNames[i]);
+ }
+ portBean.put("mimeType", TypeDescriptor
+ .translateJavaType(attributeTypes[i]));
+ int depth = depthForDescriptor(attributes.get(i));
+ portBean.put("depth", depth);
+ portBean.put("granularDepth", depth);
+ }
+ } else if (descriptor instanceof ArrayTypeDescriptor) {
+ ObjectNode portBean = outputDefinitions.addObject();
+ String name=descriptor.getName();
+ portBean.put("name", name);
+ portBean.put("depth", 1);
+ portBean.put("granularDepth", 1);
+ if (((ArrayTypeDescriptor) descriptor).getElementType() instanceof BaseTypeDescriptor) {
+ portBean.put("mimeType", "l('text/plain')");
+ } else {
+ portBean.put("mimeType", "l('text/xml')");
+ }
+ }
+
+
+ String wrappedType = new XMLOutputter().outputString(element);
+ bean.put("wrappedType", wrappedType);
+
+ return bean;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/taverna-wsdl-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
index fb1c735..7e0ee46 100644
--- a/taverna-wsdl-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
+++ b/taverna-wsdl-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
@@ -1,4 +1,4 @@
-net.sf.taverna.t2.activities.wsdl.WSDLActivityHealthChecker
-net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLOutputSplitterHealthChecker
-net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLInputSplitterHealthChecker
-net.sf.taverna.t2.activities.wsdl.WSDLActivityDescriptorChecker
\ No newline at end of file
+org.apache.taverna.activities.wsdl.WSDLActivityHealthChecker
+org.apache.taverna.activities.wsdl.xmlsplitter.XMLOutputSplitterHealthChecker
+org.apache.taverna.activities.wsdl.xmlsplitter.XMLInputSplitterHealthChecker
+org.apache.taverna.activities.wsdl.WSDLActivityDescriptorChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/resources/META-INF/spring/wsdl-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/resources/META-INF/spring/wsdl-activity-context.xml b/taverna-wsdl-activity/src/main/resources/META-INF/spring/wsdl-activity-context.xml
index fbbdf55..2dac1d1 100644
--- a/taverna-wsdl-activity/src/main/resources/META-INF/spring/wsdl-activity-context.xml
+++ b/taverna-wsdl-activity/src/main/resources/META-INF/spring/wsdl-activity-context.xml
@@ -3,18 +3,18 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
- <bean id="wsdlActivityHealthChecker" class="net.sf.taverna.t2.activities.wsdl.WSDLActivityHealthChecker" />
- <bean id="xmlInputSplitterHealthChecker" class="net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLInputSplitterHealthChecker" />
- <bean id="xmlOutputSplitterHealthChecker" class="net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLOutputSplitterHealthChecker" />
+ <bean id="wsdlActivityHealthChecker" class="org.apache.taverna.activities.wsdl.WSDLActivityHealthChecker" />
+ <bean id="xmlInputSplitterHealthChecker" class="org.apache.taverna.activities.wsdl.xmlsplitter.XMLInputSplitterHealthChecker" />
+ <bean id="xmlOutputSplitterHealthChecker" class="org.apache.taverna.activities.wsdl.xmlsplitter.XMLOutputSplitterHealthChecker" />
- <bean id="wsdlActivityFactory" class="net.sf.taverna.t2.activities.wsdl.WSDLActivityFactory">
+ <bean id="wsdlActivityFactory" class="org.apache.taverna.activities.wsdl.WSDLActivityFactory">
<property name="credentialManager" ref="credentialManager" />
<property name="edits" ref="edits" />
</bean>
- <bean id="xmlInputSplitterActivityFactory" class="net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLInputSplitterActivityFactory">
+ <bean id="xmlInputSplitterActivityFactory" class="org.apache.taverna.activities.wsdl.xmlsplitter.XMLInputSplitterActivityFactory">
<property name="edits" ref="edits" />
</bean>
- <bean id="xmlOutputSplitterActivityFactory" class="net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLOutputSplitterActivityFactory">
+ <bean id="xmlOutputSplitterActivityFactory" class="org.apache.taverna.activities.wsdl.xmlsplitter.XMLOutputSplitterActivityFactory">
<property name="edits" ref="edits" />
</bean>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/main/resources/xml-splitter.schema.json
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/resources/xml-splitter.schema.json b/taverna-wsdl-activity/src/main/resources/xml-splitter.schema.json
index 3dbae7c..471defc 100644
--- a/taverna-wsdl-activity/src/main/resources/xml-splitter.schema.json
+++ b/taverna-wsdl-activity/src/main/resources/xml-splitter.schema.json
@@ -60,7 +60,7 @@
"description": "The depth of the port",
"type": "integer",
"required": true
- }
+ },
"granularDepth": {
"title": "Port Granular Depth",
"description": "The granular depth of the port",
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactoryTest.java b/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactoryTest.java
deleted file mode 100644
index 9b147cf..0000000
--- a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactoryTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2010 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package net.sf.taverna.t2.activities.wsdl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URI;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
- * @author David Withers
- */
-public class WSDLActivityFactoryTest {
-
- private WSDLActivityFactory factory;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- factory = new WSDLActivityFactory();
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#createActivity()}.
- */
- @Test
- public void testCreateActivity() {
- WSDLActivity createActivity = factory.createActivity();
- assertNotNull(createActivity);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#getActivityType()}.
- */
- @Test
- public void testGetActivityURI() {
- assertEquals(URI.create(WSDLActivity.URI), factory.getActivityType());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityTest.java b/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityTest.java
deleted file mode 100644
index b1868ac..0000000
--- a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package net.sf.taverna.t2.activities.wsdl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
-import net.sf.taverna.t2.activities.testutils.LocationConstants;
-import net.sf.taverna.t2.workflowmodel.OutputPort;
-import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class WSDLActivityTest implements LocationConstants {
-
- private static final JsonNodeFactory JSON_NODE_FACTORY = JsonNodeFactory.instance;
-
- private static WSDLActivity activity;
- private static ObjectNode configBean;
- private static ObjectNode operationConfigBean;
- private static String wsdlLocation = WSDL_TEST_BASE
- + "eutils/eutils_lite.wsdl";
-
- //@BeforeClass
- @Ignore("Integration test")
- public static void setUp() throws Exception {
- activity = new WSDLActivity(null);
- configBean = JSON_NODE_FACTORY.objectNode();
- operationConfigBean = configBean.objectNode();
- configBean.put("operation", operationConfigBean);
- operationConfigBean.put("name", "run_eInfo");
- operationConfigBean.put("wsdl", wsdlLocation);
- activity.configure(configBean);
- }
-
- @Test
- @Ignore("Integration test")
- public void testConfigureWSDLActivityConfigurationBean() throws Exception {
- assertEquals("There should be 1 input ports", 1, activity
- .getInputPorts().size());
- assertEquals("There should be 2 output ports", 2, activity
- .getOutputPorts().size());
-
- assertEquals("parameters", activity.getInputPorts().iterator().next()
- .getName());
-
- List<String> expectedOutputNames = new ArrayList<String>();
- expectedOutputNames.add("parameters");
- expectedOutputNames.add("attachmentList");
- for (OutputPort port : activity.getOutputPorts()) {
- assertTrue("Unexpected output name:" + port.getName(),
- expectedOutputNames.contains(port.getName()));
- expectedOutputNames.remove(port.getName());
- }
- assertEquals(
- "Not all of the expected outputs were found, those remainng are:"
- + expectedOutputNames.toArray(), 0, expectedOutputNames
- .size());
- }
-
- @Test
- @Ignore("Integration test")
- public void testGetConfiguration() throws Exception {
- assertSame(configBean, activity.getConfiguration());
- }
-
- @Test
- @Ignore("Service is broken")
- public void testExecuteAsynchMapOfStringEntityIdentifierAsynchronousActivityCallback()
- throws Exception {
- Map<String, Object> inputMap = new HashMap<String, Object>();
- inputMap.put("parameters", "<parameters><db>pubmed</db></parameters>");
-
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- expectedOutputs.put("parameters", String.class);
-
- Map<String, Object> outputMap = ActivityInvoker.invokeAsyncActivity(
- activity, inputMap, expectedOutputs);
- assertNotNull("there should be an output named parameters", outputMap
- .get("parameters"));
- String xml;
- if (outputMap.get("parameters") instanceof String) {
- xml = (String) outputMap.get("parameters");
- } else {
- byte[] bytes = (byte[]) outputMap.get("parameters");
- xml = new String(bytes);
- }
-
- assertTrue("the xml is not what was expected", xml
- .contains("<DbName>pubmed</DbName>"));
- }
-
- @Ignore("Integration test")
- @Test
- public void testGetTypeDescriptorForOutputPort() throws Exception {
- assertNotNull("The type for the port 'paremeters' could not be found",
- activity.getTypeDescriptorForOutputPort("parameters"));
- assertTrue(
- "The type for the port 'paremeters' shoule be complex",
- activity.getTypeDescriptorForOutputPort("parameters") instanceof ComplexTypeDescriptor);
- assertNull("There should be no type descriptor for 'fred' port",
- activity.getTypeDescriptorForOutputPort("fred"));
- }
-
- @Ignore("Integration test")
- @Test
- public void testGetTypeDescriptorForInputPort() throws Exception {
- assertNotNull("The type for the port 'parameters' could not be found",
- activity.getTypeDescriptorForInputPort("parameters"));
- assertTrue(
- "The type for the port 'parameters' shoule be complex",
- activity.getTypeDescriptorForInputPort("parameters") instanceof ComplexTypeDescriptor);
- assertNull("There should be no type descriptor for 'fred' port",
- activity.getTypeDescriptorForInputPort("fred"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSRFActivityTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSRFActivityTest.java b/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSRFActivityTest.java
deleted file mode 100644
index dd144cf..0000000
--- a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/WSRFActivityTest.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package net.sf.taverna.t2.activities.wsdl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.StringReader;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Map;
-
-import net.sf.taverna.wsdl.parser.WSDLParser;
-
-import org.apache.axis.client.Call;
-import org.apache.axis.message.SOAPEnvelope;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
-import org.jdom.input.SAXBuilder;
-import org.junit.Before;
-import org.junit.Test;
-
-public class WSRFActivityTest {
-
- public class DummyInvoker extends T2WSDLSOAPInvoker {
-
- public DummyInvoker(String wsrfEndpoint) {
- super(wsdlParser, "add", Arrays.asList("attachmentList"),
- wsrfEndpoint, null);
- }
-
- @Override
- protected SOAPEnvelope invokeCall(Call call, SOAPEnvelope requestEnv) {
- requestXML = requestEnv;
- return null;
- }
- }
-
- private static final Namespace SoapEnvelopeNS = Namespace
- .getNamespace("http://schemas.xmlsoap.org/soap/envelope/");
- private static final Namespace CounterNS = Namespace
- .getNamespace("http://counter.com");
- private static final Namespace DifficultNS = Namespace
- .getNamespace("http://difficult.com/");
-
- private static final Namespace DefaultNS = Namespace
- .getNamespace("http://default/");
-
- private URL counterServiceWSDL;
- private WSDLParser wsdlParser;
- protected SOAPEnvelope requestXML;
-
- @Before
- public void makeWSDLParser() throws Exception {
- String path = "wsrf/counterService/CounterService_.wsdl";
- counterServiceWSDL = getClass().getResource(path);
- assertNotNull("Coult not find test WSDL " + path, counterServiceWSDL);
- wsdlParser = new WSDLParser(counterServiceWSDL.toExternalForm());
- }
-
- public void noHeaders() throws Exception {
-
- }
-
- @Test
- public void insertedEndpoint() throws Exception {
- // From T2-677 - support wsa:EndpointReference directly as well
- String wsrfEndpoint = "" +
- "<wsa:EndpointReference "
- + "xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/03/addressing' "
- + "xmlns:counter='http://counter.com'>"
- + " <wsa:Address>http://130.88.195.110:8080/wsrf/services/CounterService</wsa:Address>"
- + " <wsa:ReferenceProperties>"
- + " <counter:CounterKey>15063581</counter:CounterKey>"
- + " <difficult:one xmlns:difficult='http://difficult.com/' "
- + " difficult:attrib='something' attrib='else' >"
- + " <difficult:fish><counter:fish /></difficult:fish> "
- + " </difficult:one>" + " <emptyNamespace>"
- + " <defaultNamespace xmlns='http://default/'>"
- + "\n default \n " + "</defaultNamespace>"
- + " <stillEmpty />" + " </emptyNamespace>"
- + " </wsa:ReferenceProperties>"
- + " <wsa:ReferenceParameters/>" + "</wsa:EndpointReference>";
-
- // Note: We'll subclass to avoid calling service
- // and request attachmentList to trigger TAV-617-code and avoid
- // parsing of the (missing) response
- T2WSDLSOAPInvoker invoker = new DummyInvoker(wsrfEndpoint);
- Map<String, Object> results = invoker.invoke(Collections.singletonMap(
- "add", "10"));
- assertEquals(1, results.size());
- assertEquals("attachmentList", results.keySet().iterator().next());
-
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(new StringReader(requestXML.toString()));
- Element header = doc.getRootElement()
- .getChild("Header", SoapEnvelopeNS);
- assertNotNull("Could not find soapenv:Header", header);
- assertEquals("Unexpected number of children in header", 3, header
- .getChildren().size());
-
- // Check that everything was preserved as much as possible
-
- Element counterChild = header.getChild("CounterKey", CounterNS);
- assertEquals("15063581", counterChild.getText());
- assertEquals("Did not preserve namespace", "counter", counterChild
- .getNamespacePrefix());
-
- Element difficultChild = header.getChild("one", DifficultNS);
- assertNotNull("Could not find difficult:one", difficultChild);
- assertEquals("Did not preserve namespace", "difficult", difficultChild
- .getNamespacePrefix());
- assertEquals("something", difficultChild.getAttribute("attrib",
- DifficultNS).getValue());
- assertEquals("else", difficultChild.getAttribute("attrib",
- Namespace.NO_NAMESPACE).getValue());
-
- Element counterFish = difficultChild.getChild("fish", DifficultNS)
- .getChild("fish", CounterNS);
- assertEquals("counter", counterFish.getNamespacePrefix());
-
- Element emptyChild = header.getChild("emptyNamespace",
- Namespace.NO_NAMESPACE);
- Element defaultNamespace = emptyChild.getChild("defaultNamespace",
- DefaultNS);
- assertEquals("\n default \n ", defaultNamespace.getText());
-
- Element stillEmpty = emptyChild.getChild("stillEmpty");
- assertEquals(Namespace.NO_NAMESPACE, stillEmpty.getNamespace());
-
- }
-
-
- @Test
- public void insertedEndpointWrapped() throws Exception {
- // From T2-677 - support wsa:EndpointReference wrapped in <*> to avoid
- // unnecessary XML splitters and to support legacy workflows
-
- // Example from http://www.mygrid.org.uk/dev/issues/browse/TAV-23
- String wsrfEndpoint = "" +
- "<c:createCounterResponse xmlns:c='http://counter.com'>" +
- "<wsa:EndpointReference "
- + "xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/03/addressing' "
- + "xmlns:counter='http://counter.com'>"
- + " <wsa:Address>http://130.88.195.110:8080/wsrf/services/CounterService</wsa:Address>"
- + " <wsa:ReferenceProperties>"
- + " <counter:CounterKey>15063581</counter:CounterKey>"
- + " <difficult:one xmlns:difficult='http://difficult.com/' "
- + " difficult:attrib='something' attrib='else' >"
- + " <difficult:fish><counter:fish /></difficult:fish> "
- + " </difficult:one>" + " <emptyNamespace>"
- + " <defaultNamespace xmlns='http://default/'>"
- + "\n default \n " + "</defaultNamespace>"
- + " <stillEmpty />" + " </emptyNamespace>"
- + " </wsa:ReferenceProperties>"
- + " <wsa:ReferenceParameters/>" + "</wsa:EndpointReference>" +
- "</c:createCounterResponse>";
-
- // Note: We'll subclass to avoid calling service
- // and request attachmentList to trigger TAV-617-code and avoid
- // parsing of the (missing) response
- T2WSDLSOAPInvoker invoker = new DummyInvoker(wsrfEndpoint);
- Map<String, Object> results = invoker.invoke(Collections.singletonMap(
- "add", "10"));
- assertEquals(1, results.size());
- assertEquals("attachmentList", results.keySet().iterator().next());
-
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(new StringReader(requestXML.toString()));
- Element header = doc.getRootElement()
- .getChild("Header", SoapEnvelopeNS);
- assertNotNull("Could not find soapenv:Header", header);
- assertEquals("Unexpected number of children in header", 3, header
- .getChildren().size());
-
- // Check that everything was preserved as much as possible
-
- Element counterChild = header.getChild("CounterKey", CounterNS);
- assertEquals("15063581", counterChild.getText());
- assertEquals("Did not preserve namespace", "counter", counterChild
- .getNamespacePrefix());
-
- Element difficultChild = header.getChild("one", DifficultNS);
- assertNotNull("Could not find difficult:one", difficultChild);
- assertEquals("Did not preserve namespace", "difficult", difficultChild
- .getNamespacePrefix());
- assertEquals("something", difficultChild.getAttribute("attrib",
- DifficultNS).getValue());
- assertEquals("else", difficultChild.getAttribute("attrib",
- Namespace.NO_NAMESPACE).getValue());
-
- Element counterFish = difficultChild.getChild("fish", DifficultNS)
- .getChild("fish", CounterNS);
- assertEquals("counter", counterFish.getNamespacePrefix());
-
- Element emptyChild = header.getChild("emptyNamespace",
- Namespace.NO_NAMESPACE);
- Element defaultNamespace = emptyChild.getChild("defaultNamespace",
- DefaultNS);
- assertEquals("\n default \n ", defaultNamespace.getText());
-
- Element stillEmpty = emptyChild.getChild("stillEmpty");
- assertEquals(Namespace.NO_NAMESPACE, stillEmpty.getNamespace());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/HTTPSConnectionsTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/HTTPSConnectionsTest.java b/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/HTTPSConnectionsTest.java
deleted file mode 100644
index 58d6dd5..0000000
--- a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/HTTPSConnectionsTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package net.sf.taverna.t2.activities.wsdl.security;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.cert.Certificate;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLHandshakeException;
-
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class HTTPSConnectionsTest {
-
- @Test()
- @Ignore("https://rpc103.cs.man.ac.uk:8443/wsrf/services no available")
- public void testHTTPSConnections(){
-
- String serviceURL = "https://rpc103.cs.man.ac.uk:8443/wsrf/services";
-
- URL url;
- try {
- url = new URL(serviceURL);
- SSLUtilities.trustAllHttpsCertificates();
- HttpsURLConnection httpsConnection = (HttpsURLConnection) url.openConnection();
- httpsConnection.connect();
- Certificate[] certificates = httpsConnection.getServerCertificates();
- Assert.assertFalse(certificates.length == 0);
-
- SSLUtilities.stopTrustingAllHttpsCertificates();
- HttpsURLConnection httpsConnection2 = (HttpsURLConnection) url.openConnection();
- httpsConnection2.connect(); // This should now throw an SSLHandshakeException which is a subclass of IOException
-
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
-
- } catch(SSLHandshakeException e){
- // This is what we are expecting
- e.printStackTrace();
- }
- catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/433612be/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/SecureServicesInvokerTest.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/SecureServicesInvokerTest.java b/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/SecureServicesInvokerTest.java
deleted file mode 100644
index f0c3265..0000000
--- a/taverna-wsdl-activity/src/test/java/net/sf/taverna/t2/activities/wsdl/security/SecureServicesInvokerTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package net.sf.taverna.t2.activities.wsdl.security;
-
-import static org.junit.Assert.assertEquals;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
-import javax.xml.namespace.QName;
-
-import org.apache.axis.client.Call;
-import org.apache.axis.client.Service;
-import org.apache.axis.configuration.XMLStringProvider;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class SecureServicesInvokerTest {
-
- // Broken service
- @Ignore
- @Test
- public void testCreteCallAndInvoke() throws Exception {
-
-
- String endpoint = "http://www.mygrid.org.uk/axis/services/UsernameHelloService"; // test server
- //endpoint = "http://rpc212.cs.man.ac.uk/taverna/";
-
- HostnameVerifier hv = new HostnameVerifier() {
- public boolean verify(String hostName, SSLSession session) {
- return true;
- }
- };
- HttpsURLConnection.setDefaultHostnameVerifier(hv);
- //endpoint = "https://rpc103.cs.man.ac.uk:8443/wsrf/services/cagrid/SecureHelloWorld?wsdl";
-
- // Set the system property "javax.net.ssl.Truststore" to use Taverna's truststore
- //System.setProperty("javax.net.ssl.trustStore", "/Users/alex/Desktop/t2truststore.jks");
- //System.setProperty("javax.net.ssl.trustStorePassword", "raehiekooshe0eghiPhi");
- //System.clearProperty("javax.net.ssl.trustStoreType");
- //System.clearProperty("javax.net.ssl.trustStoreProvider");
-
- //String endpoint = "http://www.mygrid.org.uk/axis/services/UsernameTimestampHelloService"; // test server
- //String endpoint = "http://www.mygrid.org.uk/axis/services/UsernameDigestHelloService"; // test server
- //String endpoint = "http://www.mygrid.org.uk/axis/services/UsernameDigestTimestampHelloService"; // test server
-
- //String endpoint = "http://localhost:8080/axis/services/UsernameHelloService" ; // local server
- //String endpoint = "http://localhost:8080/axis/services/UsernameTimestampHelloService" ;
- //String endpoint = "http://localhost:8080/axis/services/UsernameDigestHelloService" ;
- //String endpoint = "http://localhost:8080/axis/services/UsernameDigestTimestampHelloService" ;
-
- //Service service = new org.apache.axis.client.Service() ;
-
- //String wssEngineConfigurationString = WSSecurityProfiles.wssUTTimestampProfile;
- //String wssEngineConfigurationString = WSSecurityProfiles.wssUTDigestProfile;
- //String wssEngineConfigurationString = WSSecurityProfiles.wssUTDigestTimestampProfile;
-
- XMLStringProvider wssEngineConfiguration = new XMLStringProvider("<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " +
- "xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">" +
- "<globalConfiguration>" +
- "<requestFlow>" +
- "<handler type=\"java:org.apache.ws.axis.security.WSDoAllSender\">" +
- "<parameter name=\"action\" value=\"UsernameToken\"/>" +
- "<parameter name=\"passwordType\" value=\"PasswordDigest\"/>" +
- "</handler>"+
- "</requestFlow>" +
- "</globalConfiguration>" +
- "<transport name=\"http\" pivot=\"java:org.apache.axis.transport.http.HTTPSender\"/>"+
- "</deployment>");
-
- Service service = new Service(wssEngineConfiguration);
-
- Call call = new Call(service);
-
- //call.setTransport(new HTTPTransport());
- call.setTargetEndpointAddress(endpoint) ;
- call.setOperationName(new QName("hello")) ;
-
- String username = "testuser";
- String password = "testpasswd";
-
- //WSS4J WSDoAllSender's invoke() method expects username not to be empty before the agent takes over
- // to set it so we set it to the WSDL location here (that is used as keystore alias) and later on overwrite it
- call.setProperty(Call.USERNAME_PROPERTY, "testuser");
- call.setProperty(Call.PASSWORD_PROPERTY, "testpasswd");
-
-
- // Set HTTP Basic AuthN
-// MessageContext context = call.getMessageContext();
-// Hashtable headers = (Hashtable) context
-// .getProperty(HTTPConstants.REQUEST_HEADERS);
-// if (headers == null) {
-// headers = new Hashtable();
-// context.setProperty(HTTPConstants.REQUEST_HEADERS, headers);
-// }
-//// String authorization = Base64.encode(("hudsonadmin" + ":"
-//// + "ch33se").getBytes());
-// String authorization = Base64.encode((username + ":"
-// + password).getBytes());
-// headers.put("Authorization", "Basic " + authorization);
-// System.out.println("HTTP Authorization header: "
-// + headers.get("Authorization"));
-// HTTPSender http = new HTTPSender();
-//
-// Transport transport = call.getTransportForProtocol("https");
-// System.out.println(transport.getClass());
-//
-
-
-
- String nickName = "Beauty" ;
- System.out.println("Sent: '" + nickName + "'") ;
- String ret = (String) call.invoke(new Object[] {nickName}) ;
- System.out.println("Got: '" + ret + "'") ;
- assertEquals(ret, "Hello Beauty!");
- }
-
-}