/*
* Add notifiable object
*/
WorkflowTrackingNotification workflowNotification = new WorkflowTrackingNotification(brokerURL, topic);
LoggingNotification loggingNotification = new LoggingNotification();
DefaultInvocationContext invocationContext = new DefaultInvocationContext();
invocationContext.setExecutionContext(new DefaultExecutionContext());
invocationContext.setServiceName(serviceName);
invocationContext.getExecutionContext().setRegistryService(getRegistry(context));
invocationContext.getExecutionContext().setSecurityContextHeader(getHeader(messageContext));
invocationContext.getExecutionContext().addNotifiable(workflowNotification);
invocationContext.getExecutionContext().addNotifiable(loggingNotification);
GSISecurityContext gssContext = new GSISecurityContext();
SecurityContextDocument parse =
SecurityContextDocument.Factory.parse(getHeader(messageContext).getFirstChildWithName
(new QName("http://schemas.airavata.apache.org/workflow-execution-context", "security-context")).toStringWithConsume());
SecurityContextDocument.SecurityContext.GridMyproxyRepository gridMyproxyRepository = parse.getSecurityContext().getGridMyproxyRepository();
if (gridMyproxyRepository==null){
gssContext.setMyproxyPasswd((String)messageContext.getConfigurationContext().getProperty(MYPROXY_PASS));
gssContext.setMyproxyUserName((String)messageContext.getConfigurationContext().getProperty(MYPROXY_USER));
gssContext.setMyproxyLifetime(Integer.parseInt(messageContext.getConfigurationContext().getProperty(MYPROXY_LIFE).toString()));
gssContext.setMyproxyServer((String)messageContext.getConfigurationContext().getProperty(MYPROXY_SERVER));
}else{
gssContext.setMyproxyPasswd(gridMyproxyRepository.getPassword());
gssContext.setMyproxyUserName(gridMyproxyRepository.getUsername());
gssContext.setMyproxyLifetime(gridMyproxyRepository.getLifeTimeInhours());
gssContext.setMyproxyServer(gridMyproxyRepository.getMyproxyServer());
}
gssContext.setTrustedCertLoc((String)messageContext.getConfigurationContext().getProperty(TRUSTED_CERT_LOCATION));
invocationContext.addSecurityContext("myproxy",gssContext);
/*
* Add workflow context
*/
WorkflowContextImpl workflowContext = new WorkflowContextImpl();
workflowContext.setValue(WorkflowContextImpl.WORKFLOW_ID, URI.create(topic).toString());
invocationContext.addMessageContext(WorkflowContextImpl.WORKFLOW_CONTEXT_NAME, workflowContext);
/*
* read from registry and set the correct parameters
*/
ServiceDescription serviceDescription = getRegistry(context).getServiceDescription(serviceName);
/*
* Input
*/
ParameterContextImpl inputParam = new ParameterContextImpl();
ServiceDescriptionType serviceDescriptionType = serviceDescription.getType();
for (Parameter parameter : serviceDescriptionType.getInputParametersArray()) {
OMElement element = input.getFirstChildWithName(new QName(null,parameter.getParameterName()));
if (element == null) {
throw new Exception("Parameter is not found in the message");
}
//todo this implementation doesn't work when there are n number of nodes connecting .. need to fix
// String xmlContent = "";
// if(!element.getChildElements().hasNext()){
// xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
// +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.getText() + "</type:GFacParameter>";
// }else{
// xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
// +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.toStringWithConsume() + "</type:GFacParameter>";
// }
// System.out.println(xmlContent);
// inputParam.add(parameter.getParameterName(),ActualParameter.fromXML(xmlContent));
ActualParameter actualParameter = getInputActualParameter(parameter, element);
inputParam.add(parameter.getParameterName(),actualParameter);
}
/*
* Output
*/
ParameterContextImpl outputParam = new ParameterContextImpl();
// List<Parameter> outputs = serviceDescription.getOutputParameters();
for (OutputParameterType parameter : serviceDescriptionType.getOutputParametersArray()) {
ActualParameter actualParameter = new ActualParameter();
if("String".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(StringParameterType.type);
}else if("Double".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(DoubleParameterType.type);
}else if("Integer".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(IntegerParameterType.type);
}else if("Float".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FloatParameterType.type);
}else if("Boolean".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(BooleanParameterType.type);
}else if("File".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FileParameterType.type);
}else if("URI".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(URIParameterType.type);
}else if("StringArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(StringArrayType.type);
}else if("DoubleArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(DoubleArrayType.type);
}else if("IntegerArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(IntegerArrayType.type);
}else if("FloatArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FloatArrayType.type);
}else if("BooleanArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(BooleanArrayType.type);
}else if("FileArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FileArrayType.type);
}else if("URIArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(URIArrayType.type);
}
outputParam.add(parameter.getParameterName(), new ActualParameter());
}
invocationContext.setInput(inputParam);
invocationContext.setOutput(outputParam);
if (service == null) {
service = new PropertyServiceFactory(GFacService.REPOSITORY_PROPERTIES).createService();
}
// invoke service
service.execute(invocationContext);
/*
* Process Output
*/
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd", "ns1");
outputElement = fac.createOMElement("invokeResponse", omNs);
ParameterContextImpl paramContext = (ParameterContextImpl) invocationContext
.<ActualParameter> getMessageContext("output");
for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext();) {
String name = iterator.next();
String outputString = paramContext.getValue(name).toXML().replaceAll("GFacParameter", name);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(outputString));