diff options
Diffstat (limited to 'sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation')
14 files changed, 1438 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalCallback.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalCallback.java new file mode 100644 index 0000000000..a6202309bd --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalCallback.java @@ -0,0 +1,50 @@ +/* + * 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 conversation.client; + +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.Remotable; + + +/** + * The callback interface used when testing caonversational callbacks + * + * @version $Rev$ $Date$ + */ +@Remotable +@Conversational +public interface ConversationalCallback { + + public void init(); + + public void destroy(); + + public void initializeCount(int count); + + public void incrementCount(); + + public int retrieveCount(); + + public void businessException() throws Exception; + + @EndsConversation + public String endConversation(); + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClient.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClient.java new file mode 100644 index 0000000000..af269052c7 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClient.java @@ -0,0 +1,51 @@ +/* + * 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 conversation.client; + +import org.osoa.sca.annotations.Remotable; + +/** + * The client for the conversational itest. Is implemented by clients + * offering both stateless and stateful callbacks + * + * @version $Rev$ $Date$ + */ + +@Remotable +public interface ConversationalClient { + + public int runConversationFromInjectedReference(); + public int runConversationFromServiceReference(); + public int runConversationWithUserDefinedConversationId(); + public String runConversationCheckUserDefinedConversationId(); + public int runConversationCheckingScope(); + public int runConversationWithCallback(); + public int runConversationHavingPassedReference(); + public String runConversationBusinessException(); + public String runConversationBusinessExceptionCallback(); + public int runConversationCallingEndedConversation(); + public int runConversationCallingEndedConversationCallback(); + public int runConversationAgeTimeout(); + public int runConversationIdleTimeout(); + public int runConversationPrincipleError(); + + public String getCalls(); + public String getServiceCalls(); + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java new file mode 100644 index 0000000000..5eb16be597 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java @@ -0,0 +1,105 @@ +/* + * 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 conversation.client; + +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; + +import conversation.client.ConversationalCallback; +import conversation.client.ConversationalClient; +import conversation.client.ConversationalClientStatefulImpl; +import conversation.client.ConversationalClientStatelessImpl; + +/* + * OSGi bundle activator for conversation tests + */ +public class ConversationalClientActivator implements BundleActivator, ServiceListener { + + + private BundleContext bundleContext; + + + public void start(BundleContext bc) throws Exception { + + System.out.println("Started OSGiConversationClientActivator "); + + this.bundleContext = bc; + + bc.addServiceListener(this); + + Hashtable<String, Object> serviceProps; + + serviceProps = new Hashtable<String, Object>(); + + serviceProps.put("component.name", "ConversationalStatelessClientStatelessService"); + Object statelessClientFactory1 = + new ConversationalClientServiceFactory(ConversationalClientStatelessImpl.class, bundleContext, 1); + bundleContext.registerService( + new String[] {ConversationalClient.class.getName(), ConversationalCallback.class.getName()}, + statelessClientFactory1, + serviceProps); + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalStatelessClientStatefulService"); + Object statelessClientFactory2 = + new ConversationalClientServiceFactory(ConversationalClientStatelessImpl.class, bundleContext, 2); + bundleContext.registerService( + new String[] {ConversationalClient.class.getName(), ConversationalCallback.class.getName()}, + statelessClientFactory2, + serviceProps); + + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalStatefulClientStatelessService"); + Object statefulClientFactory1 = + new ConversationalClientServiceFactory(ConversationalClientStatefulImpl.class, bundleContext, 3); + bundleContext.registerService( + new String[] {ConversationalClient.class.getName(), ConversationalCallback.class.getName()}, + statefulClientFactory1, + serviceProps); + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalStatefulClientStatefulService"); + Object statefulClientFactory2 = + new ConversationalClientServiceFactory(ConversationalClientStatefulImpl.class, bundleContext, 4); + bundleContext.registerService( + new String[] {ConversationalClient.class.getName(), ConversationalCallback.class.getName()}, + statefulClientFactory2, + serviceProps); + + + } + + + + public void stop(BundleContext bc) { + } + + public void serviceChanged(ServiceEvent event) { + + if (event.getType() == ServiceEvent.REGISTERED) { + + } + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientServiceFactory.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientServiceFactory.java new file mode 100644 index 0000000000..8479624546 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientServiceFactory.java @@ -0,0 +1,135 @@ +/* + * 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 conversation.client; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceFactory; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +import conversation.client.ConversationalClientStatefulImpl; +import conversation.client.ConversationalClientStatelessImpl; +import conversation.referenceclient.ConversationalReferenceClient; +import conversation.service.ConversationalService; + +public class ConversationalClientServiceFactory implements ServiceFactory { + + private Class<?> clazz; + private BundleContext bundleContext; + private int serviceNum; + + public ConversationalClientServiceFactory(Class<?> clazz, BundleContext bundleContext, int serviceNum) { + this.clazz = clazz; + this.bundleContext = bundleContext; + this.serviceNum = serviceNum; + } + + public Object getService(Bundle bundle, ServiceRegistration reg) { + + + try { + Object instance = clazz.newInstance(); + + ConversationalClientStatelessImpl statelessClient = null; + ConversationalClientStatefulImpl statefulClient = null; + + if (serviceNum == 1 || serviceNum == 2) { + + ServiceReference ref = bundleContext.getServiceReference(ConversationalReferenceClient.class.getName()); + statelessClient = (ConversationalClientStatelessImpl)instance; + statelessClient.conversationalReferenceClient = + (ConversationalReferenceClient)bundleContext.getService(ref); + } + if (serviceNum == 1) { + + ServiceReference ref = getServiceReference(ConversationalService.class.getName(), + "(component.name=ConversationalServiceStateless)"); + statelessClient.conversationalService = (ConversationalService)bundleContext.getService(ref); + + } + + if (serviceNum == 2) { + + ServiceReference ref = getServiceReference(ConversationalService.class.getName(), + "(component.name=ConversationalServiceStateful)"); + statelessClient.conversationalService = (ConversationalService)bundleContext.getService(ref); + + } + + + if (serviceNum == 3 || serviceNum == 4) { + + ServiceReference ref = bundleContext.getServiceReference(ConversationalReferenceClient.class.getName()); + statefulClient = (ConversationalClientStatefulImpl)instance; + statefulClient.conversationalReferenceClient = + (ConversationalReferenceClient)bundleContext.getService(ref); + } + if (serviceNum == 3) { + + ServiceReference ref = getServiceReference(ConversationalService.class.getName(), + "(component.name=ConversationalServiceStateless)"); + statefulClient.conversationalService = (ConversationalService)bundleContext.getService(ref); + + } + + if (serviceNum == 4) { + + ServiceReference ref = getServiceReference(ConversationalService.class.getName(), + "(component.name=ConversationalServiceStateful)"); + statefulClient.conversationalService = (ConversationalService)bundleContext.getService(ref); + + } + + return instance; + } catch (Exception e) { + + e.printStackTrace(); + return null; + } + } + + public void ungetService(Bundle bundle, ServiceRegistration reg, Object obj) { + + } + + private ServiceReference getServiceReference(String name, String filter) throws Exception { + + ServiceReference refs[] = bundleContext.getServiceReferences(name, filter); + ServiceReference ref = refs[0]; + int ranking = 0; + if (ref.getProperty(Constants.SERVICE_RANKING) instanceof Integer) + ranking = (Integer)ref.getProperty(Constants.SERVICE_RANKING); + for (int i = 1; i < refs.length; i++) { + int thisranking = 0; + if (refs[i].getProperty(Constants.SERVICE_RANKING) instanceof Integer) { + thisranking = (Integer)refs[i].getProperty(Constants.SERVICE_RANKING); + } + if (thisranking > ranking) { + ref = refs[i]; + ranking = thisranking; + } + } + + return ref; + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatefulImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatefulImpl.java new file mode 100644 index 0000000000..3aedabc29c --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatefulImpl.java @@ -0,0 +1,254 @@ +/* + * 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 conversation.client; + +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import conversation.referenceclient.ConversationalReferenceClient; +import conversation.service.ConversationalService; + +/** + * The client for the conversational itest which presents a stateful + * callback interface + * + * @version $Rev$ $Date$ + */ + +@Service(interfaces={ConversationalClient.class}) +@Scope("CONVERSATION") +@ConversationAttributes(maxAge="10 minutes", + maxIdleTime="5 minutes", + singlePrincipal=false) +public class ConversationalClientStatefulImpl implements ConversationalClient, ConversationalCallback { + + @Context + protected ComponentContext componentContext; + + protected ConversationalService conversationalService; + + protected ConversationalReferenceClient conversationalReferenceClient; + + private int clientCount = 0; + private int callbackCount = 0; + + + // a static member variable that records the number of times this service is called + public static StringBuffer calls = new StringBuffer(); + + // From ConversationalClient + public int runConversationFromInjectedReference(){ + calls.append("runConversationFromInjectedReference,"); + conversationalService.initializeCount(1); + conversationalService.incrementCount(); + clientCount = conversationalService.retrieveCount(); + conversationalService.endConversation(); + + return clientCount; + } + public int runConversationFromServiceReference(){ + calls.append("runConversationFromServiceReference,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + // serviceReference.getConversation().end(); + + return clientCount; + } + public int runConversationWithUserDefinedConversationId(){ + calls.append("runConversationWithUserDefinedConversationId,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + serviceReference.setConversationID("MyConversation1"); + + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + // serviceReference.getConversation().end(); + + return clientCount; + } + public String runConversationCheckUserDefinedConversationId(){ + calls.append("runConversationCheckUserDefinedConversationId,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + serviceReference.setConversationID("MyConversation2"); + + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + return callableReference.endConversation(); + + } + public int runConversationCheckingScope(){ + calls.append("runConversationCheckingScope,"); + // run a conversation + return runConversationFromInjectedReference(); + + // test will then use a static method to find out how many times + // init/destroy were called + } + public int runConversationWithCallback(){ + calls.append("runConversationWithCallback,"); + callbackCount = 2; + conversationalService.initializeCountCallback(1); + conversationalService.incrementCountCallback(); + clientCount = conversationalService.retrieveCountCallback(); + conversationalService.endConversationCallback(); + + return clientCount; + } + public int runConversationHavingPassedReference(){ + calls.append("runConversationHavingPassedReference,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + conversationalReferenceClient.incrementCount(serviceReference); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + serviceReference.getConversation().end(); + + return clientCount; + } + public String runConversationBusinessException(){ + calls.append("runConversationbusinessException,"); + try { + conversationalService.initializeCount(1); + conversationalService.businessException(); + clientCount = conversationalService.retrieveCount(); + conversationalService.endConversation(); + } catch(Exception ex) { + return ex.getMessage(); + } + + return "No Exception Returned"; + } + + public String runConversationBusinessExceptionCallback(){ + calls.append("runConversationbusinessExceptionCallback,"); + try { + conversationalService.initializeCountCallback(1); + conversationalService.businessExceptionCallback(); + clientCount = conversationalService.retrieveCountCallback(); + conversationalService.endConversationCallback(); + } catch(Exception ex) { + return ex.getMessage(); + } + + return "No Exception Returned"; + } + + public int runConversationCallingEndedConversation(){ + calls.append("runConversationCallingEndedConversation,"); + conversationalService.initializeCount(1); + conversationalService.endConversation(); + return conversationalService.retrieveCount(); + } + + public int runConversationCallingEndedConversationCallback(){ + calls.append("runConversationCallingEndedConversationCallback,"); + conversationalService.initializeCountCallback(1); + conversationalService.endConversationCallback(); + return conversationalService.retrieveCountCallback(); + } + + public int runConversationAgeTimeout(){ + calls.append("runConversationAgeTimeout,"); + // done in other testing + return clientCount; + } + public int runConversationIdleTimeout(){ + calls.append("runConversationIdleTimeout,"); + // done in other testing + return clientCount; + } + public int runConversationPrincipleError(){ + calls.append("runConversationPrincipleError,"); + // TODO - when policy framework is done + return clientCount; + } + + + // From ConversationalCallback + @Init + public void init(){ + calls.append("init,"); + } + + @Destroy + public void destroy(){ + calls.append("destroy,"); + } + + public void initializeCount(int count){ + calls.append("initializeCount,"); + callbackCount += count; + } + + public void incrementCount(){ + calls.append("incrementCount,"); + callbackCount++; + } + + public int retrieveCount(){ + calls.append("retrieveCount,"); + return callbackCount; + } + + public void businessException() throws Exception { + throw new Exception("Business Exception"); + } + + public String endConversation(){ + calls.append("endConversation,"); + callbackCount = 0; + return null; + } + + public String getCalls() { + return calls.toString(); + } + + public String getServiceCalls() { + return conversationalService.getCalls().toString(); + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatelessImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatelessImpl.java new file mode 100644 index 0000000000..b12e094bc1 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientStatelessImpl.java @@ -0,0 +1,253 @@ +/* + * 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 conversation.client; + + +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import conversation.referenceclient.ConversationalReferenceClient; +import conversation.service.ConversationalService; + +/** + * The client for the conversational itest which presents a stateful + * callback interface + * + * @version $Rev$ $Date$ + */ + +@Service(interfaces={ConversationalClient.class}) +@Scope("STATELESS") +public class ConversationalClientStatelessImpl implements ConversationalClient, ConversationalCallback { + + @Context + protected ComponentContext componentContext; + + @Reference + protected ConversationalService conversationalService; + + @Reference + protected ConversationalReferenceClient conversationalReferenceClient; + + private int clientCount = 0; + private int callbackCount = 0; + + // a static member variable that records the number of times this service is called + public static StringBuffer calls = new StringBuffer(); + + // From ConversationalClient + public int runConversationFromInjectedReference(){ + calls.append("runConversationFromInjectedReference,"); + conversationalService.initializeCount(1); + conversationalService.incrementCount(); + clientCount = conversationalService.retrieveCount(); + conversationalService.endConversation(); + + return clientCount; + } + public int runConversationFromServiceReference(){ + calls.append("runConversationFromServiceReference,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + // serviceReference.getConversation().end(); + + return clientCount; + } + public int runConversationWithUserDefinedConversationId(){ + calls.append("runConversationWithUserDefinedConversationId,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + // serviceReference.getConversation().end(); + + return clientCount; + } + public String runConversationCheckUserDefinedConversationId(){ + calls.append("runConversationCheckUserDefinedConversationId,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + serviceReference.setConversationID("MyConversation2"); + + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + clientCount = callableReference.retrieveCount(); + return callableReference.endConversation(); + + } + public int runConversationCheckingScope(){ + calls.append("runConversationCheckingScope,"); + // run a conversation + return runConversationFromInjectedReference(); + + // test will then use a static method to find out how many times + // init/destroy were called + } + public int runConversationWithCallback(){ + calls.append("runConversationWithCallback,"); + conversationalService.initializeCountCallback(1); + conversationalService.incrementCountCallback(); + clientCount = conversationalService.retrieveCountCallback(); + conversationalService.endConversationCallback(); + + return clientCount; + } + + public int runConversationHavingPassedReference(){ + calls.append("runConversationHavingPassedReference,"); + ServiceReference<ConversationalService> serviceReference = componentContext.getServiceReference(ConversationalService.class, + "conversationalService"); + ConversationalService callableReference = serviceReference.getService(); + + callableReference.initializeCount(1); + callableReference.incrementCount(); + conversationalReferenceClient.incrementCount(serviceReference); + clientCount = callableReference.retrieveCount(); + callableReference.endConversation(); + + // serviceReference.getConversation().end(); + + return clientCount; + } + + public String runConversationBusinessException(){ + calls.append("runConversationbusinessException,"); + try { + conversationalService.initializeCount(1); + conversationalService.businessException(); + clientCount = conversationalService.retrieveCount(); + conversationalService.endConversation(); + } catch(Exception ex) { + return ex.getMessage(); + } + + return "No Exception Returned"; + } + + public String runConversationBusinessExceptionCallback(){ + calls.append("runConversationbusinessExceptionCallback,"); + try { + conversationalService.initializeCountCallback(1); + conversationalService.businessExceptionCallback(); + clientCount = conversationalService.retrieveCountCallback(); + conversationalService.endConversationCallback(); + } catch(Exception ex) { + return ex.getMessage(); + } + + return "No Exception Returned"; + } + + public int runConversationCallingEndedConversation(){ + calls.append("runConversationCallingEndedConversation,"); + conversationalService.initializeCount(1); + conversationalService.endConversation(); + return conversationalService.retrieveCount(); + } + + public int runConversationCallingEndedConversationCallback(){ + calls.append("runConversationCallingEndedConversationCallback,"); + conversationalService.initializeCountCallback(1); + conversationalService.endConversationCallback(); + return conversationalService.retrieveCountCallback(); + } + + public int runConversationAgeTimeout(){ + calls.append("runConversationAgeTimeout,"); + // done in other testing + return clientCount; + } + public int runConversationIdleTimeout(){ + calls.append("runConversationIdleTimeout,"); + // done in other testing + return clientCount; + } + public int runConversationPrincipleError(){ + calls.append("runConversationPrincipleError,"); + // TODO - when policy framework is done + return clientCount; + } + + + // From ConversationalCallback + @Init + public void init(){ + calls.append("init,"); + + } + + @Destroy + public void destroy(){ + calls.append("destroy,"); + + } + + public void initializeCount(int count){ + calls.append("initializeCount,"); + callbackCount = 0; + } + + public void incrementCount(){ + calls.append("incrementCount,"); + callbackCount++; + } + + public int retrieveCount(){ + calls.append("retrieveCount,"); + return callbackCount; + } + + public void businessException() throws Exception { + throw new Exception("Business Exception"); + } + + public String endConversation(){ + calls.append("endConversation,"); + return null; + } + + public String getCalls() { + return calls.toString(); + } + + public String getServiceCalls() { + return conversationalService.getCalls().toString(); + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClient.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClient.java new file mode 100644 index 0000000000..59e128b993 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClient.java @@ -0,0 +1,38 @@ +/* + * 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 conversation.referenceclient; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.annotations.Remotable; + +import conversation.service.ConversationalService; + +/** + * The client that calls into an existing conversation by accepting + * a reference to that conversation + * + * @version $Rev$ $Date$ + */ + +@Remotable +public interface ConversationalReferenceClient { + + public void incrementCount(CallableReference<ConversationalService> conversationalService); + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientActivator.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientActivator.java new file mode 100644 index 0000000000..ff6f16cba3 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientActivator.java @@ -0,0 +1,66 @@ +/* + * 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 conversation.referenceclient; + +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; + +/* + * OSGi bundle activator for conversation tests + */ +public class ConversationalReferenceClientActivator implements BundleActivator, ServiceListener { + + + private BundleContext bundleContext; + + + public void start(BundleContext bc) throws Exception { + + System.out.println("Started OSGiConversationReferenceClientActivator "); + + this.bundleContext = bc; + + bc.addServiceListener(this); + + Hashtable<String, Object> serviceProps; + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalReferenceClient"); + ConversationalReferenceClientImpl refClient = new ConversationalReferenceClientImpl(); + bundleContext.registerService(ConversationalReferenceClient.class.getName(), refClient, serviceProps); + + } + + + + public void stop(BundleContext bc) { + } + + public void serviceChanged(ServiceEvent event) { + + if (event.getType() == ServiceEvent.REGISTERED) { + + } + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientImpl.java new file mode 100644 index 0000000000..4524c6bd3d --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/referenceclient/ConversationalReferenceClientImpl.java @@ -0,0 +1,45 @@ +/* + * 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 conversation.referenceclient; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Service; + +import conversation.service.ConversationalService; + +/** + * A client component that accepts a reference to an ongoing conversation + * and takes part in that conversation + * + * @version $Rev$ $Date$ + */ + +@Service(interfaces={ConversationalReferenceClient.class}) +@AllowsPassByReference +public class ConversationalReferenceClientImpl implements ConversationalReferenceClient{ + + public void incrementCount(CallableReference<ConversationalService> conversationalService){ + ConversationalService callableReference = conversationalService.getService(); + + callableReference.incrementCount(); + } + + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalService.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalService.java new file mode 100644 index 0000000000..bcd24ef0b1 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalService.java @@ -0,0 +1,65 @@ +/* + * 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 conversation.service; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.Remotable; + +import conversation.client.ConversationalCallback; + + +/** + * The service interface used when testing conversations + * + * @version $Rev$ $Date$ + */ +@Remotable +@Conversational +@Callback(ConversationalCallback.class) +public interface ConversationalService { + + public void init(); + + public void destroy(); + + public void initializeCount(int count); + + public void incrementCount(); + + public int retrieveCount(); + + public void businessException() throws Exception; + + public void initializeCountCallback(int count); + + public void incrementCountCallback(); + + public int retrieveCountCallback(); + + public void businessExceptionCallback() throws Exception; + + @EndsConversation + public String endConversation(); + + public String endConversationCallback(); + + public String getCalls(); +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceActivator.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceActivator.java new file mode 100644 index 0000000000..903f8bf229 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceActivator.java @@ -0,0 +1,76 @@ +/* + * 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 conversation.service; + +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; + + +/* + * OSGi bundle activator for conversation tests + */ +public class ConversationalServiceActivator implements BundleActivator, ServiceListener { + + + private BundleContext bundleContext; + + + public void start(BundleContext bc) throws Exception { + + System.out.println("Started OSGiConversationServiceActivator "); + + this.bundleContext = bc; + + bc.addServiceListener(this); + + Hashtable<String, Object> serviceProps; + + serviceProps = new Hashtable<String, Object>(); + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalServiceStateful"); + Object statefulService = + new ConversationalServiceFactory(ConversationalServiceStatefulImpl.class); + bundleContext.registerService(ConversationalService.class.getName(), statefulService, serviceProps); + + serviceProps = new Hashtable<String, Object>(); + serviceProps.put("component.name", "ConversationalServiceStateless"); + ConversationalServiceStatelessImpl statelessService = new ConversationalServiceStatelessImpl(); + bundleContext.registerService(ConversationalService.class.getName(), statelessService, serviceProps); + + + } + + + + public void stop(BundleContext bc) { + } + + public void serviceChanged(ServiceEvent event) { + + if (event.getType() == ServiceEvent.REGISTERED) { + + } + } + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceFactory.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceFactory.java new file mode 100644 index 0000000000..fe8bd23f07 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceFactory.java @@ -0,0 +1,52 @@ +/* + * 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 conversation.service; + +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceFactory; +import org.osgi.framework.ServiceRegistration; + + +public class ConversationalServiceFactory implements ServiceFactory { + + private Class<?> clazz; + + public ConversationalServiceFactory(Class<?> clazz) { + this.clazz = clazz; + } + + public Object getService(Bundle bundle, ServiceRegistration reg) { + + try { + return clazz.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + } + + public void ungetService(Bundle bundle, ServiceRegistration reg, Object obj) { + + } + + + +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatefulImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatefulImpl.java new file mode 100644 index 0000000000..ec30d641ac --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatefulImpl.java @@ -0,0 +1,121 @@ +/* + * 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 conversation.service; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import conversation.client.ConversationalCallback; + + +/** + * The service used when testing stateful conversations + * + * @version $Rev$ $Date$ + */ +@Service(ConversationalService.class) +@Scope("CONVERSATION") +@ConversationAttributes(maxAge="10 minutes", + maxIdleTime="5 minutes", + singlePrincipal=false) +public class ConversationalServiceStatefulImpl implements ConversationalService { + + @ConversationID + protected String conversationId; + + @Callback + protected ConversationalCallback conversationalCallback; + + // local count - accumulates during the conversation + private int count = 0; + + // a static member variable that records the number of times this service is called + public static StringBuffer calls = new StringBuffer(); + + @Init + public void init(){ + calls.append("init,"); + } + + @Destroy + public void destroy(){ + calls.append("destroy,"); + } + + public void initializeCount(int count){ + calls.append("initializeCount,"); + this.count = count; + } + + public void incrementCount(){ + calls.append("incrementCount,"); + count++; + } + + public int retrieveCount(){ + calls.append("retrieveCount,"); + return count; + } + + public void businessException() throws Exception { + throw new Exception("Business Exception"); + } + + public void initializeCountCallback(int count){ + calls.append("initializeCountCallback,"); + this.count = count; + conversationalCallback.initializeCount(count); + } + + public void incrementCountCallback(){ + calls.append("incrementCountCallback,"); + count++; + conversationalCallback.incrementCount(); + } + + public int retrieveCountCallback(){ + calls.append("retrieveCountCallback,"); + return conversationalCallback.retrieveCount(); + } + + public void businessExceptionCallback() throws Exception { + calls.append("businessExceptionCallback,"); + conversationalCallback.businessException(); + } + + public String endConversation(){ + calls.append("endConversation,"); + count = 0; + return conversationId; + } + + public String endConversationCallback(){ + calls.append("endConversationCallback,"); + return conversationalCallback.endConversation(); + } + + public String getCalls() { + return calls.toString(); + } +} diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatelessImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatelessImpl.java new file mode 100644 index 0000000000..34baca71d1 --- /dev/null +++ b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/conversation/service/ConversationalServiceStatelessImpl.java @@ -0,0 +1,127 @@ +/* + * 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 conversation.service; + +import java.util.HashMap; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import conversation.client.ConversationalCallback; + + +/** + * The service used when testing stateful conversations + * + * @version $Rev$ $Date$ + */ +@Service(ConversationalService.class) +@Scope("STATELESS") +public class ConversationalServiceStatelessImpl implements ConversationalService { + + @ConversationID + protected String conversationId; + + @Callback + protected ConversationalCallback conversationalCallback; + + // static area in which to hold conversational data + private static HashMap<String, Integer> conversationalState = new HashMap<String, Integer>(); + + // a static member variable that records the number of times this service is called + public static StringBuffer calls = new StringBuffer(); + + @Init + public void init(){ + calls.append("init,"); + } + + @Destroy + public void destroy(){ + calls.append("destroy,"); + } + + public void initializeCount(int count){ + calls.append("initializeCount,"); + Integer conversationalCount = new Integer(count); + conversationalState.put(conversationId, conversationalCount); + } + + public void incrementCount(){ + calls.append("incrementCount,"); + Integer conversationalCount = conversationalState.get(conversationId); + conversationalCount++; + conversationalState.put(conversationId, conversationalCount); + } + + public int retrieveCount(){ + calls.append("retrieveCount,"); + Integer count = conversationalState.get(conversationId); + if (count != null){ + return count.intValue(); + } else { + return -999; + } + } + + public void businessException() throws Exception { + throw new Exception("Business Exception"); + } + + public void initializeCountCallback(int count){ + calls.append("initializeCountCallback,"); + initializeCount(count); + conversationalCallback.initializeCount(count); + } + + public void incrementCountCallback(){ + calls.append("incrementCountCallback,"); + incrementCount(); + conversationalCallback.incrementCount(); + } + + public int retrieveCountCallback(){ + calls.append("retrieveCountCallback,"); + return conversationalCallback.retrieveCount(); + } + + public void businessExceptionCallback() throws Exception { + calls.append("businessExceptionCallback,"); + conversationalCallback.businessException(); + } + + public String endConversation(){ + calls.append("endConversation,"); + conversationalState.remove(conversationId); + return conversationId; + } + + public String endConversationCallback(){ + calls.append("endConversationCallback,"); + return conversationalCallback.endConversation(); + } + + public String getCalls() { + return calls.toString(); + } +} |