public OMElement invoke(String serviceName, OMElement input) {
OMElement output = null;
try {
InvocationContext ct = new InvocationContext();
ct.setExecutionContext(new ExecutionContextImpl());
ct.getExecutionContext().setNotificationService(new DummyNotification());
MessageContext msgContext = MessageContext.getCurrentMessageContext();
Map<String, Object> m = (Map)msgContext.getProperty(SECURITY_CONTEXT);
for (String key : m.keySet()) {
ct.addSecurityContext(key, (SecurityContext)m.get(key));
}
ct.setServiceName(serviceName);
// TODO define real parameter passing in SOAP body
//handle parameter
for (Iterator iterator = input.getChildren(); iterator.hasNext();) {
OMElement element = (OMElement) iterator.next();
String name = element.getQName().getLocalPart();
String type = element.getAttribute(new QName("type")).getAttributeValue();
String value = element.getText();
ParameterContextImpl x = new ParameterContextImpl();
x.addParameter(name, type, value);
ct.addMessageContext("input", x);
}
if (service == null) {
service = new PropertyServiceFactory().createService();
}
//invoke service
service.execute(ct);
//TODO also define how output too
/*
* Process Output
*/
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd", "ns1");
output = fac.createOMElement("output", omNs);
org.ogce.gfac.context.MessageContext context = ct.getMessageContext("output");
for (Iterator<String> iterator = context.getParameterNames(); iterator.hasNext();) {
String name = iterator.next();
OMElement ele = fac.createOMElement(name, omNs);
ele.addAttribute("type", context.getParameterType(name), omNs);
ele.setText(context.getParameterValue(name).toString());