You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2011/08/12 23:36:10 UTC
svn commit: r1157261 - in /incubator/airavata/trunk/modules/gfac-axis2: ./
src/main/java/org/apache/airavata/services/gfac/axis2/
src/main/java/org/apache/airavata/services/gfac/axis2/reciever/
src/main/resources/
Author: lahiru
Date: Fri Aug 12 21:36:10 2011
New Revision: 1157261
URL: http://svn.apache.org/viewvc?rev=1157261&view=rev
Log:
implementing the message reciever with invoke and getWSDL method handling
Added:
incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/repository.properties
Modified:
incubator/airavata/trunk/modules/gfac-axis2/pom.xml
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java
Modified: incubator/airavata/trunk/modules/gfac-axis2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/pom.xml?rev=1157261&r1=1157260&r2=1157261&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/pom.xml (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/pom.xml Fri Aug 12 21:36:10 2011
@@ -46,6 +46,11 @@
<artifactId>gfac-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java?rev=1157261&r1=1157260&r2=1157261&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java Fri Aug 12 21:36:10 2011
@@ -21,31 +21,22 @@
package org.apache.airavata.services.gfac.axis2;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.airavata.core.gfac.context.InvocationContext;
-import org.apache.airavata.core.gfac.context.SecurityContext;
-import org.apache.airavata.core.gfac.context.impl.ExecutionContextImpl;
-import org.apache.airavata.core.gfac.context.impl.ParameterContextImpl;
-import org.apache.airavata.core.gfac.factory.PropertyServiceFactory;
-import org.apache.airavata.core.gfac.notification.DummyNotification;
+import java.io.File;
+import java.io.FileInputStream;
+import java.lang.reflect.Constructor;
+import java.util.*;
+
import org.apache.airavata.core.gfac.services.GenericService;
-import org.apache.airavata.core.gfac.type.parameter.StringParameter;
import org.apache.airavata.services.gfac.axis2.handlers.AmazonSecurityHandler;
import org.apache.airavata.services.gfac.axis2.handlers.MyProxySecurityHandler;
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.Phase;
import org.apache.axis2.engine.ServiceLifeCycle;
+import javax.jcr.*;
+
public class GFacService implements ServiceLifeCycle {
public static final String SECURITY_CONTEXT = "security_context";
@@ -55,10 +46,11 @@ public class GFacService implements Serv
public void startUp(ConfigurationContext configctx, AxisService service) {
AxisConfiguration config = null;
List<Phase> phases = null;
-
config = service.getAxisConfiguration();
phases = config.getInFlowPhases();
+ initializeRepository(configctx);
+
for (Iterator iterator = phases.iterator(); iterator.hasNext();) {
Phase phase = (Phase) iterator.next();
if ("Security".equals(phase.getPhaseName())) {
@@ -67,80 +59,27 @@ public class GFacService implements Serv
return;
}
}
-
}
-
+ private void initializeRepository(ConfigurationContext context) {
+ Properties properties = new Properties();
+ try {
+ String axis2Home = System.getenv("AXIS2_HOME");
+ properties.load(new FileInputStream(axis2Home + File.separator + "conf/repository.properties"));
+ Map<String, String> map = new HashMap<String, String>((Map) properties);
+ Class registryRepositoryFactory = Class.forName(map.get("repository.factory"));
+ Constructor c = registryRepositoryFactory.getConstructor();
+ RepositoryFactory repositoryFactory = (RepositoryFactory) c.newInstance();
+ Repository repository = repositoryFactory.getRepository(map);
+ Credentials credentials = new SimpleCredentials(map.get("userName"), (map.get("password")).toCharArray());
+ Session session = repository.login(credentials);
+ context.setProperty("credentials",credentials);
+ context.setProperty("repositorySession",session);
+ } catch (Exception e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
public void shutDown(ConfigurationContext configctx, AxisService service) {
// TODO Auto-generated method stub
}
-
- public OMElement getWSDL(String serviceName) {
- return null;
- }
-
- 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();
-
- StringParameter value = new StringParameter();
- value.parseStringVal(element.getText());
-
- ParameterContextImpl x = new ParameterContextImpl();
- x.addParameter(name, 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);
-
- ParameterContextImpl context = (ParameterContextImpl)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.getParameterValue(name).getType().toString(), omNs);
- ele.setText(context.getParameterValue(name).toString());
-
- //add output
- output.addChild(ele);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
-
- }
- return output;
- }
}
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java?rev=1157261&r1=1157260&r2=1157261&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java Fri Aug 12 21:36:10 2011
@@ -21,32 +21,170 @@ package org.apache.airavata.services.gfa
*
*/
+import org.apache.airavata.core.gfac.context.InvocationContext;
+import org.apache.airavata.core.gfac.context.SecurityContext;
+import org.apache.airavata.core.gfac.context.impl.ExecutionContextImpl;
+import org.apache.airavata.core.gfac.context.impl.ParameterContextImpl;
+import org.apache.airavata.core.gfac.factory.PropertyServiceFactory;
+import org.apache.airavata.core.gfac.notification.DummyNotification;
+import org.apache.airavata.core.gfac.services.GenericService;
+import org.apache.airavata.core.gfac.type.parameter.StringParameter;
import org.apache.airavata.services.gfac.axis2.utils.GFacServiceOperations;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.AxisEngine;
import org.apache.axis2.engine.MessageReceiver;
-import org.apache.axis2.receivers.AbstractMessageReceiver;
import org.apache.axis2.util.MessageContextBuilder;
+import org.apache.axis2.util.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Map;
+
public class GFacMessageReciever implements MessageReceiver {
private static final Log log = LogFactory.getLog(GFacMessageReciever.class);
+ public static final String SECURITY_CONTEXT = "security_context";
+ GenericService service = null;
public void receive(org.apache.axis2.context.MessageContext axisRequestMsgCtx)
throws AxisFault {
GFacServiceOperations operation = GFacServiceOperations.valueFrom(axisRequestMsgCtx.getOperationContext().getOperationName());
switch (operation) {
case INVOKE: {
+ processInvokeOperation(axisRequestMsgCtx);
log.info("Invoke operation invoked !!");
}
break;
case GETWSDL: {
+ processgetWSDLOperation(axisRequestMsgCtx);
log.info("getWSDL operation invoked !!");
}
}
}
+ public void processInvokeOperation(MessageContext messageContext) {
+ MessageContext response = null;
+ String serviceName = getOriginalServiceName(messageContext);
+ OMElement input = messageContext.getEnvelope().getBody().getFirstChildWithName(new QName("input"));
+ OMElement output = invokeApplication(serviceName, input);
+ SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
+ SOAPEnvelope responseEnv = sf.createSOAPEnvelope();
+ sf.createSOAPBody(responseEnv);
+ responseEnv.getBody().addChild(output);
+ try {
+ response = MessageContextBuilder.createOutMessageContext(messageContext);
+ response.setEnvelope(responseEnv);
+ response.getOperationContext().addMessageContext(response);
+ AxisEngine.send(response);
+ } catch (AxisFault fault) {
+ log.error("Error creating response");
+ }
+ }
+
+ private OMElement invokeApplication(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();
+
+ StringParameter value = new StringParameter();
+ value.parseStringVal(element.getText());
+
+ ParameterContextImpl x = new ParameterContextImpl();
+ x.addParameter(name, 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);
+
+ ParameterContextImpl context = (ParameterContextImpl) 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.getParameterValue(name).getType().toString(), omNs);
+ ele.setText(context.getParameterValue(name).toString());
+ output.addChild(ele);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ }
+ return output;
+ }
+
+ public void processgetWSDLOperation(MessageContext messageContext) {
+ MessageContext response = null;
+ String serviceName = getOriginalServiceName(messageContext);
+ ConfigurationContext context = messageContext.getConfigurationContext();
+ //todo this logic has to change based on the logic we are storing data into repository
+ try {
+ Session session = (Session) context.getProperty("repositorySession");
+ Node node = session.getNode("wsdls").getNode(serviceName);
+ Property propertyContent = node.getProperty("content");
+ String wsdlContent = propertyContent.getString();
+ SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
+ SOAPEnvelope responseEnv = sf.createSOAPEnvelope();
+ OMElement wsdlElement = sf.createOMElement(wsdlContent, "", "");
+ sf.createSOAPBody(responseEnv);
+ responseEnv.getBody().addChild(wsdlElement);
+ response = MessageContextBuilder.createOutMessageContext(messageContext);
+ response.setEnvelope(responseEnv);
+ response.getOperationContext().addMessageContext(response);
+ AxisEngine.send(response);
+ } catch (Exception fault) {
+ log.error("Error creating response");
+ }
+ }
+
+ private String getOriginalServiceName(MessageContext messageContext) {
+ String toAddress = messageContext.getTo().getAddress();
+ String[] values = Utils.parseRequestURLForServiceAndOperation(toAddress,
+ messageContext
+ .getConfigurationContext().getServiceContextPath());
+ return values[0];
+ }
+
}
Added: incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/repository.properties
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/repository.properties?rev=1157261&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/repository.properties (added)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/repository.properties Fri Aug 12 21:36:10 2011
@@ -0,0 +1,34 @@
+#
+#
+# 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.
+#
+#
+
+ssl.hostcertsKeyFile=/home/ptangcha/ogce-workspace/sgfac/target/dist-bin/conf/ogce_services_key.pem
+ssl.trustedCertsFile=/home/ptangcha/ogce-workspace/sgfac/target/dist-bin/certificates
+repository.factory=org.wso2.carbon.registry.jcr.RegistryRepositoryFactory
+registryUrl=https://localhost:9443/registry
+certPath=/Users/lahirugunathilake/work/wso2greg-4.0.0/repository/resources/security/client-truststore.jks
+trustStorePassword=wso2carbon
+carbon.home=/Users/lahirugunathilake/work/wso2greg-4.0.0
+userName=admin
+password=admin
+#repository.factory=org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory
+#org.apache.jackrabbit.repository.uri=http://localhost:8081/jackrabbit-webapp-2.2.7/rmi
+#prechain.classes=
+#postchain.classes
\ No newline at end of file