From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/services/bindings/binding.axis2/.ruleset | 190 +++ .../services/bindings/binding.axis2/LICENSE.txt | 202 ++++ .../sca/services/bindings/binding.axis2/NOTICE.txt | 14 + .../sca/services/bindings/binding.axis2/pom.xml | 163 +++ .../binding.axis2/src/main/assembly/axis2.xml | 38 + .../binding/axis2/Axis2AsyncTargetInvoker.java | 84 ++ .../tuscany/binding/axis2/Axis2BindingBuilder.java | 208 ++++ .../axis2/Axis2BindingBuilderRuntimeException.java | 65 + .../axis2/Axis2BindingRunTimeException.java | 48 + .../axis2/Axis2CallbackInvocationHandler.java | 74 ++ .../binding/axis2/Axis2OneWayTargetInvoker.java | 71 ++ .../tuscany/binding/axis2/Axis2Reference.java | 187 +++ .../binding/axis2/Axis2ReferenceCallback.java | 55 + .../axis2/Axis2ReferenceCallbackTargetInvoker.java | 100 ++ .../apache/tuscany/binding/axis2/Axis2Service.java | 290 +++++ .../axis2/Axis2ServiceCallbackTargetInvoker.java | 114 ++ .../axis2/Axis2ServiceInMessageReceiver.java | 67 + .../Axis2ServiceInOutAsyncMessageReceiver.java | 95 ++ .../Axis2ServiceInOutSyncMessageReceiver.java | 73 ++ .../tuscany/binding/axis2/Axis2ServiceServlet.java | 207 ++++ .../tuscany/binding/axis2/Axis2TargetInvoker.java | 136 +++ .../tuscany/binding/axis2/WebServiceBinding.java | 78 ++ .../binding/axis2/WebServiceBindingLoader.java | 143 +++ .../axis2/util/TuscanyAxisConfigurator.java | 44 + .../axis2/util/WebServiceOperationMetaData.java | 491 ++++++++ .../binding/axis2/util/WebServicePortMetaData.java | 377 ++++++ .../main/resources/META-INF/sca/binding.axis2.scdl | 48 + .../src/main/resources/META-INF/sca/default.scdl | 49 + .../tuscany/binding/axis2/engine/config/axis2.xml | 302 +++++ .../binding/axis2/Axis2ReferenceTestCase.java | 105 ++ .../binding/axis2/Axis2ServiceTestCase.java | 150 +++ .../org/apache/tuscany/binding/axis2/Greeter.java | 31 + .../tuscany/binding/axis2/GreetingCallback.java | 24 + .../test/resources/wsdl/hello_world_doc_lit.wsdl | 169 +++ .../services/bindings/binding.celtix/.checkstyle | 24 + .../sca/services/bindings/binding.celtix/.pmd | 23 + .../sca/services/bindings/binding.celtix/.ruleset | 190 +++ .../services/bindings/binding.celtix/LICENSE.txt | 202 ++++ .../services/bindings/binding.celtix/NOTICE.txt | 14 + .../services/bindings/binding.celtix/README.txt | 35 + .../sca/services/bindings/binding.celtix/pom.xml | 96 ++ .../apache/tuscany/binding/celtix/BusService.java | 35 + .../tuscany/binding/celtix/BusServiceImpl.java | 77 ++ .../binding/celtix/CeltixBindingBuilder.java | 104 ++ .../tuscany/binding/celtix/CeltixInvoker.java | 245 ++++ .../tuscany/binding/celtix/CeltixReference.java | 66 + .../tuscany/binding/celtix/CeltixService.java | 270 +++++ .../binding/celtix/CeltixServiceInitException.java | 43 + .../binding/celtix/InvokerCreationException.java | 43 + .../tuscany/binding/celtix/TuscanyWSDLManager.java | 89 ++ .../tuscany/binding/celtix/WebServiceBinding.java | 90 ++ .../binding/celtix/WebServiceBindingLoader.java | 195 +++ .../tuscany/binding/celtix/io/NodeDataReader.java | 205 ++++ .../tuscany/binding/celtix/io/NodeDataWriter.java | 322 +++++ .../celtix/io/RawByteArrayOutputStream.java | 30 + .../binding/celtix/io/SCADataBindingCallback.java | 83 ++ .../celtix/io/SCAServerDataBindingCallback.java | 69 ++ .../src/main/resources/META-INF/sca/default.scdl | 31 + .../tuscany/binding/celtix/BootstrapTestCase.java | 35 + .../binding/celtix/CeltixInvokerTestCase.java | 134 ++ .../binding/celtix/CeltixServiceTestCase.java | 129 ++ .../org/apache/tuscany/binding/celtix/Greeter.java | 32 + .../apache/tuscany/binding/celtix/GreeterImpl.java | 33 + .../src/test/resources/wsdl/hello_world.wsdl | 181 +++ .../test/resources/wsdl/hello_world_doc_lit.wsdl | 154 +++ .../resources/wsdl/hello_world_doc_lit_inout.wsdl | 181 +++ .../bindings/binding.celtix/tuscany-checkstyle.xml | 288 +++++ .../sca/services/bindings/binding.jsonrpc/.ruleset | 190 +++ .../services/bindings/binding.jsonrpc/LICENSE.txt | 202 ++++ .../services/bindings/binding.jsonrpc/NOTICE.txt | 14 + .../sca/services/bindings/binding.jsonrpc/pom.xml | 59 + .../tuscany/binding/jsonrpc/JSONRPCBinding.java | 38 + .../binding/jsonrpc/JSONRPCBindingBuilder.java | 56 + .../binding/jsonrpc/JSONRPCBindingLoader.java | 57 + .../binding/jsonrpc/JSONRPCEntryPointServlet.java | 71 ++ .../tuscany/binding/jsonrpc/JSONRPCService.java | 56 + .../binding/jsonrpc/ScriptGetterServlet.java | 52 + .../resources/META-INF/sca/binding.jsonrpc.scdl | 42 + .../src/main/resources/META-INF/sca/default.scdl | 43 + .../resources/META-INF/sca/jsonrpc_extension.scdl | 42 + .../org/apache/tuscany/binding/jsonrpc/jsonrpc.js | 484 ++++++++ .../sca/services/bindings/binding.rmi/.ruleset | 190 +++ .../sca/services/bindings/binding.rmi/LICENSE.txt | 202 ++++ .../sca/services/bindings/binding.rmi/NOTICE.txt | 14 + .../sca/services/bindings/binding.rmi/pom.xml | 63 + .../binding/rmi/NoRemoteMethodException.java | 37 + .../binding/rmi/NoRemoteServiceException.java | 37 + .../org/apache/tuscany/binding/rmi/RMIBinding.java | 57 + .../tuscany/binding/rmi/RMIBindingBuilder.java | 78 ++ .../tuscany/binding/rmi/RMIBindingLoader.java | 64 + .../org/apache/tuscany/binding/rmi/RMIInvoker.java | 66 + .../apache/tuscany/binding/rmi/RMIReference.java | 87 ++ .../tuscany/binding/rmi/RMIRuntimeException.java | 39 + .../org/apache/tuscany/binding/rmi/RMIService.java | 160 +++ .../tuscany/binding/rmi/RemoteMethodHandler.java | 47 + .../tuscany/binding/rmi/host/RMIHostImpl.java | 136 +++ .../src/main/resources/META-INF/sca/default.scdl | 55 + .../main/resources/META-INF/sca/rmi_extension.scdl | 42 + .../src/test/java/helloworld/HelloWorldImpl.java | 32 + .../test/java/helloworld/HelloWorldRmiImpl.java | 45 + .../test/java/helloworld/HelloWorldRmiService.java | 28 + .../test/java/helloworld/HelloWorldService.java | 28 + .../tuscany/binding/rmi/BindingTestCase.java | 54 + .../rmi/NoRemoteMethodExceptionTestCase.java | 47 + .../rmi/NoRemoteServiceExceptionTestCase.java | 47 + .../binding/rmi/RMIBindingBuilderTestCase.java | 48 + .../binding/rmi/RMIBindingLoaderTestCase.java | 74 ++ .../tuscany/binding/rmi/RMIBindingTestCase.java | 40 + .../tuscany/binding/rmi/RMIInvokerTestCase.java | 84 ++ .../tuscany/binding/rmi/RMIReferenceTestCase.java | 48 + .../tuscany/binding/rmi/RMIServiceTestCase.java | 53 + .../binding/rmi/RemoteMethodHandlerTestCase.java | 42 + .../binding/rmi/host/RMIHostImplTestCase.java | 76 ++ .../test/resources/HelloWorldImpl.componentType | 27 + .../test/resources/HelloWorldRmiImpl.componentType | 29 + .../src/test/resources/META-INF/LICENSE.txt | 1277 ++++++++++++++++++++ .../binding.rmi/src/test/resources/META-INF/NOTICE | 18 + .../src/test/resources/META-INF/sca/default.scdl | 44 + .../services/bindings/binding.servicemix/pom.xml | 60 + .../org/apache/servicemix/sca/ScaBootstrap.java | 169 +++ .../org/apache/servicemix/sca/ScaComponent.java | 43 + .../org/apache/servicemix/sca/ScaDeployer.java | 60 + .../org/apache/servicemix/sca/ScaEndpoint.java | 157 +++ .../org/apache/servicemix/sca/ScaLifeCycle.java | 30 + .../org/apache/servicemix/sca/ScaServiceUnit.java | 113 ++ .../sca/assembly/JbiAssemblyFactory.java | 33 + .../apache/servicemix/sca/assembly/JbiBinding.java | 85 ++ .../sca/assembly/impl/JbiAssemblyFactoryImpl.java | 44 + .../sca/assembly/impl/JbiBindingImpl.java | 166 +++ .../sca/builder/ExternalJbiServiceBuilder.java | 151 +++ .../sca/builder/ExternalJbiServiceWireBuilder.java | 70 ++ .../sca/builder/JbiServiceEntryPointBuilder.java | 169 +++ .../config/ExternalJbiServiceContextFactory.java | 30 + .../config/JbiServiceEntryPointContextFactory.java | 30 + .../sca/handler/ExternalJbiServiceClient.java | 94 ++ .../handler/ExternalJbiServiceTargetInvoker.java | 110 ++ .../servicemix/sca/loader/JbiBindingLoader.java | 75 ++ .../servicemix/sca/tuscany/BootstrapHelper.java | 125 ++ .../sca/tuscany/CommonsLoggingMonitorFactory.java | 90 ++ .../servicemix/sca/tuscany/TuscanyRuntime.java | 174 +++ .../org/apache/tuscany/servicemix/JBIBinding.java | 47 + .../tuscany/servicemix/JBIBindingLoader.java | 63 + .../tuscany/servicemix/ServiceMixBuilder.java | 57 + .../tuscany/servicemix/ServiceMixInvoker.java | 77 ++ .../tuscany/servicemix/ServiceMixReference.java | 54 + .../tuscany/servicemix/ServiceMixService.java | 42 + .../src/main/jbi/META-INF/DISCLAIMER | 6 + .../src/main/jbi/META-INF/LICENSE | 203 ++++ .../src/main/jbi/META-INF/NOTICE | 11 + .../apache/servicemix/sca/AssemblyLoaderTest.java | 74 ++ .../apache/servicemix/sca/ScaComponentTest.java | 110 ++ .../sca/bigbank/account/AccountReportRequest.java | 43 + .../sca/bigbank/account/AccountReportResponse.java | 45 + .../sca/bigbank/account/AccountService.java | 27 + .../sca/bigbank/account/AccountServiceImpl.java | 93 ++ .../sca/bigbank/account/AccountSummary.java | 68 ++ .../bigbank/accountdata/AccountDataService.java | 28 + .../accountdata/AccountDataServiceImpl.java | 50 + .../sca/bigbank/accountdata/CheckingAccount.java | 41 + .../sca/bigbank/accountdata/SavingsAccount.java | 41 + .../sca/bigbank/accountdata/StockAccount.java | 50 + .../sca/bigbank/stockquote/StockQuoteRequest.java | 43 + .../sca/bigbank/stockquote/StockQuoteResponse.java | 43 + .../sca/bigbank/stockquote/StockQuoteService.java | 29 + .../src/test/resources/log4j-tests.properties | 38 + .../src/test/resources/log4j.properties | 39 + .../sca/bigbank/account/AccountService.wsdl | 80 ++ .../org/apache/servicemix/sca/bigbank/sca.module | 56 + .../sca-java-M2/sca/services/bindings/pom.xml | 63 + .../sca/services/bindings/sunjars/build.xml | 56 + .../sca/services/bindings/sunjars/pom.xml | 102 ++ 171 files changed, 17018 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/NOTICE.txt create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/assembly/axis2.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/binding.axis2.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/default.scdl create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/org/apache/tuscany/binding/axis2/engine/config/axis2.xml create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ServiceTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Greeter.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/GreetingCallback.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/resources/wsdl/hello_world_doc_lit.wsdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.pmd create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/NOTICE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/README.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world.wsdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit.wsdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit_inout.wsdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/tuscany-checkstyle.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/NOTICE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServlet.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/binding.jsonrpc.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/jsonrpc_extension.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/org/apache/tuscany/binding/jsonrpc/jsonrpc.js create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/.ruleset create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/NOTICE.txt create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RemoteMethodHandler.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/host/RMIHostImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/rmi_extension.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldRmiImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaBootstrap.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaComponent.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaDeployer.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportRequest.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportResponse.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountSummary.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/CheckingAccount.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/SavingsAccount.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/StockAccount.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteRequest.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteResponse.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteService.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j-tests.properties create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j.properties create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/build.xml create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/pom.xml (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/bindings') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/.ruleset b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/.ruleset new file mode 100644 index 0000000000..70a035bc01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/LICENSE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, serviceDefinition marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/NOTICE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/pom.xml new file mode 100755 index 0000000000..e9d32c7f9c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/pom.xml @@ -0,0 +1,163 @@ + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + 4.0.0 + axis2 + Apache Tuscany Binding for Axis2 + Implementation of the SCA Web Services binding using Axis2. + + + + + apache.ws.zones + Apache WS zones Repository + http://ws.zones.apache.org/repository/ + legacy + + false + + + + + + + org.apache.tuscany.sca.services.idl + wsdl + ${sca.version} + compile + + + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + ${sca.version} + runtime + + + + javax.servlet + servlet-api + + + + + + org.apache.axis2 + axis2-kernel + + + + org.apache.ws.commons.axiom + axiom-api + + + + org.apache.ws.commons.axiom + axiom-impl + + + + incubator-woden + woden + 1.0.0M6 + runtime + + + + woodstox + wstx-asl + + + + commons-logging + commons-logging + 1.1 + runtime + + + + org.apache.ws.commons.neethi + neethi + 2.0 + runtime + + + + org.apache.ws.commons.schema + XmlSchema + + + + commons-httpclient + commons-httpclient + 3.0.1 + runtime + + + + javax.mail + mail + 1.4 + runtime + + + + backport-util-concurrent + backport-util-concurrent + 2.2 + runtime + + + + commons-codec + commons-codec + 1.3 + runtime + + + + httpcomponents-httpcore + jakarta-httpcore + 4.0-alpha2 + runtime + + + + + + + org.easymock + easymock + + + + org.apache.tuscany.sca + test + ${sca.version} + test + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/assembly/axis2.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/assembly/axis2.xml new file mode 100644 index 0000000000..7c835caa5c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/assembly/axis2.xml @@ -0,0 +1,38 @@ + + + + bin + false + + zip + tar.gz + + + + + extension + + org.apache.tuscany.bindings:axis2 + + 644 + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java new file mode 100644 index 0000000000..0cf3976f37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java @@ -0,0 +1,84 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; + +public class Axis2AsyncTargetInvoker extends Axis2TargetInvoker { + + protected static final OMElement RESPONSE = null; + + private InboundWire wire; + private Object messageId; + private Axis2ReferenceCallbackTargetInvoker callbackInvoker; + + public Axis2AsyncTargetInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory, + InboundWire wire) { + super(serviceClient, wsdlOperationName, options, soapFactory); + this.wire = wire; + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException { + try { + Object[] args = (Object[])payload; + OperationClient operationClient = createOperationClient(args); + callbackInvoker.setCorrelationId(messageId); + Axis2ReferenceCallback callback = new Axis2ReferenceCallback(callbackInvoker); + operationClient.setCallback(callback); + + operationClient.execute(false); + + // REVIEW it seems ok to return null + return RESPONSE; + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + wire.addMapping(msg.getMessageId(), msg.getFromAddress()); + messageId = msg.getMessageId(); + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public void setCallbackTargetInvoker(Axis2ReferenceCallbackTargetInvoker callbackInvoker) { + this.callbackInvoker = callbackInvoker; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java new file mode 100755 index 0000000000..1090be874d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java @@ -0,0 +1,208 @@ +/* + * 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.tuscany.binding.axis2; + +import javax.wsdl.Port; +import javax.wsdl.PortType; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.tuscany.binding.axis2.util.TuscanyAxisConfigurator; +import org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector; +import org.apache.tuscany.idl.wsdl.WSDLServiceContract; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.builder.BuilderConfigException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; + +/** + * Builds a {@link org.osoa.sca.annotations.Service} or {@link org.apache.tuscany.spi.component.Reference} configured + * with the Axis2 binding + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingBuilder extends BindingBuilderExtension { + private static final String OM_DATA_BINDING = OMElement.class.getName(); + + private ServletHost servletHost; + + private ConfigurationContext configContext; + + private WorkContext workContext; + + private InterfaceWSDLIntrospector introspector; + + public Axis2BindingBuilder() { + initAxis(); + } + + @Autowire(required = false) + public void setServletHost(ServletHost servletHost) { + this.servletHost = servletHost; + } + + /** + * @param introspector the introspector to set + */ + @Autowire + public void setIntrospector(InterfaceWSDLIntrospector introspector) { + this.introspector = introspector; + } + + @Autowire + public void setWorkContext(WorkContext workContext) { + this.workContext = workContext; + } + + @SuppressWarnings("unchecked") + public Service build( + CompositeComponent parent, + BoundServiceDefinition serviceDefinition, + DeploymentContext deploymentContext) { + + try { + // Set the default databinding + ServiceContract outboundContract = serviceDefinition.getServiceContract(); + if (WSDLServiceContract.class.isInstance(outboundContract)) { + outboundContract.setDataBinding(OM_DATA_BINDING); + } + + // FIXME: We need to define how the WSDL PortType is honored in the case that + // both the binding.ws and interface.wsdl are in place. + // The WSDL portType from the WSDL Port decides the incoming SOAP message format + // There are also cases that interface.java is used. + + ServiceContract inboundContract = null; + WebServiceBinding wsBinding = serviceDefinition.getBinding(); + Port port = wsBinding.getWSDLPort(); + if (port == null) { + // FIXME: [rfeng] No WSDL is referenced by binding.ws, we need to create one from + // the outbound service contract if it's JavaServiceContract + inboundContract = outboundContract; + } + + PortType portType = wsBinding.getWSDLPort().getBinding().getPortType(); + inboundContract = introspector.introspect(portType); + + // FIXME: + inboundContract.setInterfaceClass(serviceDefinition.getServiceContract().getInterfaceClass()); + inboundContract.setDataBinding(OM_DATA_BINDING); + inboundContract.setCallbackName(serviceDefinition.getServiceContract().getCallbackName()); + + try { + wireService.checkCompatibility(inboundContract, outboundContract, true); + } catch (IncompatibleServiceContractException e) { + throw new Axis2BindingBuilderRuntimeException(e); + } + + Service service = new Axis2Service(serviceDefinition.getName(), outboundContract, parent, wireService, wsBinding, + servletHost, configContext, workContext); + service.setBindingServiceContract(inboundContract); + + return service; + + } catch (InvalidServiceContractException e) { + throw new Axis2BindingBuilderRuntimeException(e); + } + } + + @SuppressWarnings("unchecked") + public Reference build( + CompositeComponent parent, + BoundReferenceDefinition boundReferenceDefinition, + DeploymentContext deploymentContext) { + + try { + // Set the default binding + ServiceContract inboundContract = boundReferenceDefinition.getServiceContract(); + if (WSDLServiceContract.class.isInstance(inboundContract)) { + inboundContract.setDataBinding(OM_DATA_BINDING); + } + + // FIXME: We need to define how the WSDL PortType is honored in the case that + // both the binding.ws and interface.wsdl are in place + // The WSDL portType from the WSDL Port decides the incoming SOAP message format + + ServiceContract outboundContract = inboundContract; + WebServiceBinding wsBinding = boundReferenceDefinition.getBinding(); + Port port = wsBinding.getWSDLPort(); + if (port == null) { + // FIXME: [rfeng] No WSDL is referenced by binding.ws, we need to create one from + // the inbound service contract if it's JavaServiceContract + outboundContract = inboundContract; + } + PortType portType = port.getBinding().getPortType(); + outboundContract = introspector.introspect(portType); + + // Set the default databinding + outboundContract.setDataBinding(OM_DATA_BINDING); + + try { + wireService.checkCompatibility(inboundContract, outboundContract, true); + } catch (IncompatibleServiceContractException e) { + throw new Axis2BindingBuilderRuntimeException(e); + } + + Reference reference = new Axis2Reference(boundReferenceDefinition.getName(), parent, wireService, wsBinding, + inboundContract, workContext); + reference.setBindingServiceContract(outboundContract); + + return reference; + + } catch (InvalidServiceContractException e) { + throw new Axis2BindingBuilderRuntimeException(e); + } + } + + protected Class getBindingType() { + return WebServiceBinding.class; + } + + protected void initAxis() { + // TODO: Fix classloader switching. See TUSCANY-647 + // TODO: also consider having a system component wrapping the Axis2 ConfigContext + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + ClassLoader scl = getClass().getClassLoader(); + try { + if (tccl != scl) { + Thread.currentThread().setContextClassLoader(scl); + } + try { + this.configContext = new TuscanyAxisConfigurator().getConfigurationContext(); + } catch (AxisFault e) { + throw new BuilderConfigException(e); + } + } finally { + if (tccl != scl) { + Thread.currentThread().setContextClassLoader(tccl); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java new file mode 100644 index 0000000000..a5743668a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.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 org.apache.tuscany.binding.axis2; + + +/** + * Base class for Exceptions raised during the loading process. Loader implementations should throw a subclass of this + * to indicate the actual problem. + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingBuilderRuntimeException extends Axis2BindingRunTimeException { + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + + public Axis2BindingBuilderRuntimeException() { + } + + public Axis2BindingBuilderRuntimeException(String message) { + super(message); + } + + public Axis2BindingBuilderRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public Axis2BindingBuilderRuntimeException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being loaded. + * + * @return the location of the resource that was being loaded + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being loaded. + * + * @param resourceURI the location of the resource that was being loaded + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java new file mode 100644 index 0000000000..cd957c2ec6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java @@ -0,0 +1,48 @@ +/* + * 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.tuscany.binding.axis2; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Denotes an error creating a new object instance + * + * @version $Rev$ $Date$ + */ +public class Axis2BindingRunTimeException extends TuscanyRuntimeException { + private static final long serialVersionUID = -6423113430265944499L; + + public Axis2BindingRunTimeException() { + super(); + } + + public Axis2BindingRunTimeException(String message) { + super(message); + } + + public Axis2BindingRunTimeException(String message, Throwable cause) { + super(message, cause); + } + + public Axis2BindingRunTimeException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java new file mode 100644 index 0000000000..4a9e054237 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java @@ -0,0 +1,74 @@ +/* + * 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.tuscany.binding.axis2; + +import java.util.Map; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.OutboundInvocationChain; +import org.apache.tuscany.spi.wire.TargetInvoker; + +public class Axis2CallbackInvocationHandler extends AbstractOutboundInvocationHandler { + + private InboundWire inboundWire; + private Object messageId; + private Object correlationId; + + public Axis2CallbackInvocationHandler(InboundWire inboundWire) { + this.inboundWire = inboundWire; + } + + public Object invoke(Operation operation, Object[] args) throws Throwable { + Object targetAddress = inboundWire.retrieveMapping(correlationId); + if (targetAddress == null) { + throw new AssertionError("No from address associated with message id [" + correlationId + "]"); + } + //TODO optimize as this is slow in local invocations + Map, OutboundInvocationChain> sourceCallbackInvocationChains = + inboundWire.getSourceCallbackInvocationChains(targetAddress); + OutboundInvocationChain chain = sourceCallbackInvocationChains.get(operation); + TargetInvoker invoker = chain.getTargetInvoker(); + return invoke(chain, invoker, args); + } + + // This must be called before invoke + public void setMessageId(Object messageId) { + this.messageId = messageId; + } + + // This must be called before invoke + public void setCorrelationId(Object correlationId) { + this.correlationId = correlationId; + } + + protected Object getFromAddress() { + return (inboundWire.getContainer() == null) ? null : inboundWire.getContainer().getName(); + } + + protected Object getMessageId() { + return messageId; + } + + protected Object getCorrelationId() { + return correlationId; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java new file mode 100644 index 0000000000..a85c57313f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java @@ -0,0 +1,71 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; + +public class Axis2OneWayTargetInvoker extends Axis2TargetInvoker { + + protected static final OMElement RESPONSE = null; + + public Axis2OneWayTargetInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory) { + + super(serviceClient, wsdlOperationName, options, soapFactory); + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException { + try { + Object[] args = (Object[])payload; + OperationClient operationClient = createOperationClient(args); + + operationClient.execute(false); + + // REVIEW it seems ok to return null + return RESPONSE; + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } catch (Throwable t) { + throw new Axis2BindingRunTimeException(t); + } + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java new file mode 100755 index 0000000000..53ae1ae51e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java @@ -0,0 +1,187 @@ +/* + * 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.tuscany.binding.axis2; + +import java.util.Collection; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.tuscany.binding.axis2.util.TuscanyAxisConfigurator; +import org.apache.tuscany.binding.axis2.util.WebServiceOperationMetaData; +import org.apache.tuscany.binding.axis2.util.WebServicePortMetaData; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.extension.ReferenceExtension; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.OutboundWire; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; + +/** + * Axis2Reference uses Axis2 to invoke a remote web service + */ +public class Axis2Reference extends ReferenceExtension { + + private WebServicePortMetaData wsPortMetaData; + private ServiceClient serviceClient; + + // private WorkContext workContext; + + @SuppressWarnings("unchecked") + public Axis2Reference(String theName, + CompositeComponent parent, + WireService wireService, + WebServiceBinding wsBinding, + ServiceContract contract, + WorkContext workContext) { + super(theName, (Class)contract.getInterfaceClass(), parent, wireService); + try { + Definition wsdlDefinition = wsBinding.getWSDLDefinition(); + wsPortMetaData = + new WebServicePortMetaData(wsdlDefinition, wsBinding.getWSDLPort(), wsBinding.getURI(), false); + serviceClient = createServiceClient(wsdlDefinition, wsPortMetaData); + // this.workContext = workContext; + } catch (AxisFault e) { + throw new Axis2BindingRunTimeException(e); + } + } + + public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { + Axis2TargetInvoker invoker; + try { + boolean isOneWay = operation.isNonBlocking(); + invoker = createOperationInvoker(serviceClient, operation, wsPortMetaData, false, isOneWay); + } catch (AxisFault e) { + throw new Axis2BindingRunTimeException(e); + } + return invoker; + } + + public TargetInvoker createAsyncTargetInvoker(OutboundWire wire, Operation operation) { + Axis2AsyncTargetInvoker invoker; + try { + // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader + // as parameters. + invoker = + (Axis2AsyncTargetInvoker)createOperationInvoker(serviceClient, + operation, + wsPortMetaData, + true, + false); + // FIXME: This makes the (BIG) assumption that there is only one + // callback method + // Relaxing this assumption, however, does not seem to be trivial, + // it may depend on knowledge + // of what actual callback method was invoked by the service at the + // other end + Operation callbackOperation = findCallbackOperation(); + Axis2CallbackInvocationHandler invocationHandler = + new Axis2CallbackInvocationHandler(inboundWire); + Axis2ReferenceCallbackTargetInvoker callbackInvoker = + new Axis2ReferenceCallbackTargetInvoker(callbackOperation, inboundWire, invocationHandler); + invoker.setCallbackTargetInvoker(callbackInvoker); + } catch (AxisFault e) { + throw new Axis2BindingRunTimeException(e); + } + return invoker; + } + + private Operation findCallbackOperation() { + ServiceContract contract = inboundWire.getServiceContract(); + Operation callbackOperation = null; + Collection callbackOperations = contract.getCallbackOperations().values(); + if (callbackOperations.size() != 1) { + throw new Axis2BindingRunTimeException("Can only handle one callback operation"); + } else { + callbackOperation = (Operation)callbackOperations.iterator().next(); + } + return callbackOperation; + } + + /** + * Create an Axis2 ServiceClient + */ + private ServiceClient createServiceClient(Definition wsdlDefinition, WebServicePortMetaData wsPortMetaData) + throws AxisFault { + + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext(); + QName serviceQName = wsPortMetaData.getServiceName(); + String portName = wsPortMetaData.getPortName().getLocalPart(); + AxisService axisService = + AxisService.createClientSideAxisService(wsdlDefinition, serviceQName, portName, new Options()); + return new ServiceClient(configurationContext, axisService); + } + + /** + * Create and configure an Axis2TargetInvoker for each operations + */ + private Axis2TargetInvoker createOperationInvoker(ServiceClient serviceClient, + Operation m, + WebServicePortMetaData wsPortMetaData, + boolean hasCallback, + boolean isOneWay) throws AxisFault { + SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory(); + String portTypeNS = wsPortMetaData.getPortTypeName().getNamespaceURI(); + + String methodName = m.getName(); + + WebServiceOperationMetaData operationMetaData = wsPortMetaData.getOperationMetaData(methodName); + + Options options = new Options(); + options.setTo(new EndpointReference(wsPortMetaData.getEndpoint())); + options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + + String wsdlOperationName = operationMetaData.getBindingOperation().getOperation().getName(); + + String soapAction = wsPortMetaData.getOperationMetaData(wsdlOperationName).getSOAPAction(); + if (soapAction != null && soapAction.length() > 1) { + options.setAction(soapAction); + } + + options.setTimeOutInMilliSeconds(5 * 60 * 1000); + + QName wsdlOperationQName = new QName(portTypeNS, wsdlOperationName); + + Axis2TargetInvoker invoker; + if (hasCallback) { + invoker = + new Axis2AsyncTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory, + inboundWire); + } else if (isOneWay) { + invoker = new Axis2OneWayTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } else { + invoker = new Axis2TargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } + + return invoker; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java new file mode 100644 index 0000000000..d6bb1a0290 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java @@ -0,0 +1,55 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.client.async.AsyncResult; +import org.apache.axis2.client.async.Callback; +import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; + +public class Axis2ReferenceCallback extends Callback { + + private Axis2ReferenceCallbackTargetInvoker targetInvoker; + + public Axis2ReferenceCallback(Axis2ReferenceCallbackTargetInvoker targetInvoker) { + this.targetInvoker = targetInvoker; + } + + public void onComplete(AsyncResult result) { + MessageContext responseMC = result.getResponseMessageContext(); + OMElement responseOM = responseMC.getEnvelope().getBody().getFirstElement(); + try { + targetInvoker.invokeTarget(new Object[] {responseOM}); + } catch (InvocationTargetException e) { + // FIXME what is the appropriate exception here? + throw new InvocationRuntimeException(e); + } + } + + public void setComplete(boolean complete) { + super.setComplete(complete); + } + + public void onError(Exception e) { + throw new InvocationRuntimeException(e); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java new file mode 100644 index 0000000000..87f9b5654b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; + +public class Axis2ReferenceCallbackTargetInvoker implements TargetInvoker { + + private Operation operation; + private InboundWire inboundWire; + private Object correlationId; + private boolean cacheable; + Axis2CallbackInvocationHandler invocationHandler; + + public Axis2ReferenceCallbackTargetInvoker(Operation operation, + InboundWire inboundWire, + Axis2CallbackInvocationHandler invocationHandler) { + + this.operation = operation; + this.inboundWire = inboundWire; + this.invocationHandler = invocationHandler; + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException { + invocationHandler.setMessageId(null); + invocationHandler.setCorrelationId(correlationId); + Object[] args; + if (payload != null && !payload.getClass().isArray()) { + args = new Object[]{payload}; + } else { + args = (Object[]) payload; + } + try { + return invocationHandler.invoke(operation, args); + } catch(Throwable t) { + t.printStackTrace(); + throw new InvocationTargetException(t); + } + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBodyWithFault(e.getCause()); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public boolean isCacheable() { + return cacheable; + } + + public void setCacheable(boolean cacheable) { + this.cacheable = cacheable; + } + + public boolean isOptimizable() { + return isCacheable(); // we only need to check if the scopes are correct + } + + public Axis2ReferenceCallbackTargetInvoker clone() throws CloneNotSupportedException { + Axis2ReferenceCallbackTargetInvoker invoker = (Axis2ReferenceCallbackTargetInvoker) super.clone(); + invoker.operation = this.operation; + invoker.inboundWire = this.inboundWire; + invoker.correlationId = this.correlationId; + invoker.cacheable = this.cacheable; + invoker.invocationHandler = this.invocationHandler; + return invoker; + } + + public void setCorrelationId(Object correlationId) { + this.correlationId = correlationId; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java new file mode 100755 index 0000000000..47c9d8308a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java @@ -0,0 +1,290 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CountDownLatch; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +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.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants; +import org.apache.tuscany.binding.axis2.util.WebServicePortMetaData; +import org.apache.tuscany.spi.builder.BuilderConfigException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageId; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; +import org.osoa.sca.annotations.Destroy; + +/** + * An implementation of a {@link ServiceExtension} configured with the Axis2 + * binding + * + * @version $Rev$ $Date$ + */ +public class Axis2Service extends ServiceExtension { + private ServiceContract serviceContract; + + private ServletHost servletHost; + + private ConfigurationContext configContext; + + private WebServiceBinding binding; + + private WorkContext workContext; + + private Map invCtxMap = new HashMap(); + + private String serviceName; + + public Axis2Service(String theName, + ServiceContract serviceContract, + CompositeComponent parent, + WireService wireService, + WebServiceBinding binding, + ServletHost servletHost, + ConfigurationContext configContext, + WorkContext workContext) { + + super(theName, serviceContract.getInterfaceClass(), parent, wireService); + + this.serviceContract = serviceContract; + this.binding = binding; + this.servletHost = servletHost; + this.configContext = configContext; + this.workContext = workContext; + this.serviceName = theName; + } + + public void start() { + super.start(); + + try { + configContext.getAxisConfiguration().addService(createAxisService(binding)); + } catch (AxisFault e) { + throw new Axis2BindingRunTimeException(e); + } + + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + configContext.setContextRoot(getName()); + servletHost.registerMapping("/" + getName(), servlet); + } + + @Destroy + public void stop() { + servletHost.unregisterMapping("/" + getName()); + try { + configContext.getAxisConfiguration().removeService(getName()); + } catch (AxisFault e) { + throw new Axis2BindingRunTimeException(e); + } + super.stop(); + } + + private AxisService createAxisService(WebServiceBinding wsBinding) throws AxisFault { + Definition definition = wsBinding.getWSDLDefinition(); + WebServicePortMetaData wsdlPortInfo = + new WebServicePortMetaData(definition, wsBinding.getWSDLPort(), null, false); + + // TODO investigate if this is 20 wsdl what todo? + WSDLToAxisServiceBuilder builder = + new WSDL11ToAxisServiceBuilder(definition, wsdlPortInfo.getServiceName(), wsdlPortInfo.getPort() + .getName()); + builder.setServerSide(true); + AxisService axisService = builder.populateService(); + + axisService.setName(this.getName()); + axisService.setServiceDescription("Tuscany configured AxisService for service: '" + this.getName() + + "'"); + + // Use the existing WSDL + Parameter wsdlParam = new Parameter(WSDLConstants.WSDL_4_J_DEFINITION, null); + wsdlParam.setValue(definition); + axisService.addParameter(wsdlParam); + Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); + axisService.addParameter(userWSDL); + + PortType wsdlPortType = wsdlPortInfo.getPortType(); + for (Object o : wsdlPortType.getOperations()) { + Operation wsdlOperation = (Operation)o; + String operationName = wsdlOperation.getName(); + QName operationQN = new QName(definition.getTargetNamespace(), operationName); + + org.apache.tuscany.spi.model.Operation op = serviceContract.getOperations().get(operationName); + + MessageReceiver msgrec = null; + boolean opIsNonBlocking = op.isNonBlocking(); + if (serviceContract.getCallbackName() != null) { + msgrec = new Axis2ServiceInOutAsyncMessageReceiver(this, op, workContext); + } else if (opIsNonBlocking) { + msgrec = new Axis2ServiceInMessageReceiver(this, op); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op); + } + + AxisOperation axisOp = axisService.getOperation(operationQN); + if (opIsNonBlocking) { + axisOp.setMessageExchangePattern(WSDL20_2004Constants.MEP_URI_IN_ONLY); + } else { + axisOp.setMessageExchangePattern(WSDL20_2004Constants.MEP_URI_IN_OUT); + } + axisOp.setMessageReceiver(msgrec); + } + + return axisService; + } + + public Object invokeTarget(org.apache.tuscany.spi.model.Operation op, Object[] args) + throws InvocationTargetException { + InvocationChain chain = inboundWire.getInvocationChains().get(op); + Interceptor headInterceptor = chain.getHeadInterceptor(); + if (headInterceptor == null) { + try { + // short-circuit the dispatch and invoke the target directly + if (chain.getTargetInvoker() == null) { + throw new AssertionError("No target invoker [" + chain.getOperation().getName() + "]"); + } + return chain.getTargetInvoker().invokeTarget(args); + } catch (InvocationTargetException e) { + // the cause was thrown by the target so throw it + throw e; + } + } else { + Object messageId = workContext.getCurrentMessageId(); + workContext.setCurrentMessageId(null); + Object correlationId = workContext.getCurrentCorrelationId(); + workContext.setCurrentCorrelationId(null); + + Message msg = new MessageImpl(); + msg.setTargetInvoker(chain.getTargetInvoker()); + msg.setFromAddress(getFromAddress()); + if (messageId == null) { + messageId = new MessageId(); + } + msg.setMessageId(messageId); + msg.setCorrelationId(correlationId); + msg.setBody(args); + Message resp; + // dispatch the wire down the chain and get the response + // TODO http://issues.apache.org/jira/browse/TUSCANY-777 + ClassLoader oldtccl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + resp = headInterceptor.invoke(msg); + } finally { + Thread.currentThread().setContextClassLoader(oldtccl); + } + Object body = resp.getBody(); + if (resp.isFault()) { + throw new InvocationTargetException((Throwable)body); + } + return body; + } + } + + protected Object getFromAddress() { + return this.serviceName; + } + + /** + * Get the Method from an interface matching the WSDL operation name + */ + protected Method getMethod(Class serviceInterface, String operationName) { + // Note: this doesn't support overloaded operations + Method[] methods = serviceInterface.getMethods(); + for (Method m : methods) { + if (m.getName().equals(operationName)) { + return m; + } + // tolerate WSDL with capatalized operation name + StringBuilder sb = new StringBuilder(operationName); + sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); + if (m.getName().equals(sb.toString())) { + return m; + } + } + throw new BuilderConfigException("no operation named " + operationName + + " found on service interface: " + + serviceInterface.getName()); + } + + public TargetInvoker createCallbackTargetInvoker(ServiceContract contract, + org.apache.tuscany.spi.model.Operation operation) { + + return new Axis2ServiceCallbackTargetInvoker(workContext, this); + } + + public void addMapping(MessageId msgId, InvocationContext invCtx) { + this.invCtxMap.put(msgId, invCtx); + } + + public InvocationContext retrieveMapping(MessageId msgId) { + return this.invCtxMap.get(msgId); + } + + public void removeMapping(MessageId msgId) { + this.invCtxMap.remove(msgId); + } + + protected class InvocationContext { + public MessageContext inMessageContext; + + public org.apache.tuscany.spi.model.Operation operation; + + public SOAPFactory soapFactory; + + public CountDownLatch doneSignal; + + public InvocationContext(MessageContext messageCtx, + org.apache.tuscany.spi.model.Operation operation, + SOAPFactory soapFactory, + CountDownLatch doneSignal) { + this.inMessageContext = messageCtx; + this.operation = operation; + this.soapFactory = soapFactory; + this.doneSignal = doneSignal; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java new file mode 100644 index 0000000000..ca7812e01b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java @@ -0,0 +1,114 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.engine.AxisEngine; +import org.apache.axis2.util.Utils; +import org.apache.tuscany.binding.axis2.Axis2Service.InvocationContext; +import org.apache.tuscany.binding.axis2.Axis2AsyncTargetInvoker; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageId; +import org.apache.tuscany.spi.wire.TargetInvoker; + +public class Axis2ServiceCallbackTargetInvoker implements TargetInvoker { + + private Axis2Service service; + + private MessageId currentCorrelationId; + + public Axis2ServiceCallbackTargetInvoker(WorkContext workContext, Axis2Service service) { + this.service = service; + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException { + try { + // Use current correlation id as index to retrieve inv context + InvocationContext invCtx = service.retrieveMapping(this.currentCorrelationId); + + MessageContext outMC = Utils.createOutMessageContext(invCtx.inMessageContext); + outMC.getOperationContext().addMessageContext(outMC); + + OMElement responseOM = null; + if (payload != null && !payload.getClass().isArray()) { + responseOM = (OMElement)payload; + } else { + responseOM = (OMElement)((Object[])payload)[0]; + } + SOAPEnvelope soapEnvelope = invCtx.soapFactory.getDefaultEnvelope(); + soapEnvelope.getBody().addChild(responseOM); + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + AxisEngine engine = + new AxisEngine(invCtx.inMessageContext.getOperationContext().getServiceContext().getConfigurationContext()); + engine.send(outMC); + + invCtx.doneSignal.countDown(); + + service.removeMapping(this.currentCorrelationId); + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } catch(Throwable t) { + throw new Axis2BindingRunTimeException(t); + } + + return Axis2AsyncTargetInvoker.RESPONSE; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + this.currentCorrelationId = (MessageId)msg.getCorrelationId(); + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public Axis2ServiceCallbackTargetInvoker clone() throws CloneNotSupportedException { + try { + return (Axis2ServiceCallbackTargetInvoker)super.clone(); + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } + + public boolean isCacheable() { + return true; + } + + public void setCacheable(boolean cacheable) { + + } + + public boolean isOptimizable() { + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..3b1b0d25e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java @@ -0,0 +1,67 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInMessageReceiver; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + protected Operation operation; + + private Axis2Service axis2Service; + + public Axis2ServiceInMessageReceiver(Axis2Service service, Operation operation) { + this.axis2Service = service; + this.operation = operation; + } + + public Axis2ServiceInMessageReceiver() { + + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + + axis2Service.invokeTarget(operation, args); + + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new InvocationRuntimeException(e); + } catch (Throwable t) { + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new Axis2BindingRunTimeException(t); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java new file mode 100644 index 0000000000..f83862399c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java @@ -0,0 +1,95 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.CountDownLatch; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractMessageReceiver; +import org.apache.tuscany.binding.axis2.Axis2Service.InvocationContext; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.MessageId; + +public class Axis2ServiceInOutAsyncMessageReceiver extends AbstractMessageReceiver { + + private Operation operation; + + private WorkContext workContext; + + private Axis2Service service; + + public Axis2ServiceInOutAsyncMessageReceiver(Axis2Service service, + Operation operation, + WorkContext workContext) { + this.operation = operation; + this.workContext = workContext; + this.service = service; + } + + public Axis2ServiceInOutAsyncMessageReceiver() { + } + + public final void receive(final MessageContext messageCtx) { + try { + // Create a new message id and hand it to + // JDKInboundInvocationHandler + // via work context + MessageId messageId = new MessageId(); + workContext.setCurrentMessageId(messageId); + // Now use message id as index to context to be used by callback + // target invoker + CountDownLatch doneSignal = new CountDownLatch(1); + InvocationContext invCtx = + service.new InvocationContext(messageCtx, operation, getSOAPFactory(messageCtx), doneSignal); + service.addMapping(messageId, invCtx); + + invokeBusinessLogic(messageCtx); + + try { + doneSignal.await(); + } catch(InterruptedException e) { + e.printStackTrace(); + } + } catch (AxisFault e) { + // log.error(e); + } + } + + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + service.invokeTarget(operation, args); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new InvocationRuntimeException(e); + } catch (Exception e) { + throw AxisFault.makeFault(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..4522632d9f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java @@ -0,0 +1,73 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + + protected Operation operation; + + private Axis2Service axis2Service; + + public Axis2ServiceInOutSyncMessageReceiver(Axis2Service service, Operation operation) { + this.axis2Service = service; + this.operation = operation; + } + + public Axis2ServiceInOutSyncMessageReceiver() { + + } + + @Override + public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + + OMElement responseOM = (OMElement)axis2Service.invokeTarget(operation, args); + + SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); + soapEnvelope.getBody().addChild(responseOM); + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + } catch (InvocationTargetException e) { + e.printStackTrace(); + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new InvocationRuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + throw AxisFault.makeFault(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java new file mode 100644 index 0000000000..cab5b28ee7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java @@ -0,0 +1,207 @@ +/* + * 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.tuscany.binding.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.transport.http.AxisServlet; + +/** + * This overrides the servlet init of the AxisServlet so Tuscany can use + * a single Axis2 ConfigurationContext instance shared between AxisServlet + * instances for each SCA service with a ws binding. + * TODO: need to review if thats really what we want to be doing + */ +public class Axis2ServiceServlet extends AxisServlet { + + private static final long serialVersionUID = 1L; + + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + + private boolean inited; + + public void init(ConfigurationContext configContext) { + this.configContext = configContext; + try { + super.init(DUMMY_CONFIG); + } catch (ServletException e) { + throw new RuntimeException(e); + } + } + + /** + * We've setup the Servlet by passing in a ConfigurationContext on our init method + * override this method to just return that + */ + @Override + protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { + return this.configContext; + } + + /** + * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. + */ + private static ServletConfig createDummyServletConfig() { + ServletConfig sc = new ServletConfig() { + + public String getServletName() { + return "TuscanyAxis2DummyServlet"; + } + + public ServletContext getServletContext() { + return new ServletContext() { + + public ServletContext getContext(String uripath) { + return null; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public String getMimeType(String file) { + return null; + } + + public Set getResourcePaths(String path) { + return Collections.emptySet(); + } + + public URL getResource(String path) throws MalformedURLException { + if("/".equals(path)) { + // HACK: To avoid NPE + return new URL("/axis2"); + } + return null; + } + + public InputStream getResourceAsStream(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String arg0) { + return null; + } + + public Servlet getServlet(String arg0) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String arg0) { + } + + public void log(Exception arg0, String arg1) { + } + + public void log(String arg0, Throwable arg1) { + } + + public String getRealPath(String arg0) { + return null; + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + public Object getAttribute(String arg0) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String arg0, Object arg1) { + } + + public void removeAttribute(String arg0) { + } + + public String getServletContextName() { + return null; + } + }; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return new Vector().elements(); + } + }; + return sc; + } + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // HACK: Get the correct context root which is not available during init() call + if (!inited) { + synchronized (configContext) { + configContext.setContextRoot(request.getContextPath()); + inited = true; + } + } + super.service(request, response); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java new file mode 100755 index 0000000000..175f995c76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java @@ -0,0 +1,136 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPBody; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; + +/** + * Axis2TargetInvoker uses an Axis2 OperationClient to invoke a remote web service + */ +public class Axis2TargetInvoker implements TargetInvoker { + + private QName wsdlOperationName; + + private Options options; + + private SOAPFactory soapFactory; + + private ServiceClient serviceClient; + + public Axis2TargetInvoker(ServiceClient serviceClient, QName wsdlOperationName, Options options, + SOAPFactory soapFactory) { + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + this.serviceClient = serviceClient; + } + + /** + * Invoke a WS operation + * + * @param payload + * @return + * @throws InvocationTargetException + */ + public Object invokeTarget(final Object payload) throws InvocationTargetException { + try { + Object[] args = (Object[]) payload; + OperationClient operationClient = createOperationClient(args); + + operationClient.execute(true); + + MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + return responseMC.getEnvelope().getBody().getFirstElement(); + + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } + + } + + protected OperationClient createOperationClient(Object[] args) throws AxisFault { + SOAPEnvelope env = soapFactory.getDefaultEnvelope(); + if (args != null && args.length > 0) { + SOAPBody body = env.getBody(); + for (Object bc : args) { + if (bc instanceof OMElement) { + body.addChild((OMElement) bc); + } else { + throw new IllegalArgumentException( + "Can't handle mixed payloads betweem OMElements and other types."); + } + } + } + MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + // Axis2 operationClients can not be shared so create a new one for each request + OperationClient operationClient = serviceClient.createClient(wsdlOperationName); + operationClient.setOptions(options); + operationClient.addMessageContext(requestMC); + return operationClient; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public Axis2TargetInvoker clone() throws CloneNotSupportedException { + try { + return (Axis2TargetInvoker) super.clone(); + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } + + public boolean isCacheable() { + return true; + } + + public void setCacheable(boolean cacheable) { + + } + + public boolean isOptimizable() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java new file mode 100755 index 0000000000..6d4ec6eaf9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java @@ -0,0 +1,78 @@ +/* + * 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.tuscany.binding.axis2; + + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a Celtix binding configuration in an assembly + * + * @version $Rev$ $Date$ + */ +public class WebServiceBinding extends Binding { + + private Definition definition; + private Port port; + private Service service; + //private String portURI; + private String uri; + public WebServiceBinding(Definition definition, Port port, String uri, String portURI, Service service) { + this.definition = definition; + this.port = port; + this.uri = uri; + //this.portURI = portURI; + this.service = service; + } + + public Port getWSDLPort() { + return port; + } + + public Service getWSDLService() { + return service; + } + + public void setWSDLPort(Port value) { + port = value; + } + + public Definition getWSDLDefinition() { + return definition; + } + + public void setWSDLDefinition(Definition def) { + definition = def; + } + + // public void setPortURI(String uri) { + // portURI = uri; + // } + + public String getURI() { + return uri; + } + + public void setURI(String theUri) { + this.uri = theUri; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java new file mode 100755 index 0000000000..5535dbb5c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java @@ -0,0 +1,143 @@ +/* + * 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.tuscany.binding.axis2; + +import static org.osoa.sca.Version.XML_NAMESPACE_1_0; + +import java.io.IOException; +import java.util.Collection; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Scope; + +/** + * Parses a WebServiceBinding entry in an assembly XML file + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +@SuppressWarnings("deprecation") +public class WebServiceBindingLoader extends LoaderExtension { + public static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws"); + + private WSDLDefinitionRegistry wsdlDefinitionRegistry; + + @Constructor( { "loaderRegistry", "wsdlDefinitionRegistry" }) + public WebServiceBindingLoader(@Autowire LoaderRegistry loaderRegistry, + @Autowire WSDLDefinitionRegistry wsdlDefinitionRegistry) { + super(loaderRegistry); + this.wsdlDefinitionRegistry = wsdlDefinitionRegistry; + } + + public QName getXMLType() { + return BINDING_WS; + } + + public WebServiceBinding load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext) + throws XMLStreamException, LoaderException { + // not sure what uri was here ? String uri = reader.getAttributeValue(null, "uri"); + String uri = null; + String endpoint = reader.getAttributeValue(null, "endpoint"); + String wsdlLocation = reader.getAttributeValue(null, "location"); + LoaderUtil.skipToEndElement(reader); + try { + return createBinding(uri, endpoint, wsdlLocation, deploymentContext); + } catch (Exception e) { + throw new LoaderException(e); + } + + } + + @SuppressWarnings("unchecked") + private WebServiceBinding createBinding(String uri, String endpoint, String wsdlLocation, DeploymentContext deploymentContext) + throws WSDLException, IOException, LoaderException { + // Get the WSDL port namespace and name + if (uri == null && endpoint != null) { + int h = endpoint.indexOf('#'); + String serviceName; + String portName; + + String namespace = endpoint.substring(0, h); + String fragment = endpoint.substring(h + 1); + if (fragment.startsWith("wsdl.endpoint(") && fragment.endsWith(")")) { + fragment = fragment.substring(14, fragment.length() - 1); + int slash = fragment.indexOf('/'); + if (slash != -1) { + serviceName = fragment.substring(0, slash); + portName = fragment.substring(slash + 1); + } else { + serviceName = null; + portName = fragment; + } + } else { + serviceName = null; + portName = fragment; + } + // FIXME need to find out how to get wsdl and what context to use --- terrible hack attack! + if (null == wsdlLocation) { + throw new Axis2BindingRunTimeException( + "Failed to determine wsdl location on binding. Try specifying 'location' attribute on binding."); + } + Definition definition = + wsdlDefinitionRegistry.loadDefinition(namespace+" "+wsdlLocation, deploymentContext.getClassLoader()); + + Port thePort = null; + Service service = null; + // Find the port with the given name + for (Service serv : (Collection) definition.getServices().values()) { + QName sqn = serv.getQName(); + if (serviceName != null && !serviceName.equals(sqn.getLocalPart())) { + continue; + } + + Port p = serv.getPort(portName); + if (p != null) { + service = serv; + thePort = p; + break; + } + } + if (thePort == null) { + throw new IllegalArgumentException("Cannot find WSDL port " + endpoint); + + } + return new WebServiceBinding(definition, thePort, uri, endpoint, service); + } + // FIXME: Find the first port? + throw new LoaderException("Web Service endpoint cannot be resolved: " + endpoint); + + } + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java new file mode 100755 index 0000000000..c0ef46fee3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.binding.axis2.util; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +import org.apache.axis2.engine.AxisConfigurator; + +/** + * Helps configure Axis2 from a resource in binding.axis2 instead of Axis2.xml + *

TODO: Review: should there be a single global Axis + * ConfigurationContext + */ +public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { + + public TuscanyAxisConfigurator() throws AxisFault { + super(TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/binding/axis2/engine/config/axis2.xml"), null); + } + + public ConfigurationContext getConfigurationContext() throws AxisFault { + if (configContext == null) + configContext = ConfigurationContextFactory.createConfigurationContext(this); + return configContext; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java new file mode 100755 index 0000000000..2a453bdf15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java @@ -0,0 +1,491 @@ +/* + * 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.tuscany.binding.axis2.util; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.BindingOutput; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPHeader; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +/** + * Metadata for a WSDL operation + */ +@SuppressWarnings({"all"}) +public class WebServiceOperationMetaData implements Serializable { + private static final long serialVersionUID = 2425306250256227724L; + + // WSDL Binding and BindingOperation + private Binding binding; + private BindingOperation bindingOperation; + // Fields to cache derived metadata + private transient Set inputHeaderParts; + private transient Set outputHeaderParts; + private transient String style; + private transient String use; + private transient String soapAction; + private transient List signature; + private String encoding; + private transient QName rpcOperationName; + + public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation) { + this.binding = binding; + this.bindingOperation = bindingOperation; + } + + public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation, String style, String use, + String encoding, + String soapAction) { + this.binding = binding; + this.bindingOperation = bindingOperation; + this.style = style; + this.use = use; + this.encoding = encoding; + this.soapAction = soapAction; + } + + public Set getInputHeaderParts() { + if (inputHeaderParts == null) { + // Build a set of header parts that we need to exclude + inputHeaderParts = new HashSet(); + BindingInput bindingInput = bindingOperation.getBindingInput(); + + if (bindingInput != null) { + Operation operation = bindingOperation.getOperation(); + javax.wsdl.Message message = operation.getInput().getMessage(); + List elements = bindingInput.getExtensibilityElements(); + for (Iterator i = elements.iterator(); i.hasNext();) { + Object extensibilityElement = i.next(); + Part part = getPartFromSOAPHeader(message, extensibilityElement); + if (part != null) { + inputHeaderParts.add(part); + } + } + } + } + return inputHeaderParts; + } + + public Set getOutputHeaderParts() { + if (outputHeaderParts == null) { + // Build a set of header parts that we need to exclude + outputHeaderParts = new HashSet(); + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + + if (bindingOutput != null) { + Operation operation = bindingOperation.getOperation(); + javax.wsdl.Message message = operation.getOutput().getMessage(); + List elements = bindingOutput.getExtensibilityElements(); + for (Iterator i = elements.iterator(); i.hasNext();) { + Object extensibilityElement = i.next(); + Part part = getPartFromSOAPHeader(message, extensibilityElement); + if (part != null) { + outputHeaderParts.add(part); + } + } + } + } + return outputHeaderParts; + } + + private Part getPartFromSOAPHeader(Message message, Object extensibilityElement) { + Part part = null; + if (extensibilityElement instanceof SOAPHeader) { + SOAPHeader soapHeader = (SOAPHeader) extensibilityElement; + QName msgName = soapHeader.getMessage(); + if (message.getQName().equals(msgName)) { + part = message.getPart(soapHeader.getPart()); + } + } else if (extensibilityElement instanceof SOAPHeader) { + SOAPHeader soapHeader = (SOAPHeader) extensibilityElement; + QName msgName = soapHeader.getMessage(); + if (message.getQName().equals(msgName)) { + part = message.getPart(soapHeader.getPart()); + } + } + return part; + } + + public String getStyle() { + if (style == null) { + SOAPOperation soapOperation = (SOAPOperation) WebServicePortMetaData + .getExtensibilityElement(bindingOperation.getExtensibilityElements(), + SOAPOperation.class); + if (soapOperation != null) { + style = soapOperation.getStyle(); + } + if (style == null) { + SOAPBinding soapBinding = WebServicePortMetaData + .getExtensibilityElement(binding.getExtensibilityElements(), SOAPBinding.class); + if (soapBinding != null) { + style = soapBinding.getStyle(); + } + } + if (style == null) { + style = "document"; + } + } + return style; + } + + /** + * Returns the SOAP action for the given operation. + */ + public String getSOAPAction() { + if (soapAction == null) { + final List wsdlBindingOperationExtensions = bindingOperation.getExtensibilityElements(); + final SOAPOperation soapOp = + WebServicePortMetaData.getExtensibilityElement(wsdlBindingOperationExtensions, SOAPOperation.class); + if (soapOp != null) { + soapAction = soapOp.getSoapActionURI(); + } + } + return soapAction; + } + + public QName getRPCOperationName() { + if (rpcOperationName == null) { + javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); + String ns = + (soapBody != null) ? soapBody.getNamespaceURI() : binding.getPortType().getQName().getNamespaceURI(); + String name = bindingOperation.getOperation().getName(); + rpcOperationName = new QName(ns, name); + } + return rpcOperationName; + } + + private List getSOAPBodyParts(boolean input) { + javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(input); + if (soapBody != null) { + List parts = soapBody.getParts(); + if (parts != null) { + List names = new ArrayList(); + for (Iterator i = parts.iterator(); i.hasNext();) { + Object part = i.next(); + if (part instanceof String) { + names.add((String) part); + } else if (part instanceof Part) { + names.add(((Part) part).getName()); + } + } + return names; + } else { + return null; + } + } else { + return null; + } + } + + private javax.wsdl.extensions.soap.SOAPBody getSOAPBody(boolean input) { + List elements = null; + if (input) { + BindingInput bindingInput = bindingOperation.getBindingInput(); + if (bindingInput == null) { + return null; + } + elements = bindingInput.getExtensibilityElements(); + } else { + BindingOutput bindingOutput = bindingOperation.getBindingOutput(); + if (bindingOutput == null) { + return null; + } + elements = bindingOutput.getExtensibilityElements(); + } + javax.wsdl.extensions.soap.SOAPBody soapBody = WebServicePortMetaData.getExtensibilityElement(elements, + javax.wsdl.extensions.soap.SOAPBody.class); + return soapBody; + } + + /** + * Returns the use attribute + */ + public String getUse() { + if (use == null) { + javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); + if (soapBody != null) { + use = soapBody.getUse(); + } + if (use == null) { + use = "literal"; + } + } + return use; + } + + @SuppressWarnings("unchecked") + public String getEncoding() { + if (encoding == null) { + javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true); + if (soapBody != null) { + List styles = (List) soapBody.getEncodingStyles(); + if (styles != null && !styles.isEmpty()) { + encoding = styles.get(0); + } + } + if (encoding == null) { + encoding = ""; + } + } + return encoding; + } + + public boolean isDocLitWrapped() { + boolean flag = getStyle().equals("document") && getUse().equals("literal"); + if (!flag) { + return false; + } + Message msg = getMessage(true); + if (msg == null) { + return false; + } + List parts = msg.getOrderedParts(null); + if (parts.size() != 1) { + return false; + } + Part part = (Part) parts.get(0); + QName element = part.getElementName(); + if (element == null) { + return false; + } + return element.getLocalPart().equals(bindingOperation.getOperation().getName()); + } + + /* + * public SOAPMediator createMediator(boolean serverMode) throws SOAPException { + * // create a new mediator for each invoke for thread-safety + * boolean rpcStyle = getStyle().equals("rpc"); boolean rpcEncoded = isEncoded(); + * + * SOAPMediator mediator = null; + * + * if (!rpcStyle) { // Document mediator = new SOAPDocumentLiteralMediatorImpl(this, serverMode); + * } else { if (!rpcEncoded) mediator = new + * SOAPRPCLiteralMediatorImpl(this, serverMode); // RPC-literal else mediator = + * new SOAPRPCEncodedMediatorImpl(this, serverMode); // RPC-encoded } + * return mediator; } + */ + + /** + * Get the operation signature from the WSDL operation + */ + public List getOperationSignature() { + if (signature == null) { + signature = new ArrayList(); + + Operation operation = bindingOperation.getOperation(); + if (operation == null) { + return signature; + } + + final Input input = operation.getInput(); + if (input == null) { + return signature; + } + + String sstyle = getStyle(); + + if ("rpc".equals(sstyle)) { + Collection partNames = input.getMessage().getParts().values(); + for (Iterator i = partNames.iterator(); i.hasNext();) { + Part part = (Part) i.next(); + signature.add(part.getName()); + } + } else { + /* + * WS-I Basic Profile 1.1 4.7.6 Operation Signatures Definition: operation signature + * + * The profile defines the "operation signature" to be the fully qualified name of the child element of + * SOAP body of the SOAP input + * message described by an operation in a WSDL binding. + * + * In the case of rpc-literal binding, the operation name is used as a wrapper for the part accessors. + * In the document-literal case, designed so that they meet this requirement. + * + * An endpoint that supports multiple operations must unambiguously identify the operation being + * invoked based on the input message + * that it receives. This is only possible if all the operations specified in the wsdl:binding + * associated with an endpoint have a + * unique operation signature. + * + * R2710 The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are + * different from one another. + */ + List bodyParts = getSOAPBodyParts(true); + + Collection parts = input.getMessage().getParts().values(); + // Exclude the parts to be transmitted in SOAP header + if (bodyParts == null) { + parts.removeAll(getInputHeaderParts()); + } + for (Iterator i = parts.iterator(); i.hasNext();) { + Part part = (Part) i.next(); + if (bodyParts == null) { + // All parts + QName elementName = part.getElementName(); + if (elementName == null) { + elementName = new QName("", part.getName()); + // TODO: [rfeng] throw new + // ServiceRuntimeException("Message part for + // document style must refer to an XSD element + // using a QName: " + part); + } + signature.add(elementName); + } else { + // "parts" in soap:body + if (bodyParts.contains(part.getName())) { + QName elementName = part.getElementName(); + if (elementName == null) { + elementName = new QName("", part.getName()); + // TODO: [rfeng] throw new + // ServiceRuntimeException("Message part for + // document style must refer to an XSD + // element using a QName: " + part); + } + signature.add(elementName); + } + + } + } + } + } + return signature; + } + + public Message getMessage(boolean isInput) { + Operation operation = bindingOperation.getOperation(); + if (operation == null) { + return null; + } + + if (isInput) { + final Input input = operation.getInput(); + return input == null ? null : input.getMessage(); + } else { + final Output output = operation.getOutput(); + return output == null ? null : output.getMessage(); + } + } + + public Part getInputPart(int index) { + Part part = null; + Message message = getMessage(true); + if (message == null) { + return part; + } + + List parts = message.getOrderedParts(null); + return (Part) parts.get(index); + + } + + public Part getOutputPart(int index) { + Part part = null; + Message message = getMessage(false); + if (message == null) { + return part; + } + + List parts = message.getOrderedParts(null); + return (Part) parts.get(index); + + } + + /** + * Get a list of indexes for each part in the SOAP body + * + * @param isInput + */ + public List getBodyPartIndexes(boolean isInput) { + List indexes = new ArrayList(); + + Message message = getMessage(isInput); + if (message == null) { + return indexes; + } + + List bodyParts = getSOAPBodyParts(isInput); + List parts = message.getOrderedParts(null); + Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts(); + + int index = 0; + for (Iterator i = parts.iterator(); i.hasNext(); index++) { + Part part = (Part) i.next(); + if (headerParts.contains(part)) { + continue; + } + if (bodyParts == null) { + // All parts + indexes.add(index); + } else { + // "parts" in soap:body + if (bodyParts.contains(part.getName())) { + indexes.add(index); + } + } + } + return indexes; + } + + /** + * Get the corresponding index for a part in the SOAP header by element name + * + * @param elementName + * @param isInput + */ + public int getHeaderPartIndex(QName elementName, boolean isInput) { + + Message message = getMessage(isInput); + if (message == null) { + return -1; + } + + List parts = message.getOrderedParts(null); + Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts(); + + int index = 0; + for (Iterator i = parts.iterator(); i.hasNext(); index++) { + Part part = (Part) i.next(); + // Test if the part is in header section + if (headerParts.contains(part) && elementName.equals(part.getElementName())) { + return index; + } + } + return -1; + } + + public BindingOperation getBindingOperation() { + return bindingOperation; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java new file mode 100755 index 0000000000..a8d4f0f581 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java @@ -0,0 +1,377 @@ +/* + * 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.tuscany.binding.axis2.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.xml.namespace.QName; + +import org.apache.tuscany.idl.wsdl.WSDLServiceContract; + +/** + * Metadata for a WSDL port + * + */ +public class WebServicePortMetaData { + + private Service wsdlService; + private QName wsdlServiceName; + private Port wsdlPort; + private Binding wsdlBinding; + private QName wsdlPortName; + private PortType wsdlPortType; + private QName wsdlPortTypeName; + private String endpoint; + private boolean managed; + private List allOperationMetaData; + private WSDLServiceContract interfaceType; + + /** + * Constructor + * + * @param wsdlDefinition + */ + public WebServicePortMetaData(Definition wsdlDefinition, Port wsdlPort, String endpoint, boolean managed) { + + // Lookup the named port + this.wsdlPort = wsdlPort; + wsdlPortName = new QName(wsdlDefinition.getTargetNamespace(), wsdlPort.getName()); + Collection services = wsdlDefinition.getServices().values(); + for (Object serviceObj : services) { + Service service = (Service) serviceObj; + if (service.getPorts().containsValue(wsdlPort)) { + wsdlService = service; + wsdlServiceName = service.getQName(); + break; + } + } + + // Save the binding + wsdlBinding = wsdlPort.getBinding(); + if (wsdlBinding == null) { + throw new IllegalArgumentException("WSDL binding cannot be found for " + wsdlPortName); + } + + // Save the portType + wsdlPortType = wsdlBinding.getPortType(); + if (wsdlPortType == null) { + throw new IllegalArgumentException("WSDL portType cannot be found for " + wsdlPortName); + } + wsdlPortTypeName = wsdlPortType.getQName(); + + // Save the endpoint + this.endpoint = endpoint; + + // Track if this endpoint is managed or not + this.managed = managed; + } + + /** + * Constructor + * + * @param serviceName + * @param portName + * @param portTypeName + * @param endpoint + */ + public WebServicePortMetaData(QName serviceName, String portName, QName portTypeName, String endpoint) { + wsdlServiceName = serviceName; + wsdlPortName = new QName(serviceName.getNamespaceURI(), portName); + wsdlPortTypeName = portTypeName; + this.endpoint = endpoint; + } + + /** + * @return Returns the wsdlPort. + */ + public javax.wsdl.Port getPort() { + return wsdlPort; + } + + /** + * @return Returns the wsdlService. + */ + public QName getServiceName() { + return wsdlServiceName; + } + + /** + * @return Returns the wsdlService. + */ + public javax.wsdl.Service getService() { + return wsdlService; + } + + /** + * @return Returns the wsdlPortType. + */ + public PortType getPortType() { + return wsdlPortType; + } + + /** + * @return Returns the wsdlPortType. + */ + public QName getPortTypeName() { + return wsdlPortTypeName; + } + + /** + * @return Returns the wsdlBinding. + */ + public Binding getBinding() { + return wsdlBinding; + } + + /** + * @return Returns the wsdlPortName. + */ + public QName getPortName() { + return wsdlPortName; + } + + /** + * Returns the endpoint of a given port. + */ + public String getEndpoint() { + + // Return the specified endpoint + if (endpoint != null) { + return endpoint; + } + + // Find the target endpoint on the port + if (wsdlPort != null) { + final List wsdlPortExtensions = wsdlPort.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + } + + return null; + } + + /** + * Returns the SOAP binding style. + */ + public String getStyle() { + + // Find the binding style + String style = null; + if (wsdlBinding != null) { + final List wsdlBindingExtensions = wsdlBinding.getExtensibilityElements(); + SOAPBinding soapBinding = getExtensibilityElement(wsdlBindingExtensions, SOAPBinding.class); + if (soapBinding != null) { + style = soapBinding.getStyle(); + } + } + + // Default to document + return (style == null) ? "document" : style; + } + + /** + * Returns the use attribute + */ + public String getUse() { + List list = getAllOperationMetaData(); + return list.get(0).getUse(); + } + + /** + * Returns the encoding attribute + */ + public String getEncoding() { + List list = getAllOperationMetaData(); + return list.get(0).getEncoding(); + } + + /** + * @return Returns true if this is a managed web service. + */ + public boolean isManaged() { + return managed; + } + + /** + * Returns the first extensibility element of the given type. + * + * @param elements + * @param type + */ + public static T getExtensibilityElement(List elements, Class type) { + for (Object element : elements) { + if (type.isInstance(element)) { + return type.cast(element); + } + } + return null; + } + + /** + * Returns the extensibility elements of the given type. + * + * @param elements + * @param type + * @return List + */ + public static List getExtensibilityElements(List elements, Class type) { + List result = new ArrayList(); + for (Object element : elements) { + if (type.isInstance(element)) { + result.add(type.cast(element)); + } + } + return result; + } + + /** + * Get the operation signature from the SOAP Body + * + * @return A list of QNames + */ + // public static List getOperationSignature(javax.xml.soap.SOAPBody body) { + // List signature = new ArrayList(); + // for (Iterator i = body.getChildElements(); i.hasNext();) { + // Object child = i.next(); + // if (child instanceof SOAPBodyElement) { + // Name name = ((SOAPBodyElement) child).getElementName(); + // QName qname = new QName(name.getURI(), name.getLocalName(), name.getPrefix()); + // signature.add(qname); + // } + // } + // return signature; + // } + // public static List getRPCOperationSignature(javax.xml.soap.SOAPBody body) { + // List signature = new ArrayList(); + // for (Iterator i = body.getChildElements(); i.hasNext();) { + // Object child = i.next(); + // if (child instanceof SOAPBodyElement) { + // SOAPBodyElement op = ((SOAPBodyElement) child); + // for (Iterator j = op.getChildElements(); j.hasNext();) { + // Object part = i.next(); + // if (part instanceof SOAPElement) { + // SOAPElement p = (SOAPElement) part; + // signature.add(p.getLocalName()); + // } + // } + // } + // } + // return signature; + // } + // public WebServiceOperationMetaData getOperationMetaData(javax.xml.soap.SOAPBody body) { + // List s1 = getOperationSignature(body); + // // List rpcParts = getRPCOperationSignature(body); + // for (Iterator it = getAllOperationMetaData().iterator(); it.hasNext();) { + // WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) it.next(); + // + // String style = descriptor.getStyle(); + // + // if (style.equals("document")) { + // List s2 = descriptor.getOperationSignature(); + // if (s1.equals(s2)) + // return descriptor; + // } else { + // QName op1 = (QName) s1.get(0); + // QName op2 = descriptor.getRPCOperationName(); + // if (op1.equals(op2)) { + // /* + // * // FIXME: [rfeng] We don't support method overloading + // * List partNames = getOperationSignature(binding, + // * bindingOperation); if (rpcParts.equals(partNames)) + // */ + // return descriptor; + // } + // } + // } + // return null; + // } + public List getAllOperationMetaData() { + if (allOperationMetaData == null) { + allOperationMetaData = new ArrayList(); + for (Iterator it = wsdlBinding.getBindingOperations().iterator(); it.hasNext();) { + final BindingOperation bindingOperation = (BindingOperation) it.next(); + if (bindingOperation.getOperation() != null) { + allOperationMetaData.add(new WebServiceOperationMetaData(wsdlBinding, bindingOperation)); + } + } + } + return allOperationMetaData; + } + + public WebServiceOperationMetaData getOperationMetaData(String operationName) { + StringBuilder sb = new StringBuilder(operationName); + sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); + String capatalizedOpName = sb.toString(); + + for (WebServiceOperationMetaData webServiceOperationMetaData : getAllOperationMetaData()) { + WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) webServiceOperationMetaData; + String opName = descriptor.getBindingOperation().getOperation().getName(); + + if (opName.equals(operationName) || opName.equals(capatalizedOpName)) { + return descriptor; + } + } + return null; + } + + /** + * Returns the WSDL service contract + * + * @return WSDLServiceContract + */ + public WSDLServiceContract getInterfaceType() { + return interfaceType; + } + + /** + * Get the WSDL operation name for a Java method name + */ + public String getWSDLOperationName(String methodName) { + StringBuilder sb = new StringBuilder(methodName); + sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); + String capatalizedOpName = sb.toString(); + for (Object o : wsdlPortType.getOperations()) { + Operation operation = (Operation) o; + String wsdlOpName = operation.getName(); + if (wsdlOpName.equals(methodName)) { + return wsdlOpName; + } + if (wsdlOpName.equals(capatalizedOpName)) { + return wsdlOpName; + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/binding.axis2.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/binding.axis2.scdl new file mode 100644 index 0000000000..0eb56942f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/binding.axis2.scdl @@ -0,0 +1,48 @@ + + + + + + + org.apache.tuscany.sca.services.bindings + axis2 + 1.0-incubator-M2-SNAPSHOT + + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + 1.0-incubator-M2-SNAPSHOT + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..d14e850caf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,49 @@ + + + + + + + org.apache.tuscany.sca.services.bindings + axis2 + 1.0-incubator-M2-SNAPSHOT + + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + 1.0-incubator-M2-SNAPSHOT + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/org/apache/tuscany/binding/axis2/engine/config/axis2.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/org/apache/tuscany/binding/axis2/engine/config/axis2.xml new file mode 100755 index 0000000000..84c86d6dfb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/resources/org/apache/tuscany/binding/axis2/engine/config/axis2.xml @@ -0,0 +1,302 @@ + + + + + + + false + false + false + false + + + + + + 30 + + + + true + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + false + + + + + + + false + + + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + HTTP/1.1 + chunked + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java new file mode 100755 index 0000000000..9605c50c51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.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 org.apache.tuscany.binding.axis2; + +import java.lang.reflect.Type; +import java.net.URL; +import java.util.HashMap; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.idl.wsdl.WSDLServiceContract; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; +import org.easymock.EasyMock; +import org.xml.sax.InputSource; + +public class Axis2ReferenceTestCase extends TestCase { + + public void testInvokeService() throws Exception { + Axis2Reference axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); + Operation operation = new Operation("sayHi", null, null, null, false, null); + TargetInvoker targetInvoker = axis2Reference.createTargetInvoker(null, operation); + assertNotNull(targetInvoker); + } + + public void testAsyncTargetInvoker() throws Exception { + Axis2Reference axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); + //Create a mocked InboundWire, make the call of ServiceExtension.getInterface() returns a Class + InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class); + JavaServiceContract contract = new JavaServiceContract(Greeter.class); + contract.setCallbackClass(GreetingCallback.class); + Operation callbackOp = new Operation("sayHiCallback", null, null, null, true, null); + HashMap> callbackOps = new HashMap>(); + callbackOps.put("sayHiCallback", callbackOp); + contract.setCallbackOperations(callbackOps); + EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes(); + EasyMock.replay(inboundWire); + + axis2Reference.setInboundWire(inboundWire); + Operation operation = new Operation("sayHi", null, null, null, true, null); + TargetInvoker asyncTargetInvoker = axis2Reference.createAsyncTargetInvoker(null, operation); + assertNotNull(asyncTargetInvoker); + } + + private Axis2Reference createAxis2Reference(String webAppName, String serviceName) throws Exception { + //Create WebServiceBinding + String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; + URL url = getClass().getResource(wsdlLocation); + assertNotNull("Could not find wsdl " + url.toString(), url); + + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + InputSource input = new InputSource(url.openStream()); + Definition wsdlDef = reader.readWSDL(url.toString(), input); + Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", + "SOAPService")); + Port port = wsdlService.getPort("SoapPort"); + WebServiceBinding wsBinding = new WebServiceBinding(wsdlDef, port, "uri", "portURI", wsdlService); + //Create a mocked WireService, make the call of ServiceExtension.getServiceInstance() returns a proxy instance. + WireService wireService = EasyMock.createNiceMock(WireService.class); + EasyMock.replay(wireService); + CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); + // TODO figure out what to do with the service contract + ServiceContract contract = new WSDLServiceContract(); + contract.setInterfaceClass(Greeter.class); + WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); + EasyMock.replay(workContext); + return new Axis2Reference(serviceName, + parent, + wireService, + wsBinding, + contract, + workContext); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ServiceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ServiceTestCase.java new file mode 100755 index 0000000000..6669226547 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ServiceTestCase.java @@ -0,0 +1,150 @@ +/* + * 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.tuscany.binding.axis2; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import javax.servlet.Servlet; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.xml.sax.InputSource; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.tuscany.binding.axis2.util.TuscanyAxisConfigurator; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.OutboundInvocationChain; +import org.apache.tuscany.spi.wire.OutboundWire; +import org.apache.tuscany.spi.wire.WireService; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +public class Axis2ServiceTestCase extends TestCase { + + public void testInvokeService() throws Exception { + TestServletHost tomcatHost = new TestServletHost(); + Axis2Service axis2Service = createAxis2Service("testServiceName", tomcatHost, false); + axis2Service.start(); + + if (true) return; + Servlet servlet = tomcatHost.getMapping("testWebAppName/services/testServiceName"); + assertNotNull(servlet); + + //Create mocked HttpRequest and HttpResponse object to test the Axis2Servlet + //To be done: + + } + + public void testAsyncMessageReceiver() throws Exception { + + TestServletHost tomcatHost = new TestServletHost(); + Axis2Service axis2Service = createAxis2Service("testServiceName", tomcatHost, true); + axis2Service.start(); + } + + private Axis2Service createAxis2Service(String serviceName, ServletHost tomcatHost, boolean callback) + throws Exception { + //Create WebServiceBinding + String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; + URL url = getClass().getResource(wsdlLocation); + assertNotNull("Could not find wsdl " + url.toString(), url); + + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + InputSource input = new InputSource(url.openStream()); + Definition wsdlDef = reader.readWSDL(url.toString(), input); + Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", + "SOAPService")); + Port port = wsdlService.getPort("SoapPort"); + WebServiceBinding wsBinding = new WebServiceBinding(wsdlDef, port, "uri", "portURI", wsdlService); + + //Create a mocked WireService, make the call of ServiceExtension.getServiceInstance() returns a proxy instance. + WireService wireService = EasyMock.createNiceMock(WireService.class); + wireService.createProxy(EasyMock.isA(InboundWire.class)); + EasyMock.expectLastCall().andReturn(null); + EasyMock.replay(wireService); + + //Create a mocked InboundWire, make the call of ServiceExtension.getInterface() returns a Class + InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class); + JavaServiceContract contract = new JavaServiceContract(Greeter.class); + Map> opMap = new HashMap>(); + for(Method m: Greeter.class.getMethods()) { + opMap.put(m.getName(), new Operation(m.getName(), null, null, null)); + } + contract.setOperations(opMap); + EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes(); + if (callback) { + contract.setCallbackName(""); + } + EasyMock.replay(inboundWire); + + OutboundWire outboundWire = EasyMock.createNiceMock(OutboundWire.class); + Map, OutboundInvocationChain> map = new HashMap, OutboundInvocationChain>(); + EasyMock.expect(outboundWire.getInvocationChains()).andReturn(map).once(); + EasyMock.replay(outboundWire); + + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext(); + WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); + EasyMock.replay(workContext); + Axis2Service axis2Service = + new Axis2Service(serviceName, + contract, + null, + wireService, + wsBinding, + tomcatHost, + configurationContext, + workContext); + axis2Service.setInboundWire(inboundWire); + axis2Service.setOutboundWire(outboundWire); + + return axis2Service; + } + + protected class TestServletHost implements ServletHost { + private Map mappings = new HashMap(); + + public void registerMapping(String mapping, Servlet servlet) { + mappings.put(mapping, servlet); + } + + public void unregisterMapping(String mapping) { + } + + public Servlet getMapping(String mapping) { + return mappings.get(mapping); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Greeter.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Greeter.java new file mode 100755 index 0000000000..39fccdadd3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Greeter.java @@ -0,0 +1,31 @@ +/* + * 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.tuscany.binding.axis2; + +public interface Greeter { + + String sayHi(); + + String greetMe(String requestType); + + void greetMeOneWay(String requestType); + + void greetMeWithCallback(String requestType); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/GreetingCallback.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/GreetingCallback.java new file mode 100644 index 0000000000..4c3b3304ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/GreetingCallback.java @@ -0,0 +1,24 @@ +/* + * 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.tuscany.binding.axis2; + +public interface GreetingCallback { + + void greetMeCallback(String greetMeResponse); +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/resources/wsdl/hello_world_doc_lit.wsdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/resources/wsdl/hello_world_doc_lit.wsdl new file mode 100755 index 0000000000..2f56217f88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/test/resources/wsdl/hello_world_doc_lit.wsdl @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.checkstyle b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.checkstyle new file mode 100644 index 0000000000..a2af63613f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.pmd b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.pmd new file mode 100644 index 0000000000..3e1ff77730 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.pmd @@ -0,0 +1,23 @@ + + + + true + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.ruleset b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.ruleset new file mode 100644 index 0000000000..0933c1569c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/LICENSE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, serviceDefinition marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/NOTICE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/README.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/README.txt new file mode 100644 index 0000000000..9b26d1690a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/README.txt @@ -0,0 +1,35 @@ +Apache Tuscany M1 build (May, 2006) +=================================== + +http://incubator.apache.org/tuscany/ + +Tuscany is an effort undergoing incubation at the Apache Software Foundation +(ASF), sponsored by the Web Services PMC. + +Incubation is required of all newly accepted projects until a further review +indicates that the infrastructure, communications, and decision making process +have stabilized in a manner consistent with other successful ASF projects. + +While incubation status is not necessarily a reflection of the completeness or +stability of the code, it does indicate that the project has yet to be fully +endorsed by the ASF. + + +Support +------- + +Any problem with this release can be reported to the Tuscany mailing list +or in the JIRA issue tracker. + +Mailing list subscription: + tuscany-dev-subscribe@ws.apache.org + +Jira: + http://issues.apache.org/jira/browse/Tuscany + + +Thank you for using Tuscany! + + +The Tuscany Team. + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/pom.xml new file mode 100644 index 0000000000..0a71a1e338 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/pom.xml @@ -0,0 +1,96 @@ + + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + + 4.0.0 + celtix + Apache Tuscany Binding for Celtix + Implementation of the SCA Web Services binding using Celtix. + + + 1.0 + checkstyle.severity=error + true + + + + objectweb + ObjectWeb repo + http://maven.objectweb.org/maven2 + + true + + + false + + + + + + + org.apache.tuscany.sca.kernel + core + ${sca.version} + compile + + + + org.apache.tuscany.sca.services.idl + wsdl + ${sca.version} + compile + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + ${sca.version} + compile + + + + + org.objectweb.celtix + celtix-rt + ${celtix.version} + + + + junit + junit + + + org.easymock + easymockclassextension + + + woodstox + wstx-asl + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusService.java new file mode 100644 index 0000000000..238fbe97b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusService.java @@ -0,0 +1,35 @@ +/* + * 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.tuscany.binding.celtix; + +import org.objectweb.celtix.Bus; + +/** + * A system service that returns the active Celtix Bus for the runtime + * + * @version $Rev$ $Date$ + */ +public interface BusService { + + /** + * Returns the active bus + */ + Bus getBus(); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java new file mode 100644 index 0000000000..3a1c95c95e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java @@ -0,0 +1,77 @@ +/* + * 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.tuscany.binding.celtix; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; + +import org.objectweb.celtix.Bus; +import org.objectweb.celtix.BusException; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Scope; + +/** + * The default implementation of the Celtix Bus system service + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class BusServiceImpl implements BusService { + + protected WSDLDefinitionRegistry wsdlRegistry; + private Bus bus; + + public Bus getBus() { + return bus; + } + + /** + * FIXME the annotation processing framework must inject this + * @param wsdlReg + */ + @Property (override = "must") + public void setWsdlRegistry(WSDLDefinitionRegistry wsdlReg) { + wsdlRegistry = wsdlReg; + } + + /** + * Initializes the bus, set to be called when the runtime initializes the Celtix system composite + * @throws BusException + */ + @Init(eager = true) + public void init() throws BusException { + Map properties = new WeakHashMap(); + properties.put("celtix.WSDLManager", new TuscanyWSDLManager(wsdlRegistry)); + bus = Bus.init(new String[0], properties); + } + + /** + * Shuts down the bus, called when the runtime stops the Celtix system composite + * @throws BusException + */ + @Destroy + public void stop() throws BusException { + bus.shutdown(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java new file mode 100644 index 0000000000..ec1a71b19d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java @@ -0,0 +1,104 @@ +/* + * 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.tuscany.binding.celtix; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; +import org.objectweb.celtix.Bus; + +import commonj.sdo.helper.TypeHelper; + +/** + * Builds a {@link org.apache.tuscany.spi.component.Service} or {@link org.apache.tuscany.spi.component.Reference} + * configured with the Celtix binding + * + * @version $Rev$ $Date$ + */ +public class CeltixBindingBuilder extends BindingBuilderExtension { + + private Bus bus; + + public Service build(CompositeComponent parent, + BoundServiceDefinition boundServiceDefinition, + DeploymentContext deploymentContext) { + WebServiceBinding wsBinding = boundServiceDefinition.getBinding(); + TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName()); + if (typeHelper == null) { + typeHelper = TypeHelper.INSTANCE; + } + if (bus == null) { + bus = getBus(wsBinding.getWSDLDefinitionRegistry()); + } + return new CeltixService( + boundServiceDefinition.getName(), + boundServiceDefinition.getServiceContract().getInterfaceClass(), + parent, + wireService, + wsBinding, + bus, + typeHelper); + } + + public Reference build(CompositeComponent parent, + BoundReferenceDefinition boundReferenceDefinition, + DeploymentContext deploymentContext) { + WebServiceBinding wsBinding = boundReferenceDefinition.getBinding(); + TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName()); + if (typeHelper == null) { + typeHelper = TypeHelper.INSTANCE; + } + if (bus == null) { + bus = getBus(wsBinding.getWSDLDefinitionRegistry()); + } + return new CeltixReference( + boundReferenceDefinition.getName(), + boundReferenceDefinition.getServiceContract().getInterfaceClass(), + parent, + wireService, + wsBinding, + bus, + typeHelper); + } + + protected Class getBindingType() { + return WebServiceBinding.class; + } + + private Bus getBus(WSDLDefinitionRegistry wsdlDefinitionRegistry) { + Bus celtixBus = null; + try { + Map properties = new WeakHashMap(); + properties.put("celtix.WSDLManager", new TuscanyWSDLManager(wsdlDefinitionRegistry)); + celtixBus = Bus.init(new String[0], properties); + } catch (Exception e) { + e.printStackTrace(); + } + return celtixBus; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java new file mode 100644 index 0000000000..aba5fd5984 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java @@ -0,0 +1,245 @@ +/* + * 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.tuscany.binding.celtix; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import javax.jws.WebParam; +import javax.wsdl.Binding; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.xml.namespace.QName; +import javax.xml.ws.Holder; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; + +import commonj.sdo.helper.TypeHelper; +import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback; +import org.objectweb.celtix.Bus; +import org.objectweb.celtix.BusException; +import org.objectweb.celtix.bindings.ClientBinding; +import org.objectweb.celtix.bindings.DataBindingCallback; +import org.objectweb.celtix.bus.bindings.WSDLMetaDataCache; +import org.objectweb.celtix.bus.bindings.WSDLOperationInfo; +import org.objectweb.celtix.context.ObjectMessageContext; +import org.objectweb.celtix.ws.addressing.EndpointReferenceType; +import org.objectweb.celtix.wsdl.EndpointReferenceUtils; +import org.xmlsoap.schemas.wsdl.http.AddressType; + + +/** + * Responsible for dispatching a service operation invocation on a reference to the active Celtix Bus + * + * @version $Rev$ $Date$ + */ +public class CeltixInvoker implements TargetInvoker { + + private WSDLMetaDataCache wsdlCache; + + private ClientBinding clientBinding; + + private String operationName; + + private TypeHelper typeHelper; + + public CeltixInvoker(String operationName, + Bus bus, + Port port, + Service wsdlService, + Definition wsdlDef, + TypeHelper theTypeHelper) throws BuilderException { + this.wsdlCache = new WSDLMetaDataCache(wsdlDef, port); + this.operationName = operationName; + this.typeHelper = theTypeHelper; + // Definition wsdlDef = wsBinding.getWSDLDefinition(); + // wsdlCache = new WSDLMetaDataCache(wsdlDef, wsBinding.getWSDLPort()); + + try { + String key = wsdlDef.getDocumentBaseURI(); + URL url = new URL(key); + + QName qName = wsdlService.getQName(); + EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url, qName, port.getName()); + + String bindingId = null; + Binding binding = port.getBinding(); + if (null != binding) { + List list = binding.getExtensibilityElements(); + if (!list.isEmpty()) { + bindingId = ((ExtensibilityElement) list.get(0)).getElementType().getNamespaceURI(); + } + } + if (bindingId == null) { + List list = port.getExtensibilityElements(); + for (Object ep : list) { + ExtensibilityElement ext = (ExtensibilityElement) ep; + if (ext instanceof SOAPAddress) { + bindingId = ((SOAPAddress) ext).getLocationURI(); + } + if (ext instanceof AddressType) { + bindingId = ((AddressType) ext).getLocation(); + } + } + + } + clientBinding = bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference); + } catch (MalformedURLException e) { + throw new InvokerCreationException(e); + } catch (BusException e) { + throw new InvokerCreationException(e); + } catch (WSDLException e) { + throw new InvokerCreationException(e); + } catch (IOException e) { + throw new InvokerCreationException(e); + } + } + + /** + * Invoke an operation on the external Web service. + * + * @param args the Java object arguments to the WS operation + * @return the response from the WS as a Java object + */ + public Object invokeTarget(final Object args) throws InvocationTargetException { + WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName); + if (opInfo == null) { + // REVISIT - really map the operation name to a WSDL operation + for (String opName : wsdlCache.getAllOperationInfo().keySet()) { + if (operationName.equalsIgnoreCase(opName)) { + opInfo = wsdlCache.getOperationInfo(opName); + break; + } + } + } + + ObjectMessageContext objMsgContext = clientBinding.createObjectContext(); + + boolean hasInOut = false; + int inOutCount = 0; + Object realArgs[]; + Object argsArray[]; + if (args.getClass().isArray()) { + argsArray = (Object[]) args; + realArgs = new Object[Array.getLength(args)]; + } else { + argsArray = new Object[0]; + realArgs = new Object[0]; + } + + if (opInfo.getParamsLength() == 0) { + // REVISIT - opInfo doesn't return the needed info for the wrapped doc/lit case. + // Bug in Celtix + realArgs = argsArray; + } else { + for (int x = 0; x < argsArray.length; x++) { + if (opInfo.getWebParam(x).mode() == WebParam.Mode.IN) { + realArgs[x] = argsArray[x]; + } else { + realArgs[x] = new Holder(argsArray[x]); + inOutCount++; + hasInOut = true; + } + } + } + objMsgContext.setMessageObjects(realArgs); + boolean isOneway = opInfo.isOneWay(); + DataBindingCallback callback = new SCADataBindingCallback(opInfo, hasInOut, typeHelper); + try { + if (isOneway) { + clientBinding.invokeOneWay(objMsgContext, callback); + } else { + objMsgContext = clientBinding.invoke(objMsgContext, callback); + } + } catch (IOException e) { + throw new InvocationTargetException(e); + } + + if (objMsgContext.getException() != null) { + // REVISIT - Exceptions + /* + * if (isValidException(objMsgContext)) { throw + * (Exception)objMsgContext.getException(); } else { throw new + * ProtocolException(objMsgContext.getException()); } + */ + throw new InvocationTargetException(objMsgContext.getException()); + } + + if (hasInOut) { + Object ret[] = new Object[inOutCount + 1]; + ret[0] = objMsgContext.getReturn(); + inOutCount = 1; + for (int x = 0; x < argsArray.length; x++) { + if (opInfo.getWebParam(x).mode() != WebParam.Mode.IN) { + Holder holder = (Holder) realArgs[x]; + ret[inOutCount] = holder.value; + inOutCount++; + } + } + return ret; + } + return objMsgContext.getReturn(); + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public void setNext(Interceptor next) { + throw new UnsupportedOperationException(); + } + + public CeltixInvoker clone() throws CloneNotSupportedException { + try { + return (CeltixInvoker) super.clone(); + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } + + public boolean isCacheable() { + return true; + } + + public void setCacheable(boolean cacheable) { + + } + + public boolean isOptimizable() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java new file mode 100644 index 0000000000..c32f332d4b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.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 org.apache.tuscany.binding.celtix; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ReferenceExtension; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; + +import commonj.sdo.helper.TypeHelper; +import org.objectweb.celtix.Bus; + +/** + * The implementation of a {@link org.apache.tuscany.spi.component.Reference} configured with the Celtix binding + * + * @version $Rev$ $Date$ + */ +public class CeltixReference extends ReferenceExtension { + + private Bus bus; + private Port port; + private Definition wsdlDef; + private Service wsdlService; + private TypeHelper typeHelper; + + public CeltixReference(String name, + Class interfaze, + CompositeComponent parent, + WireService wireService, + WebServiceBinding binding, + Bus theBus, + TypeHelper theTypeHelper) { + super(name, interfaze, parent, wireService); + this.wsdlDef = binding.getWSDLDefinition(); + this.port = binding.getWSDLPort(); + this.wsdlService = binding.getWSDLService(); + this.bus = theBus; + this.typeHelper = theTypeHelper; + } + + public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { + return new CeltixInvoker(operation.getName(), bus, port, wsdlService, wsdlDef, typeHelper); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java new file mode 100644 index 0000000000..097f0ac050 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java @@ -0,0 +1,270 @@ +/* + * 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.tuscany.binding.celtix; + +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import javax.jws.soap.SOAPBinding; +import javax.wsdl.Binding; +import javax.wsdl.BindingInput; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.xml.namespace.QName; +import javax.xml.ws.WebServiceProvider; + +import org.osoa.sca.annotations.Destroy; + +import org.apache.tuscany.spi.CoreRuntimeException; +import org.apache.tuscany.spi.builder.BuilderConfigException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.wire.WireService; + +import commonj.sdo.helper.TypeHelper; +import org.apache.tuscany.binding.celtix.io.SCAServerDataBindingCallback; +import org.objectweb.celtix.Bus; +import org.objectweb.celtix.bindings.BindingFactory; +import org.objectweb.celtix.bindings.DataBindingCallback; +import org.objectweb.celtix.bindings.ServerBinding; +import org.objectweb.celtix.bindings.ServerBindingEndpointCallback; +import org.objectweb.celtix.bindings.ServerDataBindingCallback; +import org.objectweb.celtix.bus.bindings.WSDLMetaDataCache; +import org.objectweb.celtix.bus.bindings.WSDLOperationInfo; +import org.objectweb.celtix.context.ObjectMessageContext; +import org.objectweb.celtix.ws.addressing.AttributedURIType; +import org.objectweb.celtix.ws.addressing.EndpointReferenceType; +import org.objectweb.celtix.wsdl.EndpointReferenceUtils; +import org.xmlsoap.schemas.wsdl.http.AddressType; + + +/** + * An implementation of a {@link Service} configured with the Celtix binding + * + * @version $Rev$ $Date$ + */ +public class CeltixService extends ServiceExtension implements ServerBindingEndpointCallback { + + private Bus bus; + private Port port; + private Definition wsdlDef; + private Service wsdlService; + private WSDLMetaDataCache wsdlCache; + private TypeHelper typeHelper; + + private Map opMap = + new ConcurrentHashMap(); + + + public CeltixService(String theName, + Class interfaze, + CompositeComponent parent, + WireService wireService, + WebServiceBinding binding, + Bus bus, + TypeHelper theTypeHelper) { + super(theName, interfaze, parent, wireService); + this.wsdlDef = binding.getWSDLDefinition(); + this.port = binding.getWSDLPort(); + this.wsdlService = binding.getWSDLService(); + this.bus = bus; + this.wsdlCache = new WSDLMetaDataCache(wsdlDef, port); + this.typeHelper = theTypeHelper; + } + + public void start() { + super.start(); + initOperationMap(); + startServerBinding(); + } + + private void startServerBinding() { + String key = wsdlDef.getDocumentBaseURI(); + URL url; + try { + url = new URL(key); + } catch (MalformedURLException e) { + throw new CeltixServiceInitException(e); + } + + QName qName = wsdlService.getQName(); + String portName = port.getName(); + EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url,qName,portName); + + AttributedURIType address = new AttributedURIType(); + + String bindingId = null; + Binding binding = port.getBinding(); + if (null != binding) { + List list = binding.getExtensibilityElements(); + if (!list.isEmpty()) { + bindingId = ((ExtensibilityElement) list.get(0)).getElementType().getNamespaceURI(); + } + } + List list = port.getExtensibilityElements(); + for (Object ep : list) { + ExtensibilityElement ext = (ExtensibilityElement) ep; + if (ext instanceof SOAPAddress) { + if (bindingId == null) { + bindingId = ((SOAPAddress) ext).getLocationURI(); + } + address.setValue(((SOAPAddress) ext).getLocationURI()); + } + if (ext instanceof AddressType) { + if (bindingId == null) { + bindingId = ((AddressType) ext).getLocation(); + } + address.setValue(((AddressType) ext).getLocation()); + } + } + if (reference.getAddress() == null) { + //REVIST - bug in Celtix that the HTTP transport won't find the address correctly + reference.setAddress(address); + } + ClassLoader previousLoader = null; + try { + //FIXME: This hack is because SAAJImpl uses Thread.currentThread().getContextClassLoader(), + //this classloader is different from current classLoader. + previousLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + BindingFactory bindingFactory = bus.getBindingManager().getBindingFactory(bindingId); + ServerBinding serverBinding = bindingFactory.createServerBinding(reference, this); + serverBinding.activate(); + } catch (Exception e) { + throw new CeltixServiceInitException(e); + } finally { + if (previousLoader != null) { + Thread.currentThread().setContextClassLoader(previousLoader); + } + } + } + + private void initOperationMap() { + List ops = port.getBinding().getBindingOperations(); + for (Object op1 : ops) { + BindingOperation op = (BindingOperation) op1; + BindingInput bindingInput = op.getBindingInput(); + List elements = bindingInput.getExtensibilityElements(); + QName qn = new QName(wsdlDef.getTargetNamespace(), op.getName()); + + //In case soap:body namespace is different from targetNamespace + for (Object element : elements) { + if (SOAPBody.class.isInstance(element)) { + SOAPBody body = (SOAPBody) element; + if (body.getNamespaceURI() != null) { + qn = new QName(body.getNamespaceURI(), op.getName()); + } + } + } + + ServerDataBindingCallback cb = getDataBindingCallback(qn, null, DataBindingCallback.Mode.PARTS); + opMap.put(qn, cb); + if (!"".equals(cb.getRequestWrapperQName().getLocalPart())) { + opMap.put(cb.getRequestWrapperQName(), cb); + } + } + } + + @Destroy + public void stop() throws CoreRuntimeException { + super.stop(); + } + + public ServerDataBindingCallback getDataBindingCallback(QName operationName, + ObjectMessageContext objContext, + DataBindingCallback.Mode mode) { + if (opMap.containsKey(operationName)) { + return opMap.get(operationName); + } + WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName.getLocalPart()); + if (opInfo == null) { + //REVISIT - really map the operation name to a WSDL operation + for (String opName : wsdlCache.getAllOperationInfo().keySet()) { + if (operationName.getLocalPart().equalsIgnoreCase(opName)) { + opInfo = wsdlCache.getOperationInfo(opName); + break; + } + } + } + boolean inout = false; + + Class serviceInterface = this.getInterface(); + Method meth = getMethod(serviceInterface, operationName.getLocalPart()); + + Object proxy = this.getServiceInstance(); + + return new SCAServerDataBindingCallback(opInfo, inout, meth, proxy, typeHelper); + } + + protected Method getMethod(Class serviceInterface, String operationName) { + // Note: this doesn't support overloaded operations + Method[] methods = serviceInterface.getMethods(); + for (Method m : methods) { + if (m.getName().equals(operationName)) { + return m; + } + // tolerate WSDL with capatalized operation name + StringBuilder sb = new StringBuilder(operationName); + sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); + if (m.getName().equals(sb.toString())) { + return m; + } + } + throw new BuilderConfigException("no operation named " + operationName + + " found on service interface: " + serviceInterface.getName()); + } + + public DataBindingCallback getFaultDataBindingCallback(ObjectMessageContext objContext) { + // REVISIT - what to do about faults + return null; + } + + public Map getOperations() { + return opMap; + } + + public SOAPBinding.Style getStyle() { + return wsdlCache.getStyle(); + } + + public DataBindingCallback.Mode getServiceMode() { + return DataBindingCallback.Mode.PARTS; + } + + public WebServiceProvider getWebServiceProvider() { + //not needed I think + return null; + } + + public Executor getExecutor() { + //Let the transport handle it (or it goes to the Bus default wq + //if the transport cannot handle it + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java new file mode 100644 index 0000000000..4eca4a3bd1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.binding.celtix; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * Denotes an exception starting a {@link CeltixService} instance + * + * @version $Rev$ $Date$ + */ +public class CeltixServiceInitException extends CoreRuntimeException { + public CeltixServiceInitException() { + } + + public CeltixServiceInitException(String message) { + super(message); + } + + public CeltixServiceInitException(String message, Throwable cause) { + super(message, cause); + } + + public CeltixServiceInitException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java new file mode 100644 index 0000000000..e08a3193d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.binding.celtix; + +import org.apache.tuscany.spi.builder.BuilderException; + +/** + * Thrown when an error is encountered creating a {@link CeltixInvoker} + * + * @version $Rev$ $Date$ + */ +public class InvokerCreationException extends BuilderException { + public InvokerCreationException() { + } + + public InvokerCreationException(String message) { + super(message); + } + + public InvokerCreationException(String message, Throwable cause) { + super(message, cause); + } + + public InvokerCreationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java new file mode 100644 index 0000000000..18efe80da5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java @@ -0,0 +1,89 @@ +/* + * 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.tuscany.binding.celtix; + +import java.io.IOException; +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; + +import org.w3c.dom.Element; +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; + +import org.objectweb.celtix.wsdl.WSDLManager; + +/** + * + * @version $Rev$ $Date$ + */ +public class TuscanyWSDLManager implements WSDLManager { + WSDLDefinitionRegistry wsdlDefinitionRegistry; + + public TuscanyWSDLManager(WSDLDefinitionRegistry w) { + wsdlDefinitionRegistry = w; + } + + public WSDLFactory getWSDLFactory() { + //Not supported + return null; + } + + public ExtensionRegistry getExtenstionRegistry() { + return wsdlDefinitionRegistry.getExtensionRegistry(); + } + + public Definition getDefinition(URL url) throws WSDLException { + try { + return wsdlDefinitionRegistry.loadDefinition(null, url); + } catch (IOException e) { + //FIXME + throw new WSDLException("", "", e); + } + } + + public Definition getDefinition(String url) throws WSDLException { + try { + //The namespace is the wsdl targetNamesapce, it is only used + //when the wsdl is created into cache. we are ok here to set it to null. + //FIXME pass the current ResourceLoader + return wsdlDefinitionRegistry.loadDefinition(null, new URL(url)); + } catch (IOException e) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, e.getMessage()); + } + } + + public Definition getDefinition(Element el) throws WSDLException { + throw new UnsupportedOperationException(); + } + + public Definition getDefinition(Class sei) throws WSDLException { + throw new UnsupportedOperationException(); + } + + public void addDefinition(Object key, Definition wsdl) { + throw new UnsupportedOperationException(); + } + + public void shutdown() { + } + + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBinding.java new file mode 100644 index 0000000000..49df9a6e28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBinding.java @@ -0,0 +1,90 @@ +/* + * 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.tuscany.binding.celtix; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; + +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a Celtix binding configuration in an assembly + * + * @version $Rev$ $Date$ + */ +public class WebServiceBinding extends Binding { + + private Definition definition; + private Port port; + private Service service; + //private String portURI; + private String uri; + //We have to use WebServiceBinding to pass WSDLDefinitionRegistry to BindingBuilder + private WSDLDefinitionRegistry wsdlDefinitionRegistry; + + public WebServiceBinding(Definition definition, Port port, String uri, String portURI, Service service) { + this.definition = definition; + this.port = port; + this.uri = uri; + //this.portURI = portURI; + this.service = service; + } + + public Port getWSDLPort() { + return port; + } + + public Service getWSDLService() { + return service; + } + + public void setWSDLPort(Port value) { + port = value; + } + + public Definition getWSDLDefinition() { + return definition; + } + + public void setWSDLDefinition(Definition def) { + definition = def; + } + + public WSDLDefinitionRegistry getWSDLDefinitionRegistry() { + return wsdlDefinitionRegistry; + } + + public void setWSDLDefinitionRegistry(WSDLDefinitionRegistry theWsdlDefinitionRegistry) { + wsdlDefinitionRegistry = theWsdlDefinitionRegistry; + } + +// public void setPortURI(String uri) { +// portURI = uri; +// } + + public String getURI() { + return uri; + } + + public void setURI(String theUri) { + this.uri = theUri; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java new file mode 100644 index 0000000000..5b11d02931 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java @@ -0,0 +1,195 @@ +/* + * 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.tuscany.binding.celtix; + + +import java.io.IOException; +import java.net.URL; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.xml.sax.InputSource; +import static org.osoa.sca.Version.XML_NAMESPACE_1_0; +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Scope; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; + +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry; +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl; +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl.Monitor; + +/** + * Parses a WebServiceBinding entry in an assembly XML file + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class WebServiceBindingLoader extends LoaderExtension { + public static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws"); + + protected WSDLDefinitionRegistry wsdlRegistry; + + @Constructor({"registry"}) + public WebServiceBindingLoader(@Autowire LoaderRegistry registry) { + super(registry); + + //FIXME: this is a hack, WSDLDefinitionRegistry should not be created here + if (wsdlRegistry == null) { + try { + wsdlRegistry = new WSDLDefinitionRegistryImpl(); + Monitor monitor = new Monitor() { + public void readingWSDL(String namespace, URL location) { + } + + public void cachingDefinition(String namespace, URL location) { + } + }; + + ((WSDLDefinitionRegistryImpl) wsdlRegistry).setMonitor(monitor); + } catch (javax.wsdl.WSDLException e) { + //do nothing + } + } + } + + public QName getXMLType() { + return BINDING_WS; + } + + public WebServiceBinding load(CompositeComponent parent, + XMLStreamReader reader, + DeploymentContext deploymentContext) + throws XMLStreamException, LoaderException { + // not sure what uri was here ? String uri = reader.getAttributeValue(null, "uri"); + String uri = null; + String endpointAttribute = reader.getAttributeValue(null, "endpoint"); + //String portURI = reader.getAttributeValue(null, "port"); + String wsdlLocation = reader.getAttributeValue(null, "location"); + try { + return createBinding(uri, endpointAttribute, wsdlLocation, deploymentContext); + } catch (Exception e) { + + throw new LoaderException(e); + } + } + + private WebServiceBinding createBinding(String port, String portURI, String wsdlLocation, + DeploymentContext deploymentContext) + throws WSDLException, IOException { + List definitions = null; + // FIXME wsdlRegistry.getDefinitionsForNamespace(portNamespace, + // resourceLoader); + // Get the WSDL port namespace and name + if (port == null && portURI != null) { + int h = portURI.indexOf('#'); + String portNamespace = portURI.substring(0, h); + String serviceName; + String portName; + + String fragment = portURI.substring(h + 1); + if (fragment.startsWith("wsdl.endpoint(") && fragment.endsWith(")")) { + fragment = fragment.substring(14, fragment.length() - 1); + int slash = fragment.indexOf('/'); + if (slash != -1) { + serviceName = fragment.substring(0, slash); + portName = fragment.substring(slash + 1); + } else { + serviceName = null; + portName = fragment; + } + } else { + serviceName = null; + portName = fragment; + } + + // FIXME need to find out how to get wsdl and what context to use --- terrible hack attack! + // URL wsdlurl = Thread.currentThread().getContextClassLoader().getResource(wsdlLocation); + if (null == wsdlLocation) { + throw new RuntimeException("Failed to determin wsdl location on binding. " + + "Try specifying 'location' attribute on binding."); + } + URL wsdlurl = deploymentContext.getClassLoader().getResource(wsdlLocation); + if (wsdlurl == null) { + throw new RuntimeException("Failed to load wsdl from '" + wsdlLocation + "'"); + } + + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + InputSource input = new InputSource(wsdlurl.openStream()); + Definition wsdlDef = reader.readWSDL(wsdlurl.toString(), input); + definitions = new LinkedList(); + definitions.add(wsdlDef); + // FIXME all the above needs to better addressed. + + //FIXME: if a global wsdl cached is used, we need to do a registration here + String namespace = wsdlDef.getTargetNamespace(); + wsdlRegistry.loadDefinition(namespace, wsdlurl); + + Definition definition = null; + Port thePort = null; + Service service = null; + for (Definition def : definitions) { + + // Find the port with the given name + for (Service serv : (Collection) def.getServices().values()) { + QName sqn = serv.getQName(); + if (serviceName != null + && !serviceName.equals(sqn.getLocalPart())) { + continue; + } + + Port p = serv.getPort(portName); + if (p != null) { + service = serv; + definition = def; + thePort = p; + break; + } + } + } + if (thePort == null) { + throw new IllegalArgumentException("Cannot find WSDL port " + portURI); + + } + WebServiceBinding wsBinding = new WebServiceBinding(definition, thePort, port, portURI, service); + wsBinding.setWSDLDefinitionRegistry(wsdlRegistry); + return wsBinding; + } + // FIXME - return a broken binding for now + return new WebServiceBinding(null, null, null, portURI, null); + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java new file mode 100644 index 0000000000..7a14ab33fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java @@ -0,0 +1,205 @@ +/* + * 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.tuscany.binding.celtix.io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.List; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.w3c.dom.Node; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import static org.w3c.dom.bootstrap.DOMImplementationRegistry.PROPERTY; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSOutput; +import org.w3c.dom.ls.LSSerializer; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; + +import org.apache.tuscany.core.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument; +import org.objectweb.celtix.bindings.DataReader; +import org.objectweb.celtix.context.ObjectMessageContext; + +public class NodeDataReader implements DataReader { + + private SCADataBindingCallback callback; + + public NodeDataReader(SCADataBindingCallback cb) { + callback = cb; + } + + public Object read(int idx, Node input) { + return read(null, idx, input); + } + + public Object read(QName name, int idx, Node input) { + try { + InputStream in = getNodeStream(input); + XMLInputFactory staxFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = staxFactory.createXMLStreamReader(in); + + XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument(); + TransformationContext context = new TransformationContextImpl(); + DataType binding = new DataType(DataObject.class, null); + binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper()); + context.setTargetDataType(binding); + XMLDocument document = transformer.transform(reader, context); + + boolean isWrapped = false; + return toObjects(document, isWrapped); + } catch (Exception e) { + //REVISIT: better handling of exceptions + } + return null; + } + + public void readWrapper(ObjectMessageContext objCtx, boolean isOutBound, Node input) { + try { + QName wrapperName; + if (isOutBound) { + wrapperName = callback.getOperationInfo().getResponseWrapperQName(); + } else { + wrapperName = callback.getOperationInfo().getRequestWrapperQName(); + } + + Node nd = input.getFirstChild(); + while (nd != null + && !wrapperName.getNamespaceURI().equals(nd.getNamespaceURI()) + && !wrapperName.getLocalPart().equals(nd.getLocalName())) { + nd = nd.getNextSibling(); + } + + //REVISIT - This is SUCH a HACK. This needs to be done with StAX or something + //a bit better than streaming and reparsing + InputStream in = getNodeStream(nd); + XMLInputFactory staxFactory = XMLInputFactory.newInstance( + "javax.xml.stream.XMLInputFactory", getClass().getClassLoader()); + XMLStreamReader reader = staxFactory.createXMLStreamReader(in); + + XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument(); + TransformationContext context = new TransformationContextImpl(); + DataType binding = new DataType(DataObject.class, null); + binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper()); + context.setTargetDataType(binding); + XMLDocument document = transformer.transform(reader, context); + + //boolean isWrapped = true; + Object[] objects = toObjects(document, true); + + if (callback.hasInOut()) { + //REVISIT - inOuts + } else { + if (isOutBound) { + objCtx.setReturn(objects[0]); + } else { + objCtx.setMessageObjects(objects); + } + } + } catch (Exception e) { + //REVISIT: better handling of exceptions + } + } + + /** + * Convert a typed DataObject to Java objects + * + * @param document + * @param isWrapped + * @return the array of Objects from the DataObject + */ + public static Object[] toObjects(XMLDocument document, boolean isWrapped) { + DataObject dataObject = document.getRootObject(); + if (isWrapped) { + List ips = dataObject.getInstanceProperties(); + Object[] os = new Object[ips.size()]; + for (int i = 0; i < ips.size(); i++) { + os[i] = dataObject.get((Property) ips.get(i)); + } + return os; + } else { + Object object = dataObject; + Type type = dataObject.getType(); + if (type.isSequenced()) { + object = dataObject.getSequence().getValue(0); + } + return new Object[]{object}; + } + } + + byte[] getNodeBytes(Node node) + throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException { + + //This is also a hack, the JDK should already have this set, but it doesn't + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + if (registry == null) { + System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); + registry = DOMImplementationRegistry.newInstance(); + } + DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + if (impl == null) { + System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); + registry = DOMImplementationRegistry.newInstance(); + impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + } + LSOutput output = impl.createLSOutput(); + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + output.setByteStream(bout); + LSSerializer writer = impl.createLSSerializer(); + writer.write(node, output); + + return bout.toByteArray(); + } + + InputStream getNodeStream(Node node) + throws ClassCastException, ClassNotFoundException, + InstantiationException, IllegalAccessException { + + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + if (registry == null) { + //This is also a hack, the JDK should already have this set, but it doesn't + System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); + registry = DOMImplementationRegistry.newInstance(); + } + DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + if (impl == null) { + System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); + registry = DOMImplementationRegistry.newInstance(); + impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + } + LSOutput output = impl.createLSOutput(); + RawByteArrayOutputStream bout = new RawByteArrayOutputStream(); + output.setByteStream(bout); + LSSerializer writer = impl.createLSSerializer(); + writer.write(node, output); + + return new ByteArrayInputStream(bout.getBytes(), 0, bout.size()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java new file mode 100644 index 0000000000..d870cafa87 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java @@ -0,0 +1,322 @@ +/* + * 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.tuscany.binding.celtix.io; + +import java.util.List; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import org.apache.tuscany.spi.wire.InvocationRuntimeException; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.objectweb.celtix.bindings.DataWriter; +import org.objectweb.celtix.context.ObjectMessageContext; + +public class NodeDataWriter implements DataWriter { + private static final String XML_NS = "http://www.w3.org/2000/xmlns/"; + private SCADataBindingCallback callback; + + public NodeDataWriter(SCADataBindingCallback cb) { + callback = cb; + } + + public void write(Object obj, Node output) { + write(obj, null, output); + } + + public void write(Object obj, QName elName, Node output) { + boolean isWrapped = false; + + XMLDocument document = toXMLDocument(callback.getTypeHelper(), new Object[]{obj}, elName, isWrapped); + // HACK: [rfeng] We should use the transformer in an interceptor + XMLDocument2XMLStreamReader transformer = new XMLDocument2XMLStreamReader(); + XMLStreamReader reader = transformer.transform(document, null); + + try { + //CeltixFire supports Stax, we should not need to do following anymore. + readDocElements(output, reader, true, null); + } catch (XMLStreamException e) { + throw new InvocationRuntimeException(e.getMessage()); + } + } + + public void writeWrapper(ObjectMessageContext objCtx, boolean isOutbound, Node output) { + boolean isWrapped = true; + QName wrapperName; + if (isOutbound) { + wrapperName = callback.getOperationInfo().getResponseWrapperQName(); + } else { + wrapperName = callback.getOperationInfo().getRequestWrapperQName(); + } + + XMLDocument document = toXMLDocument( + callback.getTypeHelper(), objCtx.getMessageObjects(), wrapperName, isWrapped); + // HACK: [rfeng] We should use the transformer in an interceptor + XMLDocument2XMLStreamReader transformer = new XMLDocument2XMLStreamReader(); + XMLStreamReader reader = transformer.transform(document, null); + + try { + readDocElements(output, reader, true, null); + } catch (XMLStreamException e) { + e.printStackTrace(); + throw new InvocationRuntimeException(e.getMessage()); + } + } +/* + private DataObject toWrappedDataObject(TypeHelper typeHelper, + Object ret, + Object[] os, + QName typeQN) { + XSDHelper xsdHelper = new XSDHelperImpl(typeHelper); + Property property = xsdHelper.getGlobalProperty(typeQN.getNamespaceURI(), + typeQN.getLocalPart(), true); + DataObject dataObject = new DataFactoryImpl(typeHelper).create(property.getType()); + List ips = dataObject.getInstanceProperties(); + int offset = 0; + if (ret != null) { + dataObject.set(0, ret); + offset = 1; + } + for (int i = offset; i < ips.size(); i++) { + if (os[i - offset] instanceof Holder) { + Holder holder = (Holder)os[i - offset]; + dataObject.set(i, holder.value); + } else { + dataObject.set(i, os[i - offset]); + } + } + return dataObject; + } +*/ + + /** + * Convert objects to typed DataObject + * + * @param typeHelper + * @param os + * @param elementQName + * @param isWrapped + * @return the DataObject + */ + private static XMLDocument toXMLDocument(TypeHelper typeHelper, + Object[] os, + QName elementQName, + boolean isWrapped) { + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + + Property property = xsdHelper.getGlobalProperty( + elementQName.getNamespaceURI(), elementQName.getLocalPart(), true); + if (null == property) { + throw new InvocationRuntimeException( + "Type '" + elementQName.toString() + "' not found in registered SDO types."); + } + DataObject dataObject; + if (isWrapped) { + DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper); + dataObject = dataFactory.create(property.getType()); + List ips = dataObject.getInstanceProperties(); + for (int i = 0; i < ips.size(); i++) { + dataObject.set(i, os[i]); + } + } else { + Object value = os[0]; + Type type = property.getType(); + if (!type.isDataType()) { + dataObject = (DataObject) value; + } else { + dataObject = SDOUtil.createDataTypeWrapper(type, value); + } + } + + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + return xmlHelper.createDocument(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart()); + + } + + //REVISIT: We should not need to do following anymore with CeltixFire. + //As CeltixFire supports stax directly. + + /** + * @param parent + * @param reader + * @param repairing + * @param stopAt: stop at the specified element + * @throws XMLStreamException + */ + public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing, QName stopAt) + throws XMLStreamException { + Document doc = getDocument(parent); + + int event = reader.getEventType(); + + while (reader.hasNext()) { + switch (event) { + case XMLStreamConstants.START_ELEMENT: + if (startElement(parent, reader, repairing, stopAt) == null) { + return; + } + if (parent instanceof Document && stopAt != null) { + if (reader.hasNext()) { + reader.next(); + } + return; + } + break; + case XMLStreamConstants.END_ELEMENT: + return; + case XMLStreamConstants.NAMESPACE: + break; + case XMLStreamConstants.ATTRIBUTE: + break; + case XMLStreamConstants.CHARACTERS: + if (parent != null) { + parent.appendChild(doc.createTextNode(reader.getText())); + } + + break; + case XMLStreamConstants.COMMENT: + if (parent != null) { + parent.appendChild(doc.createComment(reader.getText())); + } + + break; + case XMLStreamConstants.CDATA: + parent.appendChild(doc.createCDATASection(reader.getText())); + + break; + case XMLStreamConstants.PROCESSING_INSTRUCTION: + parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); + + break; + case XMLStreamConstants.ENTITY_REFERENCE: + parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); + + break; + default: + break; + } + + if (reader.hasNext()) { + event = reader.next(); + } + } + } + + private static Document getDocument(Node parent) { + return (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); + } + + /** + * @param parent + * @param reader + * @return + * @throws XMLStreamException + */ + private static Element startElement(Node parent, XMLStreamReader reader, boolean repairing, QName stopAt) + throws XMLStreamException { + Document doc = getDocument(parent); + + if (stopAt != null && stopAt.getNamespaceURI().equals(reader.getNamespaceURI()) + && stopAt.getLocalPart().equals(reader.getLocalName())) { + return null; + } + + Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName()); + + if (reader.getPrefix() != null) { + e.setPrefix(reader.getPrefix()); + } + + parent.appendChild(e); + + for (int ns = 0; ns < reader.getNamespaceCount(); ns++) { + String uri = reader.getNamespaceURI(ns); + String prefix = reader.getNamespacePrefix(ns); + + declare(e, uri, prefix); + } + + for (int att = 0; att < reader.getAttributeCount(); att++) { + String name = reader.getAttributeLocalName(att); + String prefix = reader.getAttributePrefix(att); + if (prefix != null && prefix.length() > 0) { + name = prefix + ":" + name; + } + + Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name); + attr.setValue(reader.getAttributeValue(att)); + e.setAttributeNode(attr); + } + + reader.next(); + + readDocElements(e, reader, repairing, stopAt); + + if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix())) { + declare(e, reader.getNamespaceURI(), reader.getPrefix()); + } + + return e; + } + + private static void declare(Element node, String uri, String prefix) { + if (prefix != null && prefix.length() > 0) { + node.setAttributeNS(XML_NS, "xmlns:" + prefix, uri); + } else { + if (uri != null /* && uri.length() > 0 */) { + node.setAttributeNS(XML_NS, "xmlns", uri); + } + } + } + + private static boolean isDeclared(Element e, String namespaceURI, String prefix) { + Attr att; + if (prefix != null && prefix.length() > 0) { + att = e.getAttributeNodeNS(XML_NS, "xmlns:" + prefix); + } else { + att = e.getAttributeNode("xmlns"); + } + + if (att != null && att.getNodeValue().equals(namespaceURI)) { + return true; + } + + if (e.getParentNode() instanceof Element) { + return isDeclared((Element) e.getParentNode(), namespaceURI, prefix); + } + + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java new file mode 100644 index 0000000000..057481041b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.binding.celtix.io; + +import java.io.ByteArrayOutputStream; + +/** + * Just to allow raw access to the byte[] to avoid a copy + */ +class RawByteArrayOutputStream extends ByteArrayOutputStream { + public byte[] getBytes() { + return buf; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java new file mode 100644 index 0000000000..47d130383f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java @@ -0,0 +1,83 @@ +/* + * 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.tuscany.binding.celtix.io; + +import org.w3c.dom.Node; + +import commonj.sdo.helper.TypeHelper; +import org.objectweb.celtix.bindings.DataReader; +import org.objectweb.celtix.bindings.DataWriter; +import org.objectweb.celtix.bus.bindings.AbstractWSDLOperationDataBindingCallback; +import org.objectweb.celtix.bus.bindings.WSDLOperationInfo; +import org.objectweb.celtix.context.ObjectMessageContext; + + +/** + * @version $Rev$ $Date$ + */ +public class SCADataBindingCallback extends AbstractWSDLOperationDataBindingCallback { + + protected boolean hasInOut; + protected TypeHelper typeHelper; + + public SCADataBindingCallback(WSDLOperationInfo op, boolean inout, TypeHelper theTypeHelper) { + super(op); + this.hasInOut = inout; + this.typeHelper = theTypeHelper; + } + + public boolean hasInOut() { + return hasInOut; + } + + public Mode getMode() { + return Mode.PARTS; + } + + public Class[] getSupportedFormats() { + return new Class[]{Node.class}; + } + + public TypeHelper getTypeHelper() { + return typeHelper; + } + + @SuppressWarnings("unchecked") + public DataWriter createWriter(Class cls) { + if (cls == Node.class) { + return (DataWriter) new NodeDataWriter(this); + } + return null; + } + + @SuppressWarnings("unchecked") + public DataReader createReader(Class cls) { + if (cls == Node.class) { + return (DataReader) new NodeDataReader(this); + } + //REVISIT - need to figure out what to do with Faults + return null; + } + + public void initObjectContext(ObjectMessageContext octx) { + //REVISIT - is this even used? + } + + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java new file mode 100644 index 0000000000..db9c624bd4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.binding.celtix.io; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import commonj.sdo.helper.TypeHelper; + +import org.objectweb.celtix.bindings.ServerDataBindingCallback; +import org.objectweb.celtix.bus.bindings.WSDLOperationInfo; +import org.objectweb.celtix.context.ObjectMessageContext; + + +/** + * + * @version $Rev$ $Date$ + */ +public class SCAServerDataBindingCallback extends SCADataBindingCallback + implements ServerDataBindingCallback { + Method method; + Object targetObject; + + public SCAServerDataBindingCallback(WSDLOperationInfo op, + boolean inout, + Method meth, + Object target, + TypeHelper theTypeHelper) { + super(op, inout, theTypeHelper); + method = meth; + targetObject = target; + } + + + public void invoke(ObjectMessageContext octx) throws InvocationTargetException { + Object ret; + try { + ret = method.invoke(targetObject, octx.getMessageObjects()); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new InvocationTargetException(e); + } + octx.setReturn(ret); + } + + public void initObjectContext(ObjectMessageContext octx) { + Object o[] = new Object[method.getParameterTypes().length]; + //REVIST - holders? + octx.setMessageObjects(o); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..b6a5334903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java new file mode 100644 index 0000000000..cba83a7792 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/BootstrapTestCase.java @@ -0,0 +1,35 @@ +/* + * 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.tuscany.binding.celtix; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class BootstrapTestCase extends TestCase { + + public void testReference() throws Exception { +// BusServiceImpl busService = new BusServiceImpl(); +// WSDLDefinitionRegistry wsdlRegistry = new WSDLDefinitionRegistryImpl(); +// busService.setWsdlRegistry(wsdlRegistry); +// busService.init(); +// CeltixReference reference = new CeltixReference("reference",); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java new file mode 100644 index 0000000000..5440fc22ce --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java @@ -0,0 +1,134 @@ +/* + * 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.tuscany.binding.celtix; + +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.xml.sax.InputSource; + +import junit.framework.TestCase; +import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback; +import org.easymock.classextension.EasyMock; +import org.objectweb.celtix.Bus; +import org.objectweb.celtix.bindings.BindingManager; +import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory; +import org.objectweb.celtix.bus.bindings.soap.SOAPClientBinding; +import org.objectweb.celtix.context.ObjectMessageContextImpl; +import org.objectweb.celtix.ws.addressing.EndpointReferenceType; + +/** + * @version $Rev$ $Date$ + */ +public class CeltixInvokerTestCase extends TestCase { + + public void testProcessingInputWithoutInOut() throws Exception { + String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; + String operationName = "greetMe"; + ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl(); + CeltixInvoker invoker = createCeltixInvoker(wsdlLocation, + operationName, inputCtx); + + Object[] args = new Object[1]; + args[0] = new String("hello"); + invoker.invokeTarget(args); + + // Check the input object after processing is correct + // Should be no change for input if only IN parameters involved + Object[] myrtn = (Object[]) inputCtx.getMessageObjects(); + + assertEquals("hello", myrtn[0]); + } + + public void testProcessingInputWithInOut() throws Exception { + String wsdlLocation = "/wsdl/hello_world_doc_lit_inout.wsdl"; + String operationName = "greetMe"; + ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl(); + CeltixInvoker invoker = createCeltixInvoker(wsdlLocation, + operationName, inputCtx); + + Object[] args = new Object[1]; + String inputvalue = new String("hello"); + args[0] = inputvalue; + Object result = invoker.invokeTarget(args); + + // Check the input object after processing is correct + // input should be wrapped as Holder type if it is INOUT parameter + Object[] myrtn = (Object[]) inputCtx.getMessageObjects(); + + //FIXME: this does not work for the wrapped doc/lit case due to a bug in Celtix + //assertTrue("input is not Holder type", myrtn[0] instanceof Holder); + } + + // NOTE: For convenience this method presumes the soap service name is + // SOAPService and port name is SoapPort + private CeltixInvoker createCeltixInvoker(String wsdlLocation, + String operationName, + ObjectMessageContextImpl inputCtx) + throws Exception { + + // Make following call to return a mocked SOAPClientBinding: + // bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference) + SOAPClientBinding clientBinding = EasyMock + .createMock(SOAPClientBinding.class); + clientBinding.createObjectContext(); + EasyMock.expectLastCall().andReturn(inputCtx); + clientBinding.invoke(EasyMock.isA(ObjectMessageContextImpl.class), + EasyMock.isA(SCADataBindingCallback.class)); + EasyMock.expectLastCall().andReturn(new ObjectMessageContextImpl()); + EasyMock.replay(clientBinding); + + SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class); + bindingFactory.createClientBinding(EasyMock.isA(EndpointReferenceType.class)); + EasyMock.expectLastCall().andReturn(clientBinding); + EasyMock.replay(bindingFactory); + + BindingManager bindingManager = EasyMock.createNiceMock(BindingManager.class); + String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/"; + bindingManager.getBindingFactory(bindingId); + EasyMock.expectLastCall().andReturn(bindingFactory); + + Bus bus = EasyMock.createNiceMock(Bus.class); + bus.getBindingManager(); + EasyMock.expectLastCall().andReturn(bindingManager); + EasyMock.replay(bindingManager); + EasyMock.replay(bus); + + // Create WSDL Definition + URL url = getClass().getResource(wsdlLocation); + assertNotNull("Could not find wsdl " + url.toString(), url); + + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + InputSource input = new InputSource(url.openStream()); + Definition wsdlDef = reader.readWSDL(url.toString(), input); + QName qName = new QName("http://objectweb.org/hello_world_soap_http", "SOAPService"); + Service wsdlService = wsdlDef.getService(qName); + Port port = wsdlService.getPort("SoapPort"); + + return new CeltixInvoker(operationName, bus, port, wsdlService, wsdlDef, null); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java new file mode 100644 index 0000000000..1a66aa4eb5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java @@ -0,0 +1,129 @@ +/* + * 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.tuscany.binding.celtix; + +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.xml.sax.InputSource; + +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.WireService; + +import junit.framework.TestCase; +import org.easymock.classextension.EasyMock; +import org.objectweb.celtix.Bus; +import org.objectweb.celtix.bindings.BindingManager; +import static org.objectweb.celtix.bindings.DataBindingCallback.Mode.PARTS; +import org.objectweb.celtix.bindings.ServerBindingEndpointCallback; +import org.objectweb.celtix.bindings.ServerDataBindingCallback; +import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory; +import org.objectweb.celtix.bus.bindings.soap.SOAPServerBinding; +import org.objectweb.celtix.context.ObjectMessageContextImpl; +import org.objectweb.celtix.ws.addressing.EndpointReferenceType; + +/** + * @version $Rev$ $Date$ + */ +public class CeltixServiceTestCase extends TestCase { + + public void testGetDataBindingCallback() throws Exception { + CeltixService celtixService = createCeltixService(); + + QName operationName = new QName("greetMe"); + ObjectMessageContextImpl ctx = new ObjectMessageContextImpl(); + ctx.setMessageObjects(new String[]{"Celtix"}); + ServerDataBindingCallback callback1 = celtixService.getDataBindingCallback(operationName, ctx, PARTS); + assertNotNull(callback1); + + callback1.invoke(ctx); + Object rtn = (String) ctx.getReturn(); + assertEquals("Hello Celtix", rtn); + + } + + private CeltixService createCeltixService() throws Exception { + //Make following call to return a mocked SOAPClientBinding: + //bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference) + SOAPServerBinding serverBinding = EasyMock.createMock(SOAPServerBinding.class); + serverBinding.activate(); + EasyMock.replay(serverBinding); + + //ServerBindingEndpointCallback callback = EasyMock.createNiceMock(ServerBindingEndpointCallback.class); + + SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class); + bindingFactory.createServerBinding(EasyMock.isA(EndpointReferenceType.class), + EasyMock.isA(ServerBindingEndpointCallback.class)); + EasyMock.expectLastCall().andReturn(serverBinding); + EasyMock.replay(bindingFactory); + + BindingManager bindingManager = EasyMock.createNiceMock(BindingManager.class); + String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/"; + bindingManager.getBindingFactory(bindingId); + EasyMock.expectLastCall().andReturn(bindingFactory); + + Bus bus = EasyMock.createNiceMock(Bus.class); + bus.getBindingManager(); + EasyMock.expectLastCall().andReturn(bindingManager); + EasyMock.replay(bindingManager); + EasyMock.replay(bus); + + //Create WSDL Definition + String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; + URL url = getClass().getResource(wsdlLocation); + assertNotNull("Could not find wsdl " + url.toString(), url); + + WSDLFactory factory = WSDLFactory.newInstance(); + WSDLReader reader = factory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + InputSource input = new InputSource(url.openStream()); + Definition wsdlDef = reader.readWSDL(url.toString(), input); + Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", + "SOAPService")); + Port port = wsdlService.getPort("SoapPort"); + + WebServiceBinding wsBinding = new WebServiceBinding(wsdlDef, port, "uri", "portURI", wsdlService); + + //Create mocked InboundWire, for ServiceExtension.getInterface() + InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class); + JavaServiceContract contract = new JavaServiceContract(Greeter.class); + EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes(); + EasyMock.replay(inboundWire); + + //Create mocked WireService, for ServiceExtension.getServiceInstance() + WireService wireService = EasyMock.createNiceMock(WireService.class); + wireService.createProxy(EasyMock.isA(InboundWire.class)); + EasyMock.expectLastCall().andReturn(new GreeterImpl()).anyTimes(); + EasyMock.replay(wireService); + + CeltixService celtixService = new CeltixService("name", Greeter.class, null, wireService, wsBinding, bus, null); + //Not sure how InboundWire is set to CeltixService, is the following way correct? + celtixService.setInboundWire(inboundWire); + celtixService.start(); + + return celtixService; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java new file mode 100644 index 0000000000..56de472774 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/Greeter.java @@ -0,0 +1,32 @@ +/* + * 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.tuscany.binding.celtix; + +public interface Greeter { + java.lang.String sayHi(); + + java.lang.String greetMe( + java.lang.String requestType + ); + + void greetMeOneWay( + java.lang.String requestType + ); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java new file mode 100644 index 0000000000..38237ad81a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/GreeterImpl.java @@ -0,0 +1,33 @@ +/* + * 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.tuscany.binding.celtix; + +public class GreeterImpl implements Greeter { + public java.lang.String sayHi() { + return "sayHi"; + } + + public java.lang.String greetMe(String requestType) { + return "Hello " + requestType; + } + + public void greetMeOneWay(String requestType) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world.wsdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world.wsdl new file mode 100644 index 0000000000..e8767988f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world.wsdl @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit.wsdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit.wsdl new file mode 100644 index 0000000000..db625cb129 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit.wsdl @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit_inout.wsdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit_inout.wsdl new file mode 100644 index 0000000000..90634709ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/src/test/resources/wsdl/hello_world_doc_lit_inout.wsdl @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/tuscany-checkstyle.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/tuscany-checkstyle.xml new file mode 100644 index 0000000000..df8a9483d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.celtix/tuscany-checkstyle.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/.ruleset b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/LICENSE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/NOTICE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/pom.xml new file mode 100644 index 0000000000..4fede9927d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/pom.xml @@ -0,0 +1,59 @@ + + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + + 4.0.0 + binding-jsonrpc + Apache Tuscany Binding for JSON-RPC + Implementation of the SCA JSON-RPC Binding + + + + + org.apache.tuscany.sca.kernel + tuscany-spi + ${sca.version} + compile + + + + com.metaparadigm + json-rpc + 1.0 + compile + + + + tomcat + servlet-api + 5.0.18 + provided + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.java new file mode 100644 index 0000000000..101bfde6c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBinding.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 org.apache.tuscany.binding.jsonrpc; + +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a binding to an RMI service. + * + * @version $Rev$ $Date$ + */ +public class JSONRPCBinding extends Binding { + private String uri; + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java new file mode 100644 index 0000000000..85654f1104 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingBuilder.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.binding.jsonrpc; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.model.BoundServiceDefinition; + +/** + * Builds a Service for JSON-RPC binding. + * + * @version $Rev$ $Date$ + */ +public class JSONRPCBindingBuilder extends BindingBuilderExtension { + + private ServletHost servletHost; + + @Autowire() + public void setServletHost(ServletHost servletHost) { + this.servletHost = servletHost; + } + + protected Class getBindingType() { + return JSONRPCBinding.class; + } + + @SuppressWarnings("unchecked") + public Service build(CompositeComponent parent, + BoundServiceDefinition serviceDefinition, + DeploymentContext deploymentContext) { + Class interfaze = serviceDefinition.getServiceContract().getInterfaceClass(); + + return new JSONRPCService(serviceDefinition.getName(), interfaze, parent, wireService, servletHost); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java new file mode 100644 index 0000000000..9f2a35d912 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCBindingLoader.java @@ -0,0 +1,57 @@ +/* + * 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.tuscany.binding.jsonrpc; + +import static org.osoa.sca.Version.XML_NAMESPACE_1_0; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.osoa.sca.annotations.Scope; + +/** + * Loader for handling elements. + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JSONRPCBindingLoader extends LoaderExtension { + public static final QName BINDING_JSON = new QName(XML_NAMESPACE_1_0, "binding.jsonrpc"); + + public JSONRPCBindingLoader(@Autowire + LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return BINDING_JSON; + } + + public JSONRPCBinding load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext) throws XMLStreamException, + LoaderException { + + return new JSONRPCBinding(); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java new file mode 100644 index 0000000000..c7afc4742e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCEntryPointServlet.java @@ -0,0 +1,71 @@ +/* + * 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.tuscany.binding.jsonrpc; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import com.metaparadigm.jsonrpc.JSONRPCBridge; +import com.metaparadigm.jsonrpc.JSONRPCServlet; + +/** + * + * + */ +public class JSONRPCEntryPointServlet extends JSONRPCServlet { + private static final long serialVersionUID = 1L; + + String serviceName; + + Object serviceInstance; + + public JSONRPCEntryPointServlet(String serviceName, Object serviceInstance) { + this.serviceName = serviceName; + this.serviceInstance = serviceInstance; + + } + + /* + * (non-Javadoc) + * + * @see com.metaparadigm.jsonrpc.JSONRPCServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ClassCastException { + + /* + * Create a new bridge for every request to aviod all the problems with JSON-RPC-Java storing the bridge in the session + */ + HttpSession session = request.getSession(); + try { + + JSONRPCBridge jsonrpcBridge = new JSONRPCBridge(); + jsonrpcBridge.registerObject(serviceName, serviceInstance); + session.setAttribute("JSONRPCBridge", jsonrpcBridge); + + super.service(request, response); + + } finally { + session.removeAttribute("JSONRPCBridge"); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java new file mode 100644 index 0000000000..58d1d087ac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/JSONRPCService.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.binding.jsonrpc; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.wire.WireService; +import org.osoa.sca.annotations.Destroy; + +/** + * @version $Rev$ $Date$ + */ +public class JSONRPCService extends ServiceExtension { + private ServletHost servletHost; + + public JSONRPCService(String theName, Class interfaze, CompositeComponent parent, WireService wireService, ServletHost servletHost) { + + super(theName, interfaze, parent, wireService); + + this.servletHost = servletHost; + } + + public void start() { + super.start(); + + JSONRPCEntryPointServlet servlet = new JSONRPCEntryPointServlet(getName(), this.getServiceInstance()); + servletHost.registerMapping("/" + getName(), servlet); + servletHost.registerMapping("/SCA/scripts", new ScriptGetterServlet()); + } + + @Destroy + public void stop() { + servletHost.unregisterMapping("/" + getName()); + servletHost.unregisterMapping("/SCA/scripts"); + + super.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServlet.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServlet.java new file mode 100644 index 0000000000..8f8a96df20 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/java/org/apache/tuscany/binding/jsonrpc/ScriptGetterServlet.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 org.apache.tuscany.binding.jsonrpc; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ScriptGetterServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + // private static final String SCA_INIT_JS = "SCA = new JSONRpcClient(\"services/HelloWorldService\");"; + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + URL url = getClass().getResource("jsonrpc.js"); + InputStream is = url.openStream(); + writeToStream(response, is); + + // writeToStream(response, new ByteArrayInputStream(SCA_INIT_JS.getBytes())); + } + + private void writeToStream(HttpServletResponse response, InputStream is) throws IOException { + ServletOutputStream os = response.getOutputStream(); + int i; + while ((i = is.read()) != -1) { // NOPMD + os.write(i); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/binding.jsonrpc.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/binding.jsonrpc.scdl new file mode 100644 index 0000000000..4081d437c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/binding.jsonrpc.scdl @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..aec9bb440b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,43 @@ + + + + + + + com.metaparadigm + json-rpc + 1.0 + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/jsonrpc_extension.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/jsonrpc_extension.scdl new file mode 100644 index 0000000000..4081d437c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/META-INF/sca/jsonrpc_extension.scdl @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/org/apache/tuscany/binding/jsonrpc/jsonrpc.js b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/org/apache/tuscany/binding/jsonrpc/jsonrpc.js new file mode 100644 index 0000000000..2b9efbb55c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.jsonrpc/src/main/resources/org/apache/tuscany/binding/jsonrpc/jsonrpc.js @@ -0,0 +1,484 @@ +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * Licensed 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. + * + */ + + +/* escape a character */ + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/.ruleset b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/LICENSE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/NOTICE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/pom.xml new file mode 100755 index 0000000000..31ef8047d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/pom.xml @@ -0,0 +1,63 @@ + + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + + 4.0.0 + rmi + Apache Tuscany Binding for Java RMI + Implementation of the SCA RMI Binding + + + + cglib + cglib-nodep + 2.1_3 + compile + + + org.apache.tuscany.sca.kernel + tuscany-spi + ${sca.version} + compile + + + org.apache.tuscany.sca + test + ${sca.version} + test + + + org.easymock + easymock + + + org.easymock + easymockclassextension + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java new file mode 100644 index 0000000000..45404f087e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +/** + * @version $Rev$ $Date$ + */ +public class NoRemoteMethodException extends RMIRuntimeException { + public NoRemoteMethodException() { + } + + public NoRemoteMethodException(String message) { + super(message); + } + + public NoRemoteMethodException(String message, Throwable cause) { + super(message, cause); + } + + public NoRemoteMethodException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java new file mode 100644 index 0000000000..af2d2fd582 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +/** + * @version $Rev$ $Date$ + */ +public class NoRemoteServiceException extends RMIRuntimeException { + public NoRemoteServiceException() { + } + + public NoRemoteServiceException(String message) { + super(message); + } + + public NoRemoteServiceException(String message, Throwable cause) { + super(message, cause); + } + + public NoRemoteServiceException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java new file mode 100644 index 0000000000..bc8c69851e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java @@ -0,0 +1,57 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a binding to an RMI service. + * + * @version $Rev$ $Date$ + */ +public class RMIBinding extends Binding { + private String host; + + private String port; + + private String serviceName; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java new file mode 100644 index 0000000000..1e2eb9633a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java @@ -0,0 +1,78 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import java.rmi.Remote; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; +import org.osoa.sca.annotations.Constructor; + +/** + * Builds a Service or Reference for an RMI binding. + * + * @version $Rev$ $Date$ + */ + +public class RMIBindingBuilder extends BindingBuilderExtension { + + private RMIHost rmiHost; + + @Constructor({"rmiHost"}) + public RMIBindingBuilder(@Autowire RMIHost rHost) { + this.rmiHost = rHost; + } + + protected Class getBindingType() { + return RMIBinding.class; + } + + @SuppressWarnings({"unchecked"}) + public Service build(CompositeComponent parent, + BoundServiceDefinition boundServiceDefinition, + DeploymentContext deploymentContext) { + + Class intf = boundServiceDefinition.getServiceContract().getInterfaceClass(); + + return new RMIService(boundServiceDefinition.getName(), parent, wireService, rmiHost, + boundServiceDefinition.getBinding().getHost(), boundServiceDefinition.getBinding().getPort(), + boundServiceDefinition.getBinding().getServiceName(), intf); + } + + @SuppressWarnings({"unchecked"}) + public Reference build(CompositeComponent parent, + BoundReferenceDefinition boundReferenceDefinition, + DeploymentContext deploymentContext) { + String name = boundReferenceDefinition.getName(); + String host = boundReferenceDefinition.getBinding().getHost(); + String port = boundReferenceDefinition.getBinding().getPort(); + String svcName = boundReferenceDefinition.getBinding().getServiceName(); + // Class interfaze = boundReferenceDefinition.getServiceContract().getInterfaceClass(); + + return new RMIReference(name, parent, wireService, rmiHost, host, port, svcName, + boundReferenceDefinition.getServiceContract().getInterfaceClass()); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java new file mode 100755 index 0000000000..bd9b165b6d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java @@ -0,0 +1,64 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.osoa.sca.annotations.Scope; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; + +/** + * Loader for handling elements. + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class RMIBindingLoader extends LoaderExtension { + public static final QName BINDING_RMI = new QName( + "http://incubator.apache.org/tuscany/xmlns/binding/rmi/1.0-incubator-M2", "binding.rmi"); + + public RMIBindingLoader(@Autowire LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return BINDING_RMI; + } + + public RMIBinding load(CompositeComponent parent, + XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + String host = reader.getAttributeValue(null, "host"); + String port = reader.getAttributeValue(null, "port"); + String svcName = reader.getAttributeValue(null, "serviceName"); + LoaderUtil.skipToEndElement(reader); + RMIBinding binding = new RMIBinding(); + binding.setHost(host); + binding.setPort(port); + binding.setServiceName(svcName); + return binding; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java new file mode 100644 index 0000000000..afd1992d20 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java @@ -0,0 +1,66 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.spi.extension.TargetInvokerExtension; + +/** + * Invoke an RMI reference. + * + * @version $Rev$ $Date$ + */ +public class RMIInvoker extends TargetInvokerExtension { + private Method remoteMethod; + private String host; + private String port; + private String svcName; + private RMIHost rmiHost; + private Remote proxy; + + public RMIInvoker(RMIHost rmiHost, String host, String port, String svcName, Method remoteMethod) { + // assert remoteMethod.isAccessible(); + this.remoteMethod = remoteMethod; + this.host = host; + this.port = port; + this.svcName = svcName; + this.rmiHost = rmiHost; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + try { + if (proxy == null) { + proxy = rmiHost.findService(host, port, svcName); + // proxy = Naming.lookup(serviceURI); + } + return remoteMethod.invoke(proxy, (Object[]) payload); + } catch (RMIHostException e) { + // the method we are passed must be accessible + throw new AssertionError(e); + } catch (IllegalAccessException e) { + // the method we are passed must be accessible + throw new AssertionError(e); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java new file mode 100644 index 0000000000..5e810892d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java @@ -0,0 +1,87 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod; + +import java.lang.reflect.Method; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ReferenceExtension; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; + +import org.apache.tuscany.host.rmi.RMIHost; + +/** + * @version $Rev$ $Date$ + */ +public class RMIReference extends ReferenceExtension { + private final String host; + + private final String port; + + private final String svcName; + + private RMIHost rmiHost; + + public RMIReference(String name, + CompositeComponent parent, + WireService wireService, + RMIHost rmiHost, + String host, + String port, + String svcName, + Class service) { + super(name, service, parent, wireService); + this.host = host; + this.port = port; + this.svcName = svcName; + this.rmiHost = rmiHost; + } + + public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { + try { + /*Remote proxy = getProxy(); + Method remoteMethod = proxy.getClass().getMethod(operation.getName(), + (Class[]) operation.getParameterTypes()); + return new RMIInvoker(proxy, remoteMethod); + */ + Method method = findMethod(operation, contract.getInterfaceClass().getMethods()); + Method remoteMethod = + getInterface().getMethod(operation.getName(), (Class[]) method.getParameterTypes()); + return new RMIInvoker(rmiHost, host, port, svcName, remoteMethod); + } catch (NoSuchMethodException e) { + throw new NoRemoteMethodException(operation.toString(), e); + } + } + + /*protected Remote getProxy() { + try { + // todo do we need to cache this result? + return Naming.lookup(uri); + } catch (NotBoundException e) { + throw new NoRemoteServiceException(uri); + } catch (MalformedURLException e) { + throw new NoRemoteServiceException(uri); + } catch (RemoteException e) { + throw new NoRemoteServiceException(uri); + } + }*/ +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java new file mode 100644 index 0000000000..c36dec4531 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public abstract class RMIRuntimeException extends TuscanyRuntimeException { + protected RMIRuntimeException() { + } + + protected RMIRuntimeException(String message) { + super(message); + } + + protected RMIRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + protected RMIRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java new file mode 100644 index 0000000000..0de833801f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java @@ -0,0 +1,160 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.server.UnicastRemoteObject; + +import net.sf.cglib.asm.ClassWriter; +import net.sf.cglib.asm.Constants; +import net.sf.cglib.asm.Type; +import net.sf.cglib.proxy.Enhancer; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.wire.WireService; + +/** + * @version $Rev$ $Date$ + */ +public class RMIService extends ServiceExtension { + + public static final String URI_PREFIX = "//localhost"; + public static final String SLASH = "/"; + public static final String COLON = ":"; + //private final String host; + private final String port; + private final String serviceName; + private RMIHost rmiHost; + + // need this member to morph the service interface to extend from Remote if it does not + // the base class's member variable interfaze is to be maintained to enable the connection + // of the service outbound to the component's inbound wire which requires that the service + // and the component match in their service contracts. + private Class serviceInterface; + + public RMIService(String name, + CompositeComponent parent, + WireService wireService, + RMIHost rHost, + String host, + String port, + String svcName, + Class service) { + super(name, service, parent, wireService); + + this.serviceInterface = service; + this.rmiHost = rHost; + //this.host = host; + this.port = port; + this.serviceName = svcName; + } + + public void start() { + super.start(); + Remote rmiProxy = createRmiService(); + + try { + // startRMIRegistry(); + rmiHost.registerService(serviceName, + getPort(port), + rmiProxy); + // bindRmiService(uri,rmiProxy); + } catch (RMIHostException e) { + throw new NoRemoteServiceException(e); + } + } + + public void stop() { + try { + rmiHost.unregisterService(serviceName, getPort(port)); + } catch (RMIHostException e) { + throw new NoRemoteServiceException(e.getMessage()); + } + super.stop(); + } + + protected Remote createRmiService() { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(UnicastRemoteObject.class); + enhancer.setCallback(new RemoteMethodHandler(getHandler(), interfaze)); + + if (!Remote.class.isAssignableFrom(serviceInterface)) { + RMIServiceClassLoader classloader = + new RMIServiceClassLoader(getClass().getClassLoader()); + final byte[] byteCode = generateRemoteInterface(serviceInterface); + serviceInterface = classloader.defineClass(byteCode); + enhancer.setClassLoader(classloader); + } + enhancer.setInterfaces(new Class[]{serviceInterface}); + return (Remote) enhancer.create(); + } + + protected int getPort(String port) { + int portNumber = RMIHost.RMI_DEFAULT_PORT; + if (port != null && port.length() > 0) { + portNumber = Integer.decode(port); + } + + return portNumber; + } + + // if the interface of the component whose services must be exposed as RMI Service, does not + // implement java.rmi.Remote, then generate such an interface. This method will stop with + // just generating the bytecode. Defining the class from the byte code must tbe the responsibility + // of the caller of this method, since it requires a classloader to be created to define and load + // this interface. + protected byte[] generateRemoteInterface(Class serviceInterface) { + String interfazeName = serviceInterface.getCanonicalName(); + ClassWriter cw = new ClassWriter(false); + + String simpleName = serviceInterface.getSimpleName(); + cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE, + interfazeName.replace('.', '/'), "java/lang/Object", new String[]{"java/rmi/Remote"}, simpleName + ".java"); + + StringBuffer argsAndReturn = null; + Method[] methods = serviceInterface.getMethods(); + for (Method method : methods) { + argsAndReturn = new StringBuffer("("); + Class[] paramTypes = method.getParameterTypes(); + Class returnType = method.getReturnType(); + + for (Class paramType : paramTypes) { + argsAndReturn.append(Type.getType(paramType)); + } + argsAndReturn.append(")"); + argsAndReturn.append(Type.getType(returnType)); + + cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT, method.getName(), argsAndReturn.toString(), + new String[]{"java/rmi/RemoteException"}, null); + } + cw.visitEnd(); + return cw.toByteArray(); + } + + private class RMIServiceClassLoader extends ClassLoader { + public RMIServiceClassLoader(ClassLoader parent) { + super(parent); + } + public Class defineClass(byte[] byteArray) { + return defineClass(null, byteArray, 0, byteArray.length); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RemoteMethodHandler.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RemoteMethodHandler.java new file mode 100644 index 0000000000..b27c87b510 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RemoteMethodHandler.java @@ -0,0 +1,47 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import java.lang.reflect.Method; + +import org.apache.tuscany.spi.wire.WireInvocationHandler; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +public class RemoteMethodHandler implements MethodInterceptor { + public static final String FINALIZE_METHOD = "finalize"; + + private WireInvocationHandler wireHandler; + + private Class compSvcIntf; + + public RemoteMethodHandler(WireInvocationHandler handler, Class intf) { + this.wireHandler = handler; + compSvcIntf = intf; + } + + public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + // since incoming method signatures have 'remotemethod invocation' it will not match with the + // wired component's method signatures. Hence need to pull in the corresponding method from the + // component's service contract interface to make this invocation. + return wireHandler.invoke(compSvcIntf.getMethod(method.getName(), + (Class[]) method.getParameterTypes()), + args); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/host/RMIHostImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/host/RMIHostImpl.java new file mode 100644 index 0000000000..9355cf642e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/host/RMIHostImpl.java @@ -0,0 +1,136 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi.host; + +import java.rmi.AlreadyBoundException; +import java.rmi.NotBoundException; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * This class provides an implementation for the RMI Host SPIs + */ +@Scope("MODULE") +public class RMIHostImpl implements RMIHost { + + // map of RMI registries started and running + private Map rmiRegistries; + + public RMIHostImpl() { + rmiRegistries = new ConcurrentHashMap(); + /* + * if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } + */ + } + + @Init(eager = true) + public void init() { + } + + public void registerService(String serviceName, int port, Remote serviceObject) throws RMIHostException, + RMIHostRuntimeException { + Registry registry; + try { + registry = rmiRegistries.get(Integer.toString(port)); + if (registry == null) { + registry = LocateRegistry.createRegistry(port); + rmiRegistries.put(Integer.toString(port), + registry); + } + registry.bind(serviceName, + serviceObject); + } catch (AlreadyBoundException e) { + throw new RMIHostException(e.getMessage()); + } catch (RemoteException e) { + RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage()); + rmiExec.setStackTrace(e.getStackTrace()); + throw rmiExec; + } + + } + + public void registerService(String serviceName, Remote serviceObject) throws RMIHostException, + RMIHostRuntimeException { + registerService(serviceName, + RMI_DEFAULT_PORT, + serviceObject); + } + + public void unregisterService(String serviceName, int port) throws RMIHostException, + RMIHostRuntimeException { + Registry registry; + + try { + registry = rmiRegistries.get(Integer.toString(port)); + if (registry == null) { + registry = LocateRegistry.createRegistry(port); + rmiRegistries.put(Integer.toString(port), + registry); + } + registry.unbind(serviceName); + } catch (RemoteException e) { + RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage()); + rmiExec.setStackTrace(e.getStackTrace()); + throw rmiExec; + } catch (NotBoundException e) { + throw new RMIHostException(e.getMessage()); + } + } + + public void unregisterService(String serviceName) throws RMIHostException, + RMIHostRuntimeException { + unregisterService(serviceName, + RMI_DEFAULT_PORT); + + } + + public Remote findService(String host, String port, String svcName) throws RMIHostException, + RMIHostRuntimeException { + Registry registry; + Remote remoteService = null; + host = (host == null || host.length() <= 0) ? "localhost" : host; + int portNumber = (port == null || port.length() <= 0) ? RMI_DEFAULT_PORT : Integer + .decode(port); + + try { + registry = LocateRegistry.getRegistry(host, + portNumber); + + if (registry != null) { + remoteService = registry.lookup(svcName); + } + } catch (RemoteException e) { + RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage()); + rmiExec.setStackTrace(e.getStackTrace()); + throw rmiExec; + } catch (NotBoundException e) { + throw new RMIHostException(e.getMessage()); + } + return remoteService; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..61d6523472 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,55 @@ + + + + + + + + org.apache.tuscany.sca.services.bindings + rmi + 1.0-incubator-M2-SNAPSHOT + + + + org.apache.tuscany.sca.kernel + tuscany-api + 1.0-incubator-M2-SNAPSHOT + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/rmi_extension.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/rmi_extension.scdl new file mode 100644 index 0000000000..9417a1d5ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/main/resources/META-INF/sca/rmi_extension.scdl @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..ef17df1e9d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldImpl.java @@ -0,0 +1,32 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String sayHello(String name) { + return "Hello from the RMI Service to - " + name; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiImpl.java new file mode 100644 index 0000000000..a63d8d162c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiImpl.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 helloworld; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldRmiService.class) +public class HelloWorldRmiImpl implements HelloWorldRmiService { + @Reference + private HelloWorldService extService; + + public HelloWorldService getExtService() { + return extService; + } + + @Reference + public void setExtService(HelloWorldService extService) { + this.extService = extService; + } + + public String sayRmiHello(String name) { + return extService.sayHello(name) + " thro the RMI Reference"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiService.java new file mode 100644 index 0000000000..b6b99f45e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldRmiService.java @@ -0,0 +1,28 @@ +/* + * 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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldRmiService { + + String sayRmiHello(String name); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..25f2b1da31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/helloworld/HelloWorldService.java @@ -0,0 +1,28 @@ +/* + * 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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldService { + + String sayHello(String name); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java new file mode 100644 index 0000000000..7ebee2af66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.binding.rmi; + +import helloworld.HelloWorldRmiService; + +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +// TODO: renamed to XXX as it doesn't work for me +public class BindingTestCase extends SCATestCase { + private HelloWorldRmiService helloWorldRmiService; + + public void testRmiService() { + System.out.println(helloWorldRmiService.sayRmiHello("Tuscany World!")); + assertEquals("Hello from the RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHello("Tuscany World!")); + } + + protected void setUp() throws Exception { + addExtension("rmi.binding", + getClass().getClassLoader().getResource("META-INF/sca/rmi_extension.scdl")); + setApplicationSCDL(getClass().getClassLoader().getResource("META-INF/sca/default.scdl")); + + super.setUp(); + + CompositeContext context = CurrentCompositeContext.getContext(); + helloWorldRmiService = context.locateService(HelloWorldRmiService.class, + "HelloWorldRmiServiceComponent"); + } + + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java new file mode 100644 index 0000000000..cb4911a0a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class NoRemoteMethodExceptionTestCase extends TestCase { + + public void testNoArgs() { + assertNotNull(new NoRemoteMethodException()); + } + + public void testMsgArg() { + NoRemoteMethodException e = new NoRemoteMethodException("foo"); + assertEquals("foo", e.getMessage()); + } + + public void test2Args() { + Exception cause = new Exception(); + NoRemoteMethodException e = new NoRemoteMethodException("foo", cause); + assertEquals("foo", e.getMessage()); + assertEquals(cause, e.getCause()); + } + + public void testCauseArgs() { + Exception cause = new Exception(); + NoRemoteMethodException e = new NoRemoteMethodException(cause); + assertEquals(cause, e.getCause()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java new file mode 100644 index 0000000000..a5da001ad9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class NoRemoteServiceExceptionTestCase extends TestCase { + + public void testNoArgs() { + assertNotNull(new NoRemoteServiceException()); + } + + public void testMsgArg() { + NoRemoteServiceException e = new NoRemoteServiceException("foo"); + assertEquals("foo", e.getMessage()); + } + + public void test2Args() { + Exception cause = new Exception(); + NoRemoteServiceException e = new NoRemoteServiceException("foo", cause); + assertEquals("foo", e.getMessage()); + assertEquals(cause, e.getCause()); + } + + public void testCauseArgs() { + Exception cause = new Exception(); + NoRemoteServiceException e = new NoRemoteServiceException(cause); + assertEquals(cause, e.getCause()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java new file mode 100644 index 0000000000..b74be6d78b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceContract; + +public class RMIBindingBuilderTestCase extends TestCase { + + public void testGetBindingType() { + assertEquals(RMIBinding.class, new RMIBindingBuilder(null).getBindingType()); + } + + @SuppressWarnings("unchecked") + public void testBuildService() { + RMIBindingBuilder builder = new RMIBindingBuilder(null); + BoundReferenceDefinition def = createMock(BoundReferenceDefinition.class); + expect(def.getName()).andReturn("petra"); + RMIBinding binding = new RMIBinding(); + expect(def.getBinding()).andReturn(binding ); + expect(def.getBinding()).andReturn(binding ); + expect(def.getBinding()).andReturn(binding ); + ServiceContract sc = createMock(ServiceContract.class); + expect(def.getServiceContract()).andReturn(sc); + replay(def); + Object ref = builder.build(null, def, null); + assertTrue(ref instanceof RMIReference); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java new file mode 100644 index 0000000000..160ca19b8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java @@ -0,0 +1,74 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; + +public class RMIBindingLoaderTestCase extends TestCase { + private CompositeComponent parent; + + private XMLStreamReader reader; + + private DeploymentContext deploymentContext; + + private LoaderRegistry registry; + + private RMIBindingLoader loader; + + public void testLoad() throws LoaderException, XMLStreamException { + expect(reader.getAttributeValue(null, "host")).andReturn("host"); + expect(reader.getAttributeValue(null, "port")).andReturn("0"); + expect(reader.getAttributeValue(null, "serviceName")).andReturn("servicename"); + expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); + + replay(reader); + replay(deploymentContext); + + RMIBindingLoader mockLoader = new RMIBindingLoader(registry); + mockLoader.load(parent, reader, deploymentContext); + verify(reader); + verify(deploymentContext); + } + + public void testGetXMLType() throws LoaderException { + assertEquals(RMIBindingLoader.BINDING_RMI, loader.getXMLType()); + } + + protected void setUp() throws Exception { + super.setUp(); + registry = createMock(LoaderRegistry.class); + loader = new RMIBindingLoader(registry); + + parent = createMock(CompositeComponent.class); + reader = createMock(XMLStreamReader.class); + deploymentContext = createMock(DeploymentContext.class); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java new file mode 100644 index 0000000000..6dbb81437f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class RMIBindingTestCase extends TestCase { + + public void testHost() { + RMIBinding binding = new RMIBinding(); + binding.setHost("foo"); + assertEquals("foo", binding.getHost()); + } + + public void testPort() { + RMIBinding binding = new RMIBinding(); + binding.setPort("foo"); + assertEquals("foo", binding.getPort()); + } + + public void testServiceName() { + RMIBinding binding = new RMIBinding(); + binding.setServiceName("foo"); + assertEquals("foo", binding.getServiceName()); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java new file mode 100644 index 0000000000..72c0acacc4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java @@ -0,0 +1,84 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; + +import junit.framework.TestCase; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; + +public class RMIInvokerTestCase extends TestCase { + + public void testInvokeTarget() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, IllegalArgumentException, + IllegalAccessException, SecurityException, NoSuchMethodException { + Method method = Object.class.getDeclaredMethod("toString", new Class[] {}); + RMIHost host = createMock(RMIHost.class); + expect(host.findService(null, null, null)).andReturn(new Remote() { + }); + replay(host); + RMIInvoker invoker = new RMIInvoker(host, null, null, null, method); + assertNotNull(invoker.invokeTarget(new Object[] {})); + } + +// TODO: these don't seem to work +// public void testInvokeTargetRMIHostException() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, +// IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchMethodException { +// Method method = foo.class.getDeclaredMethod("bang", new Class[] {}); +// RMIHost host = createMock(RMIHost.class); +// expect(host.findService(null, null, null)).andReturn(new foo()); +// replay(host); +// try { +// new RMIInvoker(host, null, null, null, method).invokeTarget(new Object[] {}); +// fail(); +// } catch (InvocationTargetException e) { +// // expected +// } +// } +// +// public void testInvokeTargetIllegalAccessException() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, +// IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchMethodException { +// Method method = foo.class.getDeclaredMethod("crash", new Class[] {}); +// RMIHost host = createMock(RMIHost.class); +// expect(host.findService(null, null, null)).andReturn(new foo()); +// replay(host); +// try { +// new RMIInvoker(host, null, null, null, method).invokeTarget(new Object[] {}); +// fail(); +// } catch (InvocationTargetException e) { +// // expected +// } +// } +// +// class foo implements Remote { +// void crash() throws IllegalAccessException { +// throw new IllegalAccessException(); +// } +// +// void bang() throws RMIHostException { +// throw new RMIHostException(); +// } +// } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java new file mode 100644 index 0000000000..5c935ec38a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; + +public class RMIReferenceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testCreateTargetInvoker() { + // TODO: this doesn't really test anything yet + RMIReference ref = new RMIReference(null, null, null, null, null, null, null, null); + ServiceContract contract = new JavaServiceContract(); + contract.setInterfaceClass(String.class); + List l = new ArrayList(); + l.add(new DataType(null, null)); + DataType in = new DataType(null, l); + Operation operation = new Operation(null, in, null, null); + try { + ref.createTargetInvoker(contract, operation); + } catch (Exception e) { + // expected + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java new file mode 100644 index 0000000000..1386cf2c72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import junit.framework.TestCase; + +import org.apache.tuscany.binding.rmi.host.RMIHostImpl; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; +import org.apache.tuscany.spi.wire.WireInvocationHandler; + +public class RMIServiceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testGetPort() { + RMIService s = new RMIService(null, null, null, null, null, null, null, null); + assertEquals(0, s.getPort("0")); + } + + @SuppressWarnings("unchecked") + public void testGenerateRemoteInterface() { + RMIService s = new RMIService("foo27", null, null, null, null, null, null, null); + s.generateRemoteInterface(Runnable.class); + } + + @SuppressWarnings("unchecked") + public void testCreateRmiService() { + RMIService s = new RMIService("bla023", null, null, new RMIHostImpl(), null, "9996", "bla", Runnable.class) { + public WireInvocationHandler getHandler() { + return null; + } + }; + s.start(); + try { + s.stop(); + } catch (RMIHostRuntimeException e) { + // expected + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java new file mode 100644 index 0000000000..f5c9595aa3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; + +import java.lang.reflect.Method; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.wire.WireInvocationHandler; + +public class RemoteMethodHandlerTestCase extends TestCase { + + public void testIntercept() throws SecurityException, NoSuchMethodException, Throwable { + WireInvocationHandler h2 = createMock(WireInvocationHandler.class); + Method method = Runnable.class.getDeclaredMethod("run", new Class[]{}); + Object[] noArgs = new Object[]{}; + expect(h2.invoke(method, noArgs)).andReturn("foo"); + replay(h2); + RemoteMethodHandler handler = new RemoteMethodHandler(h2, Runnable.class); + Object o = handler.intercept(null, method, noArgs, null); + assertEquals("foo", o); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java new file mode 100644 index 0000000000..08f6172f3d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java @@ -0,0 +1,76 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.tuscany.binding.rmi.host; + +import java.rmi.Remote; + +import junit.framework.TestCase; + +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; + +public class RMIHostImplTestCase extends TestCase { + + public void testInit() { + new RMIHostImpl().init(); + } + + public void testFindServiceBadHost() throws RMIHostRuntimeException, RMIHostException { + try { + new RMIHostImpl().findService(null, "0", null); + fail(); + } catch (RMIHostRuntimeException e) { + // expected + } + } + + public void testRegisterService1() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("foo1", new MockRemote()); + host.unregisterService("foo1"); + } + + public void testRegisterService2() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("bar1", 9999, new MockRemote()); + host.unregisterService("bar1", 9999); + } + + public void testRegisterServiceAlreadyBound() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("bar2", 9997, new MockRemote()); + try { + host.registerService("bar2", 9997, new MockRemote()); + } catch (RMIHostException e) { + // expected + host.unregisterService("bar2", 9997); + } + } + + public void testUnRegisterService() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + try { + host.unregisterService("bar3", 9998); + fail(); + } catch (RMIHostException e) { + // expected + } + } + + private static class MockRemote implements Remote { + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldImpl.componentType b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldImpl.componentType new file mode 100644 index 0000000000..a0beb4403d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldImpl.componentType @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldRmiImpl.componentType b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldRmiImpl.componentType new file mode 100644 index 0000000000..b0e0b007a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/HelloWorldRmiImpl.componentType @@ -0,0 +1,29 @@ + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/LICENSE.txt b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000000..25d78feeac --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/LICENSE.txt @@ -0,0 +1,1277 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + +APACHE TUSCANY SUBCOMPONENTS: + +The Apache Tuscany distribution includes a number of subcomponents with +separate copyright notices and license terms. Your use of the source +code for the these subcomponents is subject to the terms and +conditions of the following licenses. + +=============================================================================== + +For the Eclipse Modeling Framework component and the Celtix binding: + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF +THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: + +i) changes to the Program, and + +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and +are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program by such +Contributor itself or anyone acting on such Contributor's behalf. +Contributions do not include additions to the Program which: (i) are +separate modules of software distributed in conjunction with the +Program under their own license agreement, and (ii) are not derivative +works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution of such +Contributor, if any, and such derivative works, in source code and +object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, if +any, in source code and object code form. This patent license shall +apply to the combination of the Contribution and the Program if, at +the time the Contribution is added by the Contributor, such addition +of the Contribution causes such combination to be covered by the +Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder. + +c) Recipient understands that although each Contributor grants the +licenses to its Contributions set forth herein, no assurances are +provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility +to secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow +Recipient to distribute the Program, it is Recipient's responsibility +to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form +under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and + +b) its license agreement: + +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose; + +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental and +consequential damages, such as lost profits; + +iii) states that any provisions which differ from this Agreement are +offered by that Contributor alone and not by any other party; and + +iv) states that source code for the Program is available from such +Contributor, and informs licensees how to obtain it in a reasonable +manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and + +b) a copy of this Agreement must be included with each copy of the +Program. + +Contributors may not remove or alter any copyright notices contained +within the Program. + +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use +of the Program, the Contributor who includes the Program in a +commercial product offering should do so in a manner which does not +create potential liability for other Contributors. Therefore, if a +Contributor includes the Program in a commercial product offering, +such Contributor ("Commercial Contributor") hereby agrees to defend +and indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") arising +from claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the acts +or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. +In order to qualify, an Indemnified Contributor must: a) promptly +notify the Commercial Contributor in writing of such claim, and b) +allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such +claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY +WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable +laws, damage to or loss of data, programs or equipment, and +unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR +ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that +the Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of +the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and +survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign +the responsibility to serve as the Agreement Steward to a suitable +separate entity. Each new version of the Agreement will be given a +distinguishing version number. The Program (including Contributions) +may always be distributed subject to the version of the Agreement +under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor +under this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No +party to this Agreement will bring a legal action under this Agreement +more than one year after the cause of action arose. Each party waives +its rights to a jury trial in any resulting litigation. + +=============================================================================== + +For the Rhino JavaScript container component: + +Mozilla Public License 1.1 (MPL 1.1) + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the +Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to +the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original Code, +prior Modifications used by a Contributor, and the Modifications made by that +particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the +combination of the Original Code and Modifications, in each case including +portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally +accepted in the software development community for the electronic transfer of +data. + + 1.5. "Executable" means Covered Code in any form other than Source +Code. + + 1.6. "Initial Developer" means the individual or entity identified as +the Initial Developer in the Source Code notice required by Exhibit A. + + 1.7. "Larger Work" means a work which combines Covered Code or +portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum +extent possible, whether at the time of the initial grant or subsequently +acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the +substance or structure of either the Original Code or any previous +Modifications. When Covered Code is released as a series of files, a +Modification is: + A. Any addition to or deletion from the contents of a file +containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or +previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code +which is described in the Source Code notice required by Exhibit A as Original +Code, and which, at the time of its release under this License is not already +Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or +hereafter acquired, including without limitation, method, process, and +apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for +making modifications to it, including all modules it contains, plus any +associated interface definition files, scripts used to control compilation and +installation of an Executable, or source code differential comparisons against +either the Original Code or another well known, available Covered Code of the +Contributor's choice. The Source Code can be in a compressed or archival form, +provided the appropriate decompression or de-archiving software is widely +available for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity +exercising rights under, and complying with all of the terms of, this License +or a future version of this License issued under Section 6.1. For legal +entities, "You" includes any entity which controls, is controlled by, or is +under common control with You. For purposes of this definition, "control" +means (a) the power, direct or indirect, to cause the direction or management +of such entity, whether by contract or otherwise, or (b) ownership of more +than fifty percent (50%) of the outstanding shares or beneficial ownership of +such entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, +non-exclusive license, subject to third party intellectual property claims: + (a) under intellectual property rights (other than patent or +trademark) Licensable by Initial Developer to use, reproduce, modify, display, +perform, sublicense and distribute the Original Code (or portions thereof) +with or without Modifications, and/or as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or selling +of Original Code, to make, have made, use, practice, sell, and offer for sale, +and/or otherwise dispose of the Original Code (or portions thereof). + (c) the licenses granted in this Section 2.1(a) and +(b) are effective on the date Initial Developer first distributes Original +Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is +granted: 1) for code that You delete from the Original Code; 2) separate from +the Original Code; or 3) for infringements caused by: i) the modification of +the Original Code or ii) the combination of the Original Code with other +software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor +hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or +trademark) Licensable by Contributor, to use, reproduce, modify, display, +perform, sublicense and distribute the Modifications created by such +Contributor (or portions thereof) either on an unmodified basis, with other +Modifications, as Covered Code and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or selling +of Modifications made by that Contributor either alone and/or in combination +with its Contributor Version (or portions of such combination), to make, use, +sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications +made by that Contributor (or portions thereof); and 2) the combination of +Modifications made by that Contributor with its Contributor Version (or +portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are +effective on the date Contributor first makes Commercial Use of the Covered +Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is +granted: 1) for any code that Contributor has deleted from the Contributor +Version; 2) separate from the Contributor Version; 3) for infringements +caused by: i) third party modifications of Contributor Version or ii) the +combination of Modifications made by that Contributor with other software +(except as part of the Contributor Version) or other devices; or 4) under +Patent Claims infringed by Covered Code in the absence of Modifications made +by that Contributor. + + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are +governed by the terms of this License, including without limitation Section +2.2. The Source Code version of Covered Code may be distributed only under the +terms of this License or a future version of this License released under +Section 6.1, and You must include a copy of this License with every copy of +the Source Code You distribute. You may not offer or impose any terms on any +Source Code version that alters or restricts the applicable version of this +License or the recipients' rights hereunder. However, You may include an +additional document offering the additional rights described in Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be +made available in Source Code form under the terms of this License either on +the same media as an Executable version or via an accepted Electronic +Distribution Mechanism to anyone to whom you made an Executable version +available; and if made available via Electronic Distribution Mechanism, must +remain available for at least twelve (12) months after the date it initially +became available, or at least six (6) months after a subsequent version of +that particular Modification has been made available to such recipients. You +are responsible for ensuring that the Source Code version remains available +even if the Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a +file documenting the changes You made to create that Covered Code and the date +of any change. You must include a prominent statement that the Modification is +derived, directly or indirectly, from Original Code provided by the Initial +Developer and including the name of the Initial Developer in (a) the Source +Code, and (b) in any notice in an Executable version or related documentation +in which You describe the origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's +intellectual property rights is required to exercise the rights granted by +such Contributor under Sections 2.1 or 2.2, Contributor must include a text +file with the Source Code distribution titled "LEGAL" which describes the +claim and the party making the claim in sufficient detail that a recipient +will know whom to contact. If Contributor obtains such knowledge after the +Modification is made available as described in Section 3.2, Contributor shall +promptly modify the LEGAL file in all copies Contributor makes available +thereafter and shall take other steps (such as notifying appropriate mailing +lists or newsgroups) reasonably calculated to inform those who received the +Covered Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming +interface and Contributor has knowledge of patent licenses which are +reasonably necessary to implement that API, Contributor must also include this +information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to +Section 3.4(a) above, Contributor believes that Contributor's Modifications +are Contributor's original creation(s) and/or Contributor has sufficient +rights to grant the rights conveyed by this License. + + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source +Code. If it is not possible to put such notice in a particular Source Code +file due to its structure, then You must include such notice in a location +(such as a relevant directory) where a user would be likely to look for such a +notice. If You created one or more Modification(s) You may add your name as a +Contributor to the notice described in Exhibit A. You must also duplicate +this License in any documentation for the Source Code where You describe +recipients' rights or ownership rights relating to Covered Code. You may +choose to offer, and to charge a fee for, warranty, support, indemnity or +liability obligations to one or more recipients of Covered Code. However, You +may do so only on Your own behalf, and not on behalf of the Initial Developer +or any Contributor. You must make it absolutely clear than any such warranty, +support, indemnity or liability obligation is offered by You alone, and You +hereby agree to indemnify the Initial Developer and every Contributor for any +liability incurred by the Initial Developer or such Contributor as a result of +warranty, support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the +requirements of Section 3.1-3.5 have been met for that Covered Code, and if +You include a notice stating that the Source Code version of the Covered Code +is available under the terms of this License, including a description of how +and where You have fulfilled the obligations of Section 3.2. The notice must +be conspicuously included in any notice in an Executable version, related +documentation or collateral in which You describe recipients' rights relating +to the Covered Code. You may distribute the Executable version of Covered Code +or ownership rights under a license of Your choice, which may contain terms +different from this License, provided that You are in compliance with the +terms of this License and that the license for the Executable version does not +attempt to limit or alter the recipient's rights in the Source Code version +from the rights set forth in this License. If You distribute the Executable +version under a different license You must make it absolutely clear that any +terms which differ from this License are offered by You alone, not by the +Initial Developer or any Contributor. You hereby agree to indemnify the +Initial Developer and every Contributor for any liability incurred by the +Initial Developer or such Contributor as a result of any such terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code +not governed by the terms of this License and distribute the Larger Work as a +single product. In such a case, You must make sure the requirements of this +License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Code due to statute, +judicial order, or regulation then You must: (a) comply with the terms of this +License to the maximum extent possible; and (b) describe the limitations and +the code they affect. Such description must be included in the LEGAL file +described in Section 3.4 and must be included with all distributions of the +Source Code. Except to the extent prohibited by statute or regulation, such +description must be sufficiently detailed for a recipient of ordinary skill to +be able to understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has attached +the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised +and/or new versions of the License from time to time. Each version will be +given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the +License, You may always continue to use it under the terms of that version. +You may also choose to use such Covered Code under the terms of any subsequent +version of the License published by Netscape. No one other than Netscape has +the right to modify the terms applicable to Covered Code created under this +License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may +only do in order to apply it to code which is not already Covered Code +governed by this License), You must (a) rename Your license so that the +phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", "MPL", "NPL" or +any confusingly similar phrase do not appear in your license (except to note +that your license differs from this License) and (b) otherwise make it clear +that Your version of the license contains terms which differ from the Mozilla +Public License and Netscape Public License. (Filling in the name of the +Initial Developer, Original Code or Contributor in the notice described in +Exhibit A shall not of themselves be deemed to be modifications of this +License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT +LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, +FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED +CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY +OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR +CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS +LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS +DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate +automatically if You fail to comply with terms herein and fail to cure such +breach within 30 days of becoming aware of the breach. All sublicenses to the +Covered Code which are properly granted shall survive any termination of this +License. Provisions which, by their nature, must remain in effect beyond the +termination of this License shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement +claim (excluding declatory judgment actions) against Initial Developer or a +Contributor (the Initial Developer or Contributor against whom You file such +action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly +infringes any patent, then any and all rights granted by such Participant to +You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice +from Participant terminate prospectively, unless if within 60 days after +receipt of notice You either: (i) agree in writing to pay Participant a +mutually agreeable reasonable royalty for Your past and future use of +Modifications made by such Participant, or (ii) withdraw Your litigation claim +with respect to the Contributor Version against such Participant. If within +60 days of notice, a reasonable royalty and payment arrangement are not +mutually agreed upon in writing by the parties or the litigation claim is not +withdrawn, the rights granted by Participant to You under Sections 2.1 and/or +2.2 automatically terminate at the expiration of the 60 day notice period +specified above. + + (b) any software, hardware, or device, other than such Participant's +Contributor Version, directly or indirectly infringes any patent, then any +rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are +revoked effective as of the date You first made, used, sold, distributed, or +had made, Modifications made by that Participant. + + 8.3. If You assert a patent infringement claim against Participant +alleging that such Participant's Contributor Version directly or indirectly +infringes any patent where such claim is resolved (such as by license or +settlement) prior to the initiation of patent infringement litigation, then +the reasonable value of the licenses granted by such Participant under +Sections 2.1 or 2.2 shall be taken into account in determining the amount or +value of any payment or license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, all +end user license agreements (excluding distributors and resellers) which have +been validly granted by You or any distributor hereunder prior to termination +shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT +(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL +DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY +SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, +SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, +WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER +FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, +EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH +DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH +OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT +APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS +EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in 48 +C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and +"commercial computer software documentation," as such terms are used in 48 +C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. +227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users +acquire Covered Code with only those rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject matter +hereof. If any provision of this License is held to be unenforceable, such +provision shall be reformed only to the extent necessary to make it +enforceable. This License shall be governed by California law provisions +(except to the extent applicable law, if any, provides otherwise), excluding +its conflict-of-law provisions. With respect to disputes in which at least one +party is a citizen of, or an entity chartered or registered to do business in +the United States of America, any litigation relating to this License shall be +subject to the jurisdiction of the Federal Courts of the Northern District of +California, with venue lying in Santa Clara County, California, with the +losing party responsible for costs, including without limitation, court costs +and reasonable attorneys' fees and expenses. The application of the United +Nations Convention on Contracts for the International Sale of Goods is +expressly excluded. Any law or regulation which provides that the language of +a contract shall be construed against the drafter shall not apply to this +License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is +responsible for claims and damages arising, directly or indirectly, out of its +utilization of rights under this License and You agree to work with Initial +Developer and Contributors to distribute such responsibility on an equitable +basis. Nothing herein is intended or shall be deemed to constitute any +admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as +Multiple-Licensed. Multiple-Licensed means that the Initial Developer permits +you to utilize portions of the Covered Code under Your choice of the MPL or +the alternative licenses, if any, specified by the Initial Developer in the +file described in Exhibit A. + + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License +Version 1.1 (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.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF + ANY KIND, either express or implied. See the License for the specific +language governing rights and + limitations under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. +Portions created by + ______________________ are Copyright (C) ______ +_______________________. All Rights + Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms of +the _____ license (the [___] License), in which case the provisions of +[______] License are applicable instead of those above. If you wish to allow +use of your version of this file only under the terms of the [____] License +and not to allow others to use your version of this file under the MPL, +indicate your decision by deleting the provisions above and replace them +with the notice and other provisions required by the [___] License. If you do +not delete the provisions above, a recipient may use your version of this file +under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of +the notices in the Source Code files of the Original Code. You should use the +text of this Exhibit A rather than the text found in the Original Code Source +Code for Your Modifications.] + + +=============================================================================== + +For the JAX-WS Reference Implementation component: + +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + + + 1. Definitions. + + 1.1. "Contributor" means each individual or entity that + creates or contributes to the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the + Original Software, prior Modifications used by a + Contributor (if any), and the Modifications made by that + particular Contributor. + + 1.3. "Covered Software" means (a) the Original Software, or + (b) Modifications, or (c) the combination of files + containing Original Software with files containing + Modifications, in each case including portions thereof. + + 1.4. "Executable" means the Covered Software in any form + other than Source Code. + + 1.5. "Initial Developer" means the individual or entity + that first makes Original Software available under this + License. + + 1.6. "Larger Work" means a work which combines Covered + Software or portions thereof with code not governed by the + terms of this License. + + 1.7. "License" means this document. + + 1.8. "Licensable" means having the right to grant, to the + maximum extent possible, whether at the time of the initial + grant or subsequently acquired, any and all of the rights + conveyed herein. + + 1.9. "Modifications" means the Source Code and Executable + form of any of the following: + + A. Any file that results from an addition to, + deletion from or modification of the contents of a + file containing Original Software or previous + Modifications; + + B. Any new file that contains any part of the + Original Software or previous Modification; or + + C. Any new file that is contributed or otherwise made + available under the terms of this License. + + 1.10. "Original Software" means the Source Code and + Executable form of computer software code that is + originally released under this License. + + 1.11. "Patent Claims" means any patent claim(s), now owned + or hereafter acquired, including without limitation, + method, process, and apparatus claims, in any patent + Licensable by grantor. + + 1.12. "Source Code" means (a) the common form of computer + software code in which modifications are made and (b) + associated documentation included in or with such code. + + 1.13. "You" (or "Your") means an individual or a legal + entity exercising rights under, and complying with all of + the terms of, this License. For legal entities, "You" + includes any entity which controls, is controlled by, or is + under common control with You. For purposes of this + definition, "control" means (a) the power, direct or + indirect, to cause the direction or management of such + entity, whether by contract or otherwise, or (b) ownership + of more than fifty percent (50%) of the outstanding shares + or beneficial ownership of such entity. + + 2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, the + Initial Developer hereby grants You a world-wide, + royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Initial Developer, + to use, reproduce, modify, display, perform, + sublicense and distribute the Original Software (or + portions thereof), with or without Modifications, + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, + using or selling of Original Software, to make, have + made, use, practice, sell, and offer for sale, and/or + otherwise dispose of the Original Software (or + portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) + are effective on the date Initial Developer first + distributes or otherwise makes the Original Software + available to a third party under the terms of this + License. + + (d) Notwithstanding Section 2.1(b) above, no patent + license is granted: (1) for code that You delete from + the Original Software, or (2) for infringements + caused by: (i) the modification of the Original + Software, or (ii) the combination of the Original + Software with other software or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, each + Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Contributor to + use, reproduce, modify, display, perform, sublicense + and distribute the Modifications created by such + Contributor (or portions thereof), either on an + unmodified basis, with other Modifications, as + Covered Software and/or as part of a Larger Work; and + + + (b) under Patent Claims infringed by the making, + using, or selling of Modifications made by that + Contributor either alone and/or in combination with + its Contributor Version (or portions of such + combination), to make, use, sell, offer for sale, + have made, and/or otherwise dispose of: (1) + Modifications made by that Contributor (or portions + thereof); and (2) the combination of Modifications + made by that Contributor with its Contributor Version + (or portions of such combination). + + (c) The licenses granted in Sections 2.2(a) and + 2.2(b) are effective on the date Contributor first + distributes or otherwise makes the Modifications + available to a third party. + + (d) Notwithstanding Section 2.2(b) above, no patent + license is granted: (1) for any code that Contributor + has deleted from the Contributor Version; (2) for + infringements caused by: (i) third party + modifications of Contributor Version, or (ii) the + combination of Modifications made by that Contributor + with other software (except as part of the + Contributor Version) or other devices; or (3) under + Patent Claims infringed by Covered Software in the + absence of Modifications made by that Contributor. + + 3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make + available in Executable form must also be made available in + Source Code form and that Source Code form must be + distributed only under the terms of this License. You must + include a copy of this License with every copy of the + Source Code form of the Covered Software You distribute or + otherwise make available. You must inform recipients of any + such Covered Software in Executable form as to how they can + obtain such Covered Software in Source Code form in a + reasonable manner on or through a medium customarily used + for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You + contribute are governed by the terms of this License. You + represent that You believe Your Modifications are Your + original creation(s) and/or You have sufficient rights to + grant the rights conveyed by this License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications + that identifies You as the Contributor of the Modification. + You may not remove or alter any copyright, patent or + trademark notices contained within the Covered Software, or + any notices of licensing or any descriptive text giving + attribution to any Contributor or the Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered + Software in Source Code form that alters or restricts the + applicable version of this License or the recipients' + rights hereunder. You may choose to offer, and to charge a + fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Software. + However, you may do so only on Your own behalf, and not on + behalf of the Initial Developer or any Contributor. You + must make it absolutely clear that any such warranty, + support, indemnity or liability obligation is offered by + You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred + by the Initial Developer or such Contributor as a result of + warranty, support, indemnity or liability terms You offer. + + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered + Software under the terms of this License or under the terms + of a license of Your choice, which may contain terms + different from this License, provided that You are in + compliance with the terms of this License and that the + license for the Executable form does not attempt to limit + or alter the recipient's rights in the Source Code form + from the rights set forth in this License. If You + distribute the Covered Software in Executable form under a + different license, You must make it absolutely clear that + any terms which differ from this License are offered by You + alone, not by the Initial Developer or Contributor. You + hereby agree to indemnify the Initial Developer and every + Contributor for any liability incurred by the Initial + Developer or such Contributor as a result of any such terms + You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software + with other code not governed by the terms of this License + and distribute the Larger Work as a single product. In such + a case, You must make sure the requirements of this License + are fulfilled for the Covered Software. + + 4. Versions of the License. + + 4.1. New Versions. + + Sun Microsystems, Inc. is the initial license steward and + may publish revised and/or new versions of this License + from time to time. Each version will be given a + distinguishing version number. Except as provided in + Section 4.3, no one other than the license steward has the + right to modify this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. If the Initial Developer includes a + notice in the Original Software prohibiting it from being + distributed or otherwise made available under any + subsequent version of the License, You must distribute and + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. Otherwise, You may also choose to + use, distribute or otherwise make the Covered Software + available under the terms of any subsequent version of the + License published by the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a + new license for Your Original Software, You may create and + use a modified version of this License if You: (a) rename + the license and remove any references to the name of the + license steward (except to note that the license differs + from this License); and (b) otherwise make it clear that + the license contains terms which differ from this License. + + + 5. DISCLAIMER OF WARRANTY. + + COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" + BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED + SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR + PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY + COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE + INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF + ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF + WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS + DISCLAIMER. + + 6. TERMINATION. + + 6.1. This License and the rights granted hereunder will + terminate automatically if You fail to comply with terms + herein and fail to cure such breach within 30 days of + becoming aware of the breach. Provisions which, by their + nature, must remain in effect beyond the termination of + this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding + declaratory judgment actions) against Initial Developer or + a Contributor (the Initial Developer or Contributor against + whom You assert such claim is referred to as "Participant") + alleging that the Participant Software (meaning the + Contributor Version where the Participant is a Contributor + or the Original Software where the Participant is the + Initial Developer) directly or indirectly infringes any + patent, then any and all rights granted directly or + indirectly to You by such Participant, the Initial + Developer (if the Initial Developer is not the Participant) + and all Contributors under Sections 2.1 and/or 2.2 of this + License shall, upon 60 days notice from Participant + terminate prospectively and automatically at the expiration + of such 60 day notice period, unless if within such 60 day + period You withdraw Your claim with respect to the + Participant Software against such Participant either + unilaterally or pursuant to a written agreement with + Participant. + + 6.3. In the event of termination under Sections 6.1 or 6.2 + above, all end user licenses that have been validly granted + by You or any distributor hereunder prior to termination + (excluding licenses granted to You by any distributor) + shall survive termination. + + 7. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE + INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF + COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE + LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR + CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT + LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK + STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL + INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT + APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO + NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR + CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT + APPLY TO YOU. + + 8. U.S. GOVERNMENT END USERS. + + The Covered Software is a "commercial item," as that term is + defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial + computer software" (as that term is defined at 48 C.F.R. + 252.227-7014(a)(1)) and "commercial computer software + documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. + 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 + through 227.7202-4 (June 1995), all U.S. Government End Users + acquire Covered Software with only those rights set forth herein. + This U.S. Government Rights clause is in lieu of, and supersedes, + any other FAR, DFAR, or other clause or provision that addresses + Government rights in computer software under this License. + + 9. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the + extent necessary to make it enforceable. This License shall be + governed by the law of the jurisdiction specified in a notice + contained within the Original Software (except to the extent + applicable law, if any, provides otherwise), excluding such + jurisdiction's conflict-of-law provisions. Any litigation + relating to this License shall be subject to the jurisdiction of + the courts located in the jurisdiction and venue specified in a + notice contained within the Original Software, with the losing + party responsible for costs, including, without limitation, court + costs and reasonable attorneys' fees and expenses. The + application of the United Nations Convention on Contracts for the + International Sale of Goods is expressly excluded. Any law or + regulation which provides that the language of a contract shall + be construed against the drafter shall not apply to this License. + You agree that You alone are responsible for compliance with the + United States export administration regulations (and the export + control laws and regulation of any other countries) when You use, + distribute or otherwise make available any Covered Software. + + 10. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or + indirectly, out of its utilization of rights under this License + and You agree to work with Initial Developer and Contributors to + distribute such responsibility on an equitable basis. Nothing + herein is intended or shall be deemed to constitute any admission + of liability. + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/NOTICE b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/NOTICE new file mode 100644 index 0000000000..d48810c0ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/NOTICE @@ -0,0 +1,18 @@ +========================================================================= +== NOTICE file corresponding to the section 4 d of == +== the Apache License, Version 2.0, == +== in this case for the Apache Tuscany distribution. == +========================================================================= + +This product includes software developed by the Apache Software Foundation +(http://www.apache.org/). + +This product also includes software developed by: +- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/) +- the Celtix project (http://celtix.objectweb.org/) +- the Mozilla Rhino project (http://www.mozilla.org/rhino/) +- the GlassFish JAX-WS project (https://jax-ws.dev.java.net/) + +Please read the LICENSE.txt file present in the root directory of this +distribution. + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..5bb55f2405 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/resources/META-INF/sca/default.scdl @@ -0,0 +1,44 @@ + + + + + + + + HelloWorldServiceComponent + + + + + + + + + HelloWorldRmiReference + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/pom.xml new file mode 100644 index 0000000000..fcb4b086c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/pom.xml @@ -0,0 +1,60 @@ + + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + + 4.0.0 + binding-servicemix + Apache Tuscany Binding for ServiceMix + Implementation of the SCA JBI Binding + + + + + org.apache.tuscany.sca.kernel + tuscany-spi + ${sca.version} + compile + + + + org.apache.servicemix + servicemix-core + 3.0-SNAPSHOT + compile + + + + org.apache.servicemix + servicemix-common + 3.0-SNAPSHOT + compile + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaBootstrap.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaBootstrap.java new file mode 100644 index 0000000000..ad407553b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaBootstrap.java @@ -0,0 +1,169 @@ +/* + * 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.servicemix.sca; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.jbi.JBIException; +import javax.jbi.component.Bootstrap; +import javax.jbi.component.InstallationContext; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +/** + * Base class for components bootstrap. + * + * @author Guillaume Nodet + * @version $Revision$ + * @since 3.0 + */ +public class ScaBootstrap implements Bootstrap { + + protected final transient Log logger = LogFactory.getLog(getClass()); + + protected InstallationContext context; + protected ObjectName mbeanName; + + public ScaBootstrap() { + } + + public ObjectName getExtensionMBeanName() { + return mbeanName; + } + + protected Object getExtensionMBean() throws Exception { + return null; + } + + protected ObjectName createExtensionMBeanName() throws Exception { + return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); + } + + /* (non-Javadoc) + * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext) + */ + public void init(InstallationContext installContext) throws JBIException { + try { + if (logger.isDebugEnabled()) { + logger.debug("Initializing bootstrap"); + } + this.context = installContext; + doInit(); + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap initialized"); + } + } catch (JBIException e) { + throw e; + } catch (Exception e) { + throw new JBIException("Error calling init", e); + } + } + + protected void doInit() throws Exception { + Object mbean = getExtensionMBean(); + if (mbean != null) { + this.mbeanName = createExtensionMBeanName(); + MBeanServer server = this.context.getContext().getMBeanServer(); + if (server == null) { + throw new JBIException("null mBeanServer"); + } + if (server.isRegistered(this.mbeanName)) { + server.unregisterMBean(this.mbeanName); + } + server.registerMBean(mbean, this.mbeanName); + } + } + + /* (non-Javadoc) + * @see javax.jbi.component.Bootstrap#cleanUp() + */ + public void cleanUp() throws JBIException { + try { + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up bootstrap"); + } + doCleanUp(); + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap cleaned up"); + } + } catch (JBIException e) { + throw e; + } catch (Exception e) { + throw new JBIException("Error calling cleanUp", e); + } + } + + protected void doCleanUp() throws Exception { + if (this.mbeanName != null) { + MBeanServer server = this.context.getContext().getMBeanServer(); + if (server == null) { + throw new JBIException("null mBeanServer"); + } + if (server.isRegistered(this.mbeanName)) { + server.unregisterMBean(this.mbeanName); + } + } + } + + /* (non-Javadoc) + * @see javax.jbi.component.Bootstrap#onInstall() + */ + public void onInstall() throws JBIException { + try { + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap onInstall"); + } + doOnInstall(); + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap onInstall done"); + } + } catch (JBIException e) { + throw e; + } catch (Exception e) { + throw new JBIException("Error calling onInstall", e); + } + } + + protected void doOnInstall() throws Exception { + } + + /* (non-Javadoc) + * @see javax.jbi.component.Bootstrap#onUninstall() + */ + public void onUninstall() throws JBIException { + try { + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap onUninstall"); + } + doOnUninstall(); + if (logger.isDebugEnabled()) { + logger.debug("Bootstrap onUninstall done"); + } + } catch (JBIException e) { + throw e; + } catch (Exception e) { + throw new JBIException("Error calling onUninstall", e); + } + } + + protected void doOnUninstall() throws Exception { + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaComponent.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaComponent.java new file mode 100644 index 0000000000..93470e0707 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaComponent.java @@ -0,0 +1,43 @@ +/* + * 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.servicemix.sca; + +import org.apache.servicemix.common.BaseComponent; +import org.apache.servicemix.common.BaseLifeCycle; +import org.apache.servicemix.common.BaseServiceUnitManager; +import org.apache.servicemix.common.Deployer; + +public class ScaComponent extends BaseComponent { + + /* (non-Javadoc) + * @see org.servicemix.common.BaseComponent#createLifeCycle() + */ + protected BaseLifeCycle createLifeCycle() { + return new ScaLifeCycle(this); + } + + /* (non-Javadoc) + * @see org.servicemix.common.BaseComponent#createServiceUnitManager() + */ + public BaseServiceUnitManager createServiceUnitManager() { + Deployer[] deployers = new Deployer[] { new ScaDeployer(this) }; + return new BaseServiceUnitManager(this, deployers); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaDeployer.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaDeployer.java new file mode 100644 index 0000000000..199721cb88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaDeployer.java @@ -0,0 +1,60 @@ +/* + * 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.servicemix.sca; + +import java.io.File; + +import javax.jbi.management.DeploymentException; + +import org.apache.servicemix.common.AbstractDeployer; +import org.apache.servicemix.common.BaseComponent; +import org.apache.servicemix.common.ServiceUnit; + +public class ScaDeployer extends AbstractDeployer { + + public static final String SCA_MODULE_FILE = "sca.module"; + + public ScaDeployer(BaseComponent component) { + super(component); + } + + public boolean canDeploy(String serviceUnitName, String serviceUnitRootPath) { + File module = new File(serviceUnitRootPath, SCA_MODULE_FILE); + return module.exists() && module.isFile(); + } + + public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) + throws DeploymentException { + File module = new File(serviceUnitRootPath, SCA_MODULE_FILE); + if (!module.exists() || !module.isFile()) { + throw failure("deploy", "No sca.module found", null); + } + try { + ScaServiceUnit su = new ScaServiceUnit(); + su.setComponent(component); + su.setName(serviceUnitName); + su.setRootPath(serviceUnitRootPath); + su.init(); + return su; + } catch (Exception e) { + throw failure("deploy", "Error loading sca module", e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java new file mode 100644 index 0000000000..8da798d26f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java @@ -0,0 +1,157 @@ +/* + * 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.servicemix.sca; + +import java.io.StringWriter; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.UndeclaredThrowableException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.jbi.component.ComponentContext; +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.MessageExchange; +import javax.jbi.messaging.NormalizedMessage; +import javax.jbi.messaging.MessageExchange.Role; +import javax.jbi.servicedesc.ServiceEndpoint; +import javax.xml.bind.JAXBContext; + +import org.apache.servicemix.common.Endpoint; +import org.apache.servicemix.common.ExchangeProcessor; +import org.apache.servicemix.jbi.jaxp.StringSource; +import org.apache.tuscany.core.context.EntryPointContext; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; + +/** + * + * @author gnodet + * @version $Revision$ + * @org.apache.xbean.XBean element="endpoint" description="A sca endpoint" + * + */ +public class ScaEndpoint extends Endpoint implements ExchangeProcessor { + + protected ServiceEndpoint activated; + + protected EntryPoint entryPoint; + + protected Map methodMap; + + protected JAXBContext jaxbContext; + + protected DeliveryChannel channel; + + public ScaEndpoint(EntryPoint entryPoint) { + this.entryPoint = entryPoint; + } + + public Role getRole() { + return Role.PROVIDER; + } + + public void activate() throws Exception { + logger = this.serviceUnit.getComponent().getLogger(); + ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext(); + activated = ctx.activateEndpoint(service, endpoint); + channel = ctx.getDeliveryChannel(); + // Get the target service + ConfiguredReference referenceValue = entryPoint.getConfiguredReference(); + ConfiguredService targetServiceEndpoint = referenceValue.getTargetConfiguredServices().get(0); + // Get the business interface + Class serviceInterface = targetServiceEndpoint.getService().getServiceContract().getInterface(); + List classes = new ArrayList(); + methodMap = new HashMap(); + for (Method mth : serviceInterface.getMethods()) { + Class[] params = mth.getParameterTypes(); + if (params.length != 1) { + throw new IllegalStateException("Supports only methods with one parameter"); + } + methodMap.put(params[0], mth); + classes.add(mth.getReturnType()); + classes.add(params[0]); + } + jaxbContext = JAXBContext.newInstance(classes.toArray(new Class[0])); + } + + public void deactivate() throws Exception { + ServiceEndpoint ep = activated; + activated = null; + ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext(); + ctx.deactivateEndpoint(ep); + } + + public ExchangeProcessor getProcessor() { + return this; + } + + public void process(MessageExchange exchange) throws Exception { + if (exchange.getStatus() == ExchangeStatus.DONE) { + return; + } else if (exchange.getStatus() == ExchangeStatus.ERROR) { + return; + } + Object input = jaxbContext.createUnmarshaller().unmarshal(exchange.getMessage("in").getContent()); + Method method = methodMap.get(input.getClass()); + if (method == null) { + throw new IllegalStateException("Could not determine invoked web method"); + } + boolean oneWay = method.getReturnType() == null; + Object output; + try { + EntryPointContext entryPointContext = (EntryPointContext) ((ScaServiceUnit) serviceUnit) + .getTuscanyRuntime().getModuleContext().getContext(entryPoint.getName()); + InvocationHandler handler = (InvocationHandler) entryPointContext.getImplementationInstance(); + output = handler.invoke(null, method, new Object[] { input }); + } catch (UndeclaredThrowableException e) { + throw e; + } catch (RuntimeException e) { + throw e; + } catch (Error e) { + throw e; + } catch (Exception e) { + throw e; + } catch (Throwable e) { + throw new RuntimeException(e); + } + if (oneWay) { + exchange.setStatus(ExchangeStatus.DONE); + channel.send(exchange); + } else { + NormalizedMessage msg = exchange.createMessage(); + exchange.setMessage(msg, "out"); + StringWriter writer = new StringWriter(); + jaxbContext.createMarshaller().marshal(output, writer); + msg.setContent(new StringSource(writer.toString())); + channel.send(exchange); + } + } + + public void start() throws Exception { + } + + public void stop() throws Exception { + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java new file mode 100644 index 0000000000..499459dc71 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java @@ -0,0 +1,30 @@ +/* + * 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.servicemix.sca; + +import org.apache.servicemix.common.BaseComponent; +import org.apache.servicemix.common.BaseLifeCycle; + +public class ScaLifeCycle extends BaseLifeCycle { + + public ScaLifeCycle(BaseComponent component) { + super(component); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java new file mode 100644 index 0000000000..e391edf071 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java @@ -0,0 +1,113 @@ +/* + * 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.servicemix.sca; + +import java.io.File; +import java.io.FilenameFilter; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Iterator; + +import javax.wsdl.Definition; +import javax.wsdl.factory.WSDLFactory; + +import org.apache.servicemix.common.ServiceUnit; +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.servicemix.sca.tuscany.CommonsLoggingMonitorFactory; +import org.apache.servicemix.sca.tuscany.TuscanyRuntime; +import org.apache.tuscany.model.assembly.Binding; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.Module; + +public class ScaServiceUnit extends ServiceUnit { + + protected static final ThreadLocal SERVICE_UNIT = new ThreadLocal(); + + public static ScaServiceUnit getCurrentScaServiceUnit() { + return SERVICE_UNIT.get(); + } + + protected TuscanyRuntime tuscanyRuntime; + protected ClassLoader classLoader; + + public void init() throws Exception { + SERVICE_UNIT.set(this); + createScaRuntime(); + createEndpoints(); + SERVICE_UNIT.set(null); + } + + protected void createScaRuntime() throws Exception { + File root = new File(getRootPath()); + File[] files = root.listFiles(new JarFileFilter()); + URL[] urls = new URL[files.length + 1]; + for (int i = 0; i < files.length; i++) { + urls[i] = files[i].toURL(); + } + urls[urls.length - 1] = root.toURL(); + classLoader = new URLClassLoader(urls, getClass().getClassLoader()); + + tuscanyRuntime = new TuscanyRuntime(getName(), getRootPath(), classLoader, new CommonsLoggingMonitorFactory()); + } + + protected void createEndpoints() throws Exception { + Module module = tuscanyRuntime.getModuleComponent().getModuleImplementation(); + for (Iterator i = module.getEntryPoints().iterator(); i.hasNext();) { + EntryPoint entryPoint = (EntryPoint) i.next(); + Binding binding = (Binding) entryPoint.getBindings().get(0); + if (binding instanceof JbiBinding) { + JbiBinding jbiBinding = (JbiBinding) binding; + ScaEndpoint endpoint = new ScaEndpoint(entryPoint); + endpoint.setServiceUnit(this); + endpoint.setService(jbiBinding.getServiceName()); + endpoint.setEndpoint(jbiBinding.getEndpointName()); + endpoint.setInterfaceName(jbiBinding.getInterfaceName()); + Definition definition = jbiBinding.getDefinition(); + if (definition != null) { + endpoint.setDefinition(definition); + endpoint.setDescription(WSDLFactory.newInstance().newWSDLWriter().getDocument(definition)); + } + addEndpoint(endpoint); + } + } + } + + private static class JarFileFilter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.endsWith(".jar"); + } + } + + public TuscanyRuntime getTuscanyRuntime() { + return tuscanyRuntime; + } + + @Override + public void start() throws Exception { + tuscanyRuntime.start(); + super.start(); + } + + @Override + public void stop() throws Exception { + super.stop(); + tuscanyRuntime.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java new file mode 100644 index 0000000000..ef7812f175 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java @@ -0,0 +1,33 @@ +/* + * 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.servicemix.sca.assembly; + +import org.apache.tuscany.model.assembly.AssemblyFactory; + +/** + * The Factory for the model. + */ +public interface JbiAssemblyFactory extends AssemblyFactory { + + /** + * Returns a new JbiBinding + */ + JbiBinding createJbiBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java new file mode 100644 index 0000000000..8bfbf80590 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java @@ -0,0 +1,85 @@ +/* + * 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.servicemix.sca.assembly; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.model.assembly.Binding; + +public interface JbiBinding extends Binding { + + /** + * Returns the URI of the WSDL port for this binding. + * @return the URI of the WSDL port for this binding + */ + String getPortURI(); + + /** + * Set the URI of the WSDL port for this binding. + * @param portURI the URI of the WSDL port + */ + void setPortURI(String portURI); + + /** + * Returns the service name. + * @return the service name + */ + QName getServiceName(); + + /** + * Returns the endpoint name. + * @return the endpoint name + */ + String getEndpointName(); + + /** + * Returns the interface name. + * @returnthe interface name + */ + QName getInterfaceName(); + + /** + * Returns the WSDL definition containing the WSDL port. + * @return the WSDL definition containing the WSDL port + */ + Definition getDefinition(); + + /** + * Returns the the WSDL service. + * @return the WSDL service + */ + Service getService(); + + /** + * Returns the WSDL port defining this binding. + * @return the WSDL port defining this binding + */ + Port getPort(); + + /** + * Returns the WSDL port type. + * @return the WSDL port type + */ + PortType getPortType(); + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java new file mode 100644 index 0000000000..4cd6a98689 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java @@ -0,0 +1,44 @@ +/* + * 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.servicemix.sca.assembly.impl; + +import org.apache.servicemix.sca.assembly.JbiAssemblyFactory; +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; + +/** + * An implementation of the model Factory. + */ +public class JbiAssemblyFactoryImpl extends AssemblyFactoryImpl implements JbiAssemblyFactory { + + /** + * Creates an instance of the factory. + */ + public JbiAssemblyFactoryImpl() { + super(); + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiAssemblyFactory#createJbiBinding() + */ + public JbiBinding createJbiBinding() { + return new JbiBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java new file mode 100644 index 0000000000..e44b9c6f45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java @@ -0,0 +1,166 @@ +/* + * 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.servicemix.sca.assembly.impl; + +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.impl.BindingImpl; + +/** + * An implementation of the model object 'Web Service Binding'. + */ +public class JbiBindingImpl extends BindingImpl implements JbiBinding { + + private String portURI; + private QName serviceName; + private String endpointName; + private QName interfaceName; + private Definition definition; + private Service service; + private PortType portType; + private Port port; + + + /** + * Constructor + */ + protected JbiBindingImpl() { + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortURI() + */ + public String getPortURI() { + return portURI; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#setPortURI(java.lang.String) + */ + public void setPortURI(String portURI) { + this.portURI = portURI; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getServiceName() + */ + public QName getServiceName() { + return serviceName; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getEndpointName() + */ + public String getEndpointName() { + return endpointName; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getInterfaceName() + */ + public QName getInterfaceName() { + return interfaceName; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getDefinition() + */ + public Definition getDefinition() { + return definition; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getService() + */ + public Service getService() { + return service; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getPort() + */ + public Port getPort() { + return port; + } + + /* (non-Javadoc) + * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortType() + */ + public PortType getPortType() { + return portType; + } + + /** + * @see org.apache.tuscany.model.assembly.impl.BindingImpl#initialize(org.apache.tuscany.model.assembly.AssemblyModelContext) + */ + public void initialize(AssemblyModelContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Get the service name and endpoint name + String[] parts = split(portURI); + serviceName = new QName(parts[0], parts[1]); + endpointName = parts[2]; + + // Load the WSDL definitions for the given namespace + List definitions = modelContext.getAssemblyLoader().loadDefinitions(parts[0]); + if (definitions != null) { + for (Definition definition : definitions) { + Service service = definition.getService(serviceName); + if (service != null) { + Port port = service.getPort(endpointName); + if (port != null) { + this.service = service; + this.port = port; + this.portType = port.getBinding().getPortType(); + this.interfaceName = portType.getQName(); + this.definition = definition; + return; + } + } + } + } + } + + protected String[] split(String uri) { + char sep; + uri = uri.trim(); + if (uri.indexOf('/') > 0) { + sep = '/'; + } else { + sep = ':'; + } + int idx1 = uri.lastIndexOf(sep); + int idx2 = uri.lastIndexOf(sep, idx1 - 1); + String epName = uri.substring(idx1 + 1); + String svcName = uri.substring(idx2 + 1, idx1); + String nsUri = uri.substring(0, idx2); + return new String[] { nsUri, svcName, epName }; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java new file mode 100644 index 0000000000..e5a7b59a75 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java @@ -0,0 +1,151 @@ +/* + * 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.servicemix.sca.builder; + +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.servicemix.sca.config.ExternalJbiServiceContextFactory; +import org.apache.servicemix.sca.handler.ExternalJbiServiceClient; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.injection.SingletonObjectFactory; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.MethodHashMap; +import org.apache.tuscany.core.invocation.ProxyConfiguration; +import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.apache.tuscany.model.scdl.WebServiceBinding; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +/** + * Creates a RuntimeConfigurationBuilder for an external service configured with the {@link WebServiceBinding} + */ +@Scope("MODULE") +public class ExternalJbiServiceBuilder implements ContextFactoryBuilder { + + private RuntimeContext runtimeContext; + + private ProxyFactoryFactory proxyFactoryFactory; + + private MessageFactory messageFactory; + + private ContextFactoryBuilder policyBuilder; + + public ExternalJbiServiceBuilder() { + } + + @Init(eager = true) + public void init() { + runtimeContext.addBuilder(this); + } + + /** + * @param runtimeContext The runtimeContext to set. + */ + @Autowire + public void setRuntimeContext(RuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + } + + /** + * Sets the factory used to construct proxies implmementing the business interface required by a reference + */ + @Autowire + public void setProxyFactoryFactory(ProxyFactoryFactory factory) { + this.proxyFactoryFactory = factory; + } + + /** + * Sets the factory used to construct invocation messages + * + * @param msgFactory + */ + @Autowire + public void setMessageFactory(MessageFactory msgFactory) { + this.messageFactory = msgFactory; + } + + /** + * Sets a builder responsible for creating source-side and target-side invocation chains for a reference. The + * reference builder may be hierarchical, containing other child reference builders that operate on specific + * metadata used to construct and invocation chain. + * + * @see org.apache.tuscany.core.builder.impl.HierarchicalBuilder + */ + public void setPolicyBuilder(ContextFactoryBuilder builder) { + policyBuilder = builder; + } + + public void build(AssemblyModelObject object) throws BuilderException { + if (!(object instanceof ExternalService)) { + return; + } + ExternalService externalService = (ExternalService) object; + if (externalService.getBindings().size() < 1 || !(externalService.getBindings().get(0) instanceof JbiBinding)) { + return; + } + + ExternalJbiServiceClient externalJbiServiceClient = new ExternalJbiServiceClient(externalService); + ExternalJbiServiceContextFactory config = new ExternalJbiServiceContextFactory(externalService.getName(), new SingletonObjectFactory(externalJbiServiceClient)); + + ConfiguredService configuredService = externalService.getConfiguredService(); + Service service = configuredService.getService(); + ServiceContract serviceContract = service.getServiceContract(); + Map iConfigMap = new MethodHashMap(); + ProxyFactory proxyFactory = proxyFactoryFactory.createProxyFactory(); + Set javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(serviceContract.getInterface()); + for (Method method : javaMethods) { + InvocationConfiguration iConfig = new InvocationConfiguration(method); + iConfigMap.put(method, iConfig); + } + QualifiedName qName = new QualifiedName(externalService.getName() + "/" + service.getName()); + ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, serviceContract.getInterface().getClassLoader(), messageFactory); + proxyFactory.setBusinessInterface(serviceContract.getInterface()); + proxyFactory.setProxyConfiguration(pConfiguration); + config.addTargetProxyFactory(service.getName(), proxyFactory); + configuredService.setProxyFactory(proxyFactory); + if (policyBuilder != null) { + // invoke the reference builder to handle additional policy metadata + policyBuilder.build(configuredService); + } + // add tail interceptor + for (InvocationConfiguration iConfig : (Collection) iConfigMap.values()) { + iConfig.addTargetInterceptor(new InvokerInterceptor()); + } + + externalService.getConfiguredService().setContextFactory(config); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java new file mode 100644 index 0000000000..1dc7d9f454 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java @@ -0,0 +1,70 @@ +/* + * 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.servicemix.sca.builder; + +import org.apache.servicemix.sca.config.ExternalJbiServiceContextFactory; +import org.apache.servicemix.sca.handler.ExternalJbiServiceTargetInvoker; +import org.apache.tuscany.core.builder.BuilderConfigException; +import org.apache.tuscany.core.builder.WireBuilder; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class ExternalJbiServiceWireBuilder implements WireBuilder { + + private RuntimeContext runtimeContext; + + /** + * Constructs a new ExternalWebServiceWireBuilder. + */ + public ExternalJbiServiceWireBuilder() { + super(); + } + + @Autowire + public void setRuntimeContext(RuntimeContext context) { + runtimeContext = context; + } + + @Init(eager=true) + public void init() { + runtimeContext.addBuilder(this); + } + + public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope, ScopeContext targetScopeContext) throws BuilderConfigException { + if (!(ExternalJbiServiceContextFactory.class.isAssignableFrom(targetType))) { + return; + } + for (InvocationConfiguration sourceInvocationConfig : sourceFactory.getProxyConfiguration().getInvocationConfigurations().values()) { + ExternalJbiServiceTargetInvoker invoker = new ExternalJbiServiceTargetInvoker(sourceFactory.getProxyConfiguration().getTargetName(), sourceInvocationConfig.getMethod(), targetScopeContext); + sourceInvocationConfig.setTargetInvoker(invoker); + } + } + + public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) + throws BuilderConfigException { + //TODO implement + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java new file mode 100644 index 0000000000..af83c7c714 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java @@ -0,0 +1,169 @@ +/* + * 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.servicemix.sca.builder; + +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.servicemix.sca.config.JbiServiceEntryPointContextFactory; +import org.apache.tuscany.core.builder.BuilderException; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.impl.EntryPointContextFactory; +import org.apache.tuscany.core.config.JavaIntrospectionHelper; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.invocation.Interceptor; +import org.apache.tuscany.core.invocation.InvocationConfiguration; +import org.apache.tuscany.core.invocation.InvocationRuntimeException; +import org.apache.tuscany.core.invocation.ProxyConfiguration; +import org.apache.tuscany.core.invocation.TargetInvoker; +import org.apache.tuscany.core.invocation.spi.ProxyFactory; +import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory; +import org.apache.tuscany.core.message.Message; +import org.apache.tuscany.core.message.MessageFactory; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.apache.tuscany.model.assembly.AssemblyModelObject; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class JbiServiceEntryPointBuilder implements ContextFactoryBuilder { + + private RuntimeContext runtimeContext; + + private ProxyFactoryFactory proxyFactoryFactory; + + private MessageFactory messageFactory; + + private ContextFactoryBuilder policyBuilder; + + public JbiServiceEntryPointBuilder() { + } + + @Init(eager = true) + public void init() { + runtimeContext.addBuilder(this); + } + + /** + * @param runtimeContext The runtimeContext to set. + */ + @Autowire + public void setRuntimeContext(RuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + } + + /** + * Sets the factory used to construct proxies implmementing the business interface required by a reference + */ + @Autowire + public void setProxyFactoryFactory(ProxyFactoryFactory factory) { + this.proxyFactoryFactory = factory; + } + + /** + * Sets the factory used to construct invocation messages + * + * @param msgFactory + */ + @Autowire + public void setMessageFactory(MessageFactory msgFactory) { + this.messageFactory = msgFactory; + } + + /** + * Sets a builder responsible for creating source-side and target-side invocation chains for a reference. The + * reference builder may be hierarchical, containing other child reference builders that operate on specific + * metadata used to construct and invocation chain. + * + * @see org.apache.tuscany.core.builder.impl.HierarchicalBuilder + */ + public void setPolicyBuilder(ContextFactoryBuilder builder) { + policyBuilder = builder; + } + + public void build(AssemblyModelObject object) throws BuilderException { + if (!(object instanceof EntryPoint)) { + return; + } + EntryPoint entryPoint = (EntryPoint) object; + if (entryPoint.getBindings().size() < 1 || !(entryPoint.getBindings().get(0) instanceof JbiBinding)) { + return; + } + + EntryPointContextFactory config = new JbiServiceEntryPointContextFactory(entryPoint.getName(), entryPoint.getConfiguredService().getService().getName(), messageFactory); + + ConfiguredService configuredService = entryPoint.getConfiguredService(); + Service service = configuredService.getService(); + ServiceContract serviceContract = service.getServiceContract(); + Map iConfigMap = new HashMap(); + ProxyFactory proxyFactory = proxyFactoryFactory.createProxyFactory(); + Set javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(serviceContract.getInterface()); + for (Method method : javaMethods) { + InvocationConfiguration iConfig = new InvocationConfiguration(method); + iConfigMap.put(method, iConfig); + } + QualifiedName qName = new QualifiedName(entryPoint.getConfiguredReference().getTargetConfiguredServices().get(0).getAggregatePart().getName() + "/" + service.getName()); + ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, serviceContract.getInterface().getClassLoader(), messageFactory); + proxyFactory.setBusinessInterface(serviceContract.getInterface()); + proxyFactory.setProxyConfiguration(pConfiguration); + config.addSourceProxyFactory(service.getName(), proxyFactory); + configuredService.setProxyFactory(proxyFactory); + if (policyBuilder != null) { + // invoke the reference builder to handle additional policy metadata + policyBuilder.build(configuredService); + } + // add tail interceptor + for (InvocationConfiguration iConfig : (Collection) iConfigMap.values()) { + iConfig.addTargetInterceptor(new EntryPointInvokerInterceptor()); + } + entryPoint.getConfiguredReference().setContextFactory(config); + } + + //FIXME same as the InvokerInterceptor except that it doesn't throw an exception in setNext + // For some reason another InvokerInterceptor is added after this one, need Jim to look into it + // and figure out why. + public class EntryPointInvokerInterceptor implements Interceptor { + + public EntryPointInvokerInterceptor() { + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + TargetInvoker invoker = msg.getTargetInvoker(); + if (invoker == null) { + throw new InvocationRuntimeException("No target invoker specified on message"); + } + return invoker.invoke(msg); + } + + public void setNext(Interceptor next) { + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java new file mode 100644 index 0000000000..93b846db8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java @@ -0,0 +1,30 @@ +/* + * 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.servicemix.sca.config; + +import org.apache.tuscany.core.builder.ObjectFactory; +import org.apache.tuscany.core.builder.impl.BaseExternalServiceContextFactory; + +public class ExternalJbiServiceContextFactory extends BaseExternalServiceContextFactory { + + public ExternalJbiServiceContextFactory(String name, ObjectFactory objectFactory) { + super(name, objectFactory); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java new file mode 100644 index 0000000000..b6adb6481d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java @@ -0,0 +1,30 @@ +/* + * 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.servicemix.sca.config; + +import org.apache.tuscany.core.builder.impl.EntryPointContextFactory; +import org.apache.tuscany.core.message.MessageFactory; + +public class JbiServiceEntryPointContextFactory extends EntryPointContextFactory { + + public JbiServiceEntryPointContextFactory(String name, String referenceName, MessageFactory msgFactory) { + super(name, referenceName, msgFactory); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java new file mode 100644 index 0000000000..22b457687f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java @@ -0,0 +1,94 @@ +/* + * 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.servicemix.sca.handler; + +import java.io.ByteArrayOutputStream; +import java.lang.reflect.Method; + +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.NormalizedMessage; +import javax.xml.bind.JAXBContext; + +import org.apache.servicemix.jbi.jaxp.StringSource; +import org.apache.servicemix.sca.ScaServiceUnit; +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.tuscany.model.assembly.ExternalService; + +public class ExternalJbiServiceClient { + + private ExternalService externalService; + + private JbiBinding jbiBinding; + + private ScaServiceUnit serviceUnit; + + /** + * Constructs a new ExternalWebServiceClient. + * + * @param externalService + * @param wsBinding + */ + public ExternalJbiServiceClient(ExternalService externalService) { + this.serviceUnit = ScaServiceUnit.getCurrentScaServiceUnit(); + this.externalService = externalService; + this.jbiBinding = (JbiBinding) this.externalService.getBindings().get(0); + } + + /** + * Invoke an operation on the external Web service. + * + * @param method + * @param args + * @return + */ + public Object invoke(Method method, Object[] args) { + if (args == null || args.length != 1) { + throw new IllegalStateException("args should have exactly one object"); + } + try { + Object payload = args[0]; + Class inputClass = method.getParameterTypes()[0]; + Class outputClass = method.getReturnType(); + JAXBContext context = JAXBContext.newInstance(inputClass, outputClass); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + context.createMarshaller().marshal(payload, baos); + + DeliveryChannel channel = serviceUnit.getComponent().getComponentContext().getDeliveryChannel(); + // TODO: in-only case ? + // TODO: interface based routing ? + // TODO: explicit endpoint selection ? + InOut inout = channel.createExchangeFactory().createInOutExchange(); + inout.setService(jbiBinding.getServiceName()); + NormalizedMessage in = inout.createMessage(); + inout.setInMessage(in); + in.setContent(new StringSource(baos.toString())); + boolean sent = channel.sendSync(inout); + // TODO: check for error ? + NormalizedMessage out = inout.getOutMessage(); + Object response = context.createUnmarshaller().unmarshal(out.getContent()); + inout.setStatus(ExchangeStatus.DONE); + channel.send(inout); + return response; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java new file mode 100644 index 0000000000..cd0560c5b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java @@ -0,0 +1,110 @@ +/* + * 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.servicemix.sca.handler; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tuscany.core.context.ExternalServiceContext; +import org.apache.tuscany.core.context.InstanceContext; +import org.apache.tuscany.core.context.QualifiedName; +import org.apache.tuscany.core.context.ScopeContext; +import org.apache.tuscany.core.context.TargetException; +import org.apache.tuscany.core.invocation.Interceptor; +import org.apache.tuscany.core.invocation.TargetInvoker; +import org.apache.tuscany.core.message.Message; + +public class ExternalJbiServiceTargetInvoker implements TargetInvoker { + + private QualifiedName serviceName; + private String esName; + private Method method; + private ScopeContext container; + + private ExternalServiceContext context; + + /** + * Constructs a new ExternalJbiServiceTargetInvoker. + * @param esName + * @param container + */ + public ExternalJbiServiceTargetInvoker(QualifiedName serviceName, Method method, ScopeContext container) { + assert (serviceName != null) : "No service name specified"; + assert (method != null) : "No method specified"; + assert (container != null) : "No scope container specified"; + this.serviceName = serviceName; + this.esName = serviceName.getPartName(); + this.method = method; + this.container = container; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + if (context == null) { + InstanceContext iContext = container.getContext(esName); + if (!(iContext instanceof ExternalServiceContext)) { + TargetException te = new TargetException("Unexpected target context type"); + te.setIdentifier(iContext.getClass().getName()); + te.addContextName(iContext.getName()); + throw te; + } + context = (ExternalServiceContext) iContext; + } + ExternalJbiServiceClient client = (ExternalJbiServiceClient) context.getImplementationInstance(true); + if (payload != null) { + return client.invoke(method, (Object[])payload); + } else { + return client.invoke(method, null); + } + } + + public boolean isCacheable() { + return false; + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } catch (Throwable e) { + msg.setBody(e); + } + return msg; + } + + public void setNext(Interceptor next) { + throw new UnsupportedOperationException(); + } + + public Object clone() { + try { + ExternalJbiServiceTargetInvoker invoker = (ExternalJbiServiceTargetInvoker) super.clone(); + invoker.container = container; + invoker.context = this.context; + invoker.esName = this.esName; + invoker.method = this.method; + invoker.serviceName = this.serviceName; + return invoker; + } catch (CloneNotSupportedException e) { + return null; // will not happen + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java new file mode 100644 index 0000000000..ac67433720 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java @@ -0,0 +1,75 @@ +/* + * 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.servicemix.sca.loader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.servicemix.sca.assembly.JbiAssemblyFactory; +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.servicemix.sca.assembly.impl.JbiAssemblyFactoryImpl; +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.core.config.ConfigurationLoadException; +import org.apache.tuscany.core.loader.StAXElementLoader; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.system.annotation.Autowire; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("MODULE") +public class JbiBindingLoader implements StAXElementLoader{ + + public static final QName BINDING_JBI = new QName("http://www.osoa.org/xmlns/sca/0.9", "binding.jbi"); + + private static final JbiAssemblyFactory jbiFactory = new JbiAssemblyFactoryImpl(); + + private StAXLoaderRegistry registry; + + @Autowire + public void setRegistry(StAXLoaderRegistry registry) { + this.registry = registry; + } + + @Init(eager = true) + public void start() { + registry.registerLoader(this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(this); + } + + public QName getXMLType() { + return BINDING_JBI; + } + + public Class getModelType() { + return JbiBinding.class; + } + + public JbiBinding load(XMLStreamReader reader, ResourceLoader resourceLoader) throws XMLStreamException, ConfigurationLoadException { + JbiBinding binding = jbiFactory.createJbiBinding(); + binding.setURI(reader.getAttributeValue(null, "uri")); + binding.setPortURI(reader.getAttributeValue(null, "port")); + return binding; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java new file mode 100644 index 0000000000..154afe4377 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java @@ -0,0 +1,125 @@ +/* + * 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.servicemix.sca.tuscany; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.config.ConfigurationException; +import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader; +import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl; +import org.apache.tuscany.core.config.impl.StAXModuleComponentConfigurationLoaderImpl; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.SystemAggregateContext; +import org.apache.tuscany.core.loader.StAXLoaderRegistry; +import org.apache.tuscany.core.loader.StAXUtil; +import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; +import org.apache.tuscany.core.system.builder.SystemContextFactoryBuilder; +import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder; +import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder; +import org.apache.tuscany.core.system.loader.SystemSCDLModelLoader; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.ModuleComponent; +import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl; +import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader; +import org.apache.tuscany.model.scdl.loader.SCDLModelLoader; +import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl; + +public class BootstrapHelper { + + /** + * Returns a default AssemblyModelContext. + * + * @param classLoader the classloader to use for application artifacts + * @return a default AssemblyModelContext + */ + public static AssemblyModelContext getModelContext(ClassLoader classLoader) { + // Create an assembly model factory + AssemblyFactory modelFactory = new SystemAssemblyFactoryImpl(); + + // Create a default assembly model loader + List scdlLoaders = new ArrayList(); + scdlLoaders.add(new SystemSCDLModelLoader()); + AssemblyModelLoader modelLoader = new SCDLAssemblyModelLoaderImpl(scdlLoaders); + + // Create a resource loader from the supplied classloader + ResourceLoader resourceLoader = new ResourceLoaderImpl(classLoader); + + // Create an assembly model context + return new AssemblyModelContextImpl(modelFactory, modelLoader, resourceLoader); + } + + /** + * Returns a default list of configuration builders. + * + * @return a default list of configuration builders + */ + public static List getBuilders() { + List configBuilders = new ArrayList(); + configBuilders.add((new SystemContextFactoryBuilder())); + configBuilders.add(new SystemEntryPointBuilder()); + configBuilders.add(new SystemExternalServiceBuilder()); + return configBuilders; + } + + private static final boolean useStax = true; + private static final String SYSTEM_LOADER_COMPONENT = "tuscany.loader"; + + /** + * Returns the default module configuration loader. + * + * @param systemContext the runtime's system context + * @param modelContext the model context the loader will use + * @return the default module configuration loader + */ + public static ModuleComponentConfigurationLoader getConfigurationLoader(SystemAggregateContext systemContext, AssemblyModelContext modelContext) throws ConfigurationException { + if (useStax) { + // Bootstrap the StAX loader module + bootstrapStaxLoader(systemContext, modelContext); + return new StAXModuleComponentConfigurationLoaderImpl(modelContext, XMLInputFactory.newInstance(), systemContext.resolveInstance(StAXLoaderRegistry.class)); + } else { + return new ModuleComponentConfigurationLoaderImpl(modelContext); + } + } + + private static AggregateContext bootstrapStaxLoader(SystemAggregateContext systemContext, AssemblyModelContext modelContext) throws ConfigurationException { + AggregateContext loaderContext = (AggregateContext) systemContext.getContext(SYSTEM_LOADER_COMPONENT); + if (loaderContext == null) { + ModuleComponent loaderComponent = StAXUtil.bootstrapLoader(SYSTEM_LOADER_COMPONENT, modelContext); + loaderContext = registerModule(systemContext, loaderComponent); + loaderContext.fireEvent(EventContext.MODULE_START, null); + } + return loaderContext; + } + + public static AggregateContext registerModule(AggregateContext parent, ModuleComponent component) throws ConfigurationException { + // register the component + parent.registerModelObject(component); + + // Get the aggregate context representing the component + return (AggregateContext) parent.getContext(component.getName()); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java new file mode 100644 index 0000000000..04bcc0bcea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java @@ -0,0 +1,90 @@ +/* + * 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.servicemix.sca.tuscany; + +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.common.monitor.MonitorFactory; + +public class CommonsLoggingMonitorFactory implements MonitorFactory { + + private final Map, WeakReference> proxies = new WeakHashMap, WeakReference>(); + + public CommonsLoggingMonitorFactory() { + } + + public T getMonitor(Class monitorInterface) { + T proxy = getCachedMonitor(monitorInterface); + if (proxy == null) { + proxy = createMonitor(monitorInterface); + proxies.put(monitorInterface, new WeakReference(proxy)); + } + return proxy; + } + + private T getCachedMonitor(Class monitorInterface) { + WeakReference ref = (WeakReference) proxies.get(monitorInterface); + return (ref != null) ? ref.get() : null; + } + + private T createMonitor(Class monitorInterface) { + String className = monitorInterface.getName(); + Log logger = LogFactory.getLog(className); + InvocationHandler handler = new LoggingHandler(logger); + return (T) Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class[]{monitorInterface}, handler); + } + + private static final class LoggingHandler implements InvocationHandler { + private final Log logger; + + public LoggingHandler(Log logger) { + this.logger = logger; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + String sourceMethod = method.getName(); + if (logger.isDebugEnabled()) { + // if the only argument is a Throwable use the special logger for it + if (args != null && args.length == 1 && args[0] instanceof Throwable) { + logger.debug(sourceMethod, (Throwable) args[0]); + } else { + StringBuilder sb = new StringBuilder(); + sb.append(sourceMethod); + sb.append("("); + for (int i = 0; i < args.length; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append(args[i]); + } + sb.append(")"); + logger.debug(sb.toString()); + } + } + return null; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java new file mode 100644 index 0000000000..ee5960dfb5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java @@ -0,0 +1,174 @@ +/* + * 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.servicemix.sca.tuscany; + +import java.util.List; + +import org.apache.tuscany.common.monitor.MonitorFactory; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.core.builder.ContextFactoryBuilder; +import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; +import org.apache.tuscany.core.config.ConfigurationException; +import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader; +import org.apache.tuscany.core.context.AggregateContext; +import org.apache.tuscany.core.context.CoreRuntimeException; +import org.apache.tuscany.core.context.EventContext; +import org.apache.tuscany.core.context.SystemAggregateContext; +import org.apache.tuscany.core.runtime.RuntimeContext; +import org.apache.tuscany.core.runtime.RuntimeContextImpl; +import org.apache.tuscany.model.assembly.AssemblyModelContext; +import org.apache.tuscany.model.assembly.ModuleComponent; +import org.apache.tuscany.model.scdl.loader.SCDLModelLoader; +import org.osoa.sca.ModuleContext; +import org.osoa.sca.SCA; +import org.osoa.sca.ServiceRuntimeException; + +public class TuscanyRuntime extends SCA { + private final TuscanyRuntime.Monitor monitor; + private final Object sessionKey = new Object(); + + private final RuntimeContext runtime; + private final AggregateContext moduleContext; + + private final ModuleComponent moduleComponent; + + private static final String SYSTEM_MODULE_COMPONENT = "org.apache.tuscany.core.system"; + + /** + * Construct a runtime using a null MonitorFactory. + * + * @param name the name of the module component + * @param uri the URI to assign to the module component + * @throws ConfigurationException if there was a problem loading the SCA configuration + * @see TuscanyRuntime#TuscanyRuntime(String, String, org.apache.tuscany.common.monitor.MonitorFactory) + */ + public TuscanyRuntime(String name, String uri) throws ConfigurationException { + this(name, uri, + Thread.currentThread().getContextClassLoader(), + new NullMonitorFactory()); + } + + /** + * Construct a runtime containing a single module component with the + * specified name. The module definition is loaded from a "/sca.module" + * resource found on the classpath of the current Thread context classloader. + * + * @param name the name of the module component + * @param uri the URI to assign to the module component + * @param classLoader the class loader to use for the assembly + * @param monitorFactory the MonitorFactory for this runtime + * @throws ConfigurationException if there was a problem loading the SCA configuration + */ + public TuscanyRuntime(String name, String uri, ClassLoader classLoader, MonitorFactory monitorFactory) throws ConfigurationException { + this.monitor = monitorFactory.getMonitor(TuscanyRuntime.Monitor.class); + + // Create an assembly model context + AssemblyModelContext modelContext = BootstrapHelper.getModelContext(classLoader); + + // Create a runtime context and start it + List loaders = modelContext.getAssemblyLoader().getLoaders(); + List configBuilders = BootstrapHelper.getBuilders(); + runtime = new RuntimeContextImpl(monitorFactory, loaders, configBuilders, new DefaultWireBuilder()); + runtime.start(); + monitor.started(runtime); + + // Load and start the system configuration + SystemAggregateContext systemContext = runtime.getSystemContext(); + ModuleComponentConfigurationLoader loader = BootstrapHelper.getConfigurationLoader(systemContext, modelContext); + ModuleComponent systemModuleComponent = loader.loadSystemModuleComponent(SYSTEM_MODULE_COMPONENT, SYSTEM_MODULE_COMPONENT); + AggregateContext context = BootstrapHelper.registerModule(systemContext, systemModuleComponent); + context.fireEvent(EventContext.MODULE_START, null); + + // Load the SCDL configuration of the application module + AggregateContext rootContext = runtime.getRootContext(); + moduleComponent = loader.loadModuleComponent(name, uri); + moduleContext = BootstrapHelper.registerModule(rootContext, moduleComponent); + } + + public ModuleComponent getModuleComponent() { + return moduleComponent; + } + + public AggregateContext getModuleContext() { + return moduleContext; + } + + /** + * Start the runtime and associate the module context with the calling thread. + */ + @Override + public void start() { + setModuleContext((ModuleContext) moduleContext); + try { + //moduleContext.start(); + moduleContext.fireEvent(EventContext.MODULE_START, null); + moduleContext.fireEvent(EventContext.REQUEST_START, null); + moduleContext.fireEvent(EventContext.SESSION_NOTIFY, sessionKey); + monitor.started(moduleContext); + } catch (CoreRuntimeException e) { + setModuleContext(null); + monitor.startFailed(moduleContext, e); + //FIXME throw a better exception + throw new ServiceRuntimeException(e); + } + } + + /** + * Disassociate the module context from the current thread and shut down the runtime. + */ + @Override + public void stop() { + setModuleContext(null); + moduleContext.fireEvent(EventContext.REQUEST_END, null); + moduleContext.fireEvent(EventContext.SESSION_END, sessionKey); + moduleContext.fireEvent(EventContext.MODULE_STOP, null); + moduleContext.stop(); + monitor.stopped(moduleContext); + runtime.stop(); + monitor.stopped(runtime); + } + + /** + * Monitor interface for a TuscanyRuntime. + */ + public static interface Monitor { + /** + * Event emitted after the runtime has been started. + * + * @param ctx the runtime's module component context + */ + void started(AggregateContext ctx); + + /** + * Event emitted when an attempt to start the runtime failed. + * + * @param ctx the runtime's module component context + * @param e the exception that caused the failure + */ + void startFailed(AggregateContext ctx, CoreRuntimeException e); + + /** + * Event emitted after the runtime has been stopped. + * + * @param ctx the runtime's module component context + */ + void stopped(AggregateContext ctx); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java new file mode 100644 index 0000000000..04781d6d69 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.servicemix; + +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a JBI binding + */ +public class JBIBinding extends Binding { + + private String uri; + + private String port; + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java new file mode 100644 index 0000000000..8b6806a731 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java @@ -0,0 +1,63 @@ +/* + * 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.tuscany.servicemix; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; +import org.osoa.sca.annotations.Scope; + +/** + * Loader for handling elements. + */ +@Scope("MODULE") +public class JBIBindingLoader extends LoaderExtension { + + public static final QName BINDING_JBI = new QName("http://tuscany.apache.org/xmlns/binding/rmi/1.0-SNAPSHOT", "binding.jbi"); + + public JBIBindingLoader(@Autowire LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return BINDING_JBI; + } + + public JBIBinding load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext) throws XMLStreamException, + LoaderException { + + String port = reader.getAttributeValue(null, "port"); + String uri = reader.getAttributeValue(null, "uri"); + LoaderUtil.skipToEndElement(reader); + + JBIBinding binding = new JBIBinding(); + binding.setPort(port); + binding.setURI(uri); + + return binding; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java new file mode 100644 index 0000000000..227d56d0b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java @@ -0,0 +1,57 @@ +/* + * 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 pejbissions and limitations + * under the License. + */ +package org.apache.tuscany.servicemix; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; + +/** + * Builds a Service or Reference for a JBI binding. + */ +public class ServiceMixBuilder extends BindingBuilderExtension { + + protected Class getBindingType() { + return JBIBinding.class; + } + + @SuppressWarnings( { "unchecked" }) + public SCAObject build(CompositeComponent parent, BoundServiceDefinition boundServiceDefinition, DeploymentContext deploymentContext) { + + String name = boundServiceDefinition.getName(); + + ServiceMixService serviceMixService = new ServiceMixService(name, parent, wireService, null); + + return serviceMixService; + } + + @SuppressWarnings( { "unchecked" }) + public ServiceMixReference build(CompositeComponent parent, BoundReferenceDefinition boundReferenceDefinition, + DeploymentContext deploymentContext) { + + + ServiceMixReference serviceMixReference = new ServiceMixReference(null, parent, wireService, null, null); + + return serviceMixReference; + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java new file mode 100644 index 0000000000..5ad2aae7b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java @@ -0,0 +1,77 @@ +/* + * 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.tuscany.servicemix; + +import java.lang.reflect.InvocationTargetException; + +import javax.jbi.messaging.DeliveryChannel; +import javax.jbi.messaging.ExchangeStatus; +import javax.jbi.messaging.InOut; +import javax.jbi.messaging.MessagingException; +import javax.jbi.messaging.NormalizedMessage; +import javax.xml.namespace.QName; + +import org.apache.servicemix.jbi.jaxp.StringSource; +import org.apache.servicemix.sca.ScaServiceUnit; +import org.apache.tuscany.spi.extension.TargetInvokerExtension; + +/** + * Invoke a JBI reference. + */ +public class ServiceMixInvoker extends TargetInvokerExtension { + + private QName serviceName; + + private ScaServiceUnit serviceUnit; + + public ServiceMixInvoker(QName serviceName) { + this.serviceName = serviceName; + this.serviceUnit = ScaServiceUnit.getCurrentScaServiceUnit(); + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + try { + DeliveryChannel channel = serviceUnit.getComponent().getComponentContext().getDeliveryChannel(); + + // TODO: in-only case ? + // TODO: interface based routing ? + // TODO: explicit endpoint selection ? + + InOut inout = channel.createExchangeFactory().createInOutExchange(); + inout.setService(serviceName); + NormalizedMessage in = inout.createMessage(); + inout.setInMessage(in); + in.setContent(new StringSource(payload.toString())); + + boolean sent = channel.sendSync(inout); + // TODO: check for error ? + + NormalizedMessage out = inout.getOutMessage(); + Object response = out.getContent(); + inout.setStatus(ExchangeStatus.DONE); + channel.send(inout); + + return response; + + } catch (MessagingException e) { + throw new InvocationTargetException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java new file mode 100644 index 0000000000..e9898f8f15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.servicemix; + +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ReferenceExtension; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; + +/** + * + */ +public class ServiceMixReference extends ReferenceExtension { + + private final String uri; + + public ServiceMixReference(String name, + CompositeComponent parent, + WireService wireService, + String uri, + Class service) + { + super(name, service, parent, wireService); + setInterface(service); + this.uri = uri; + } + + public TargetInvoker createTargetInvoker(Method arg0) { + QName serviceName = null; + ServiceMixInvoker invoker = new ServiceMixInvoker(serviceName); + return invoker; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java new file mode 100644 index 0000000000..ae7e9e3f1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java @@ -0,0 +1,42 @@ +/* + * 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.tuscany.servicemix; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.wire.WireService; + +/** + * + */ +public class ServiceMixService extends ServiceExtension { + + public ServiceMixService(String name, CompositeComponent parent, WireService wireService, Class service) { + super(name, service, parent, wireService); + } + + public void start() { + super.start(); + } + + public void stop() { + super.stop(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/DISCLAIMER b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/DISCLAIMER new file mode 100644 index 0000000000..14eddf5d92 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/DISCLAIMER @@ -0,0 +1,6 @@ +Apache ServiceMix is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Geronimo PMC. +Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, +communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. + +While incubation status is not necessarily a reflection of the completeness or stability of the code, it does +indicate that the project has yet to be fully endorsed by the ASF. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/LICENSE b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/LICENSE new file mode 100644 index 0000000000..6b0b1270ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/NOTICE b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/NOTICE new file mode 100644 index 0000000000..c035229231 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/main/jbi/META-INF/NOTICE @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache ServiceMix distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Additional copyright notices and license terms applicable are + present in the licenses directory of this distribution. diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java new file mode 100644 index 0000000000..2edf9882ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java @@ -0,0 +1,74 @@ +/* + * 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.servicemix.sca; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.servicemix.sca.assembly.JbiBinding; +import org.apache.servicemix.sca.tuscany.TuscanyRuntime; +import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; +import org.apache.tuscany.model.assembly.Binding; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Module; + +/** + * @author delfinoj + */ +public class AssemblyLoaderTest extends TestCase { + + protected void setUp() throws Exception { + super.setUp(); + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + } + + public void testLoader() throws Exception { + String name = "bigbank"; + String uri = getClass().getResource("bigbank/sca.module").toString(); + + URL url = getClass().getResource("bigbank/sca.module"); + URL parentUrl = new File(url.toURI()).getParentFile().toURL(); + ClassLoader cl = new URLClassLoader(new URL[] { parentUrl }, getClass().getClassLoader()); + + TuscanyRuntime rt = new TuscanyRuntime(name, uri, cl, new NullMonitorFactory()); + assertNotNull(rt); + + Module module = rt.getModuleComponent().getModuleImplementation(); + + Assert.assertTrue(module.getName().equals("org.apache.servicemix.sca.bigbank")); + + Component component = module.getComponent("AccountServiceComponent"); + Assert.assertTrue(component != null); + + EntryPoint entryPoint = module.getEntryPoint("AccountService"); + Assert.assertTrue(entryPoint != null); + + ExternalService externalService = module.getExternalService("StockQuoteService"); + Assert.assertTrue(externalService != null); + + Binding binding = externalService.getBindings().get(0); + Assert.assertTrue(binding instanceof JbiBinding); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java new file mode 100644 index 0000000000..bd6c4b3e88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java @@ -0,0 +1,110 @@ +/* + * 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.servicemix.sca; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.net.URL; + +import javax.naming.InitialContext; +import javax.xml.bind.JAXBContext; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.servicemix.client.DefaultServiceMixClient; +import org.apache.servicemix.client.ServiceMixClient; +import org.apache.servicemix.components.util.MockServiceComponent; +import org.apache.servicemix.jbi.container.ActivationSpec; +import org.apache.servicemix.jbi.container.JBIContainer; +import org.apache.servicemix.jbi.jaxp.SourceTransformer; +import org.apache.servicemix.jbi.jaxp.StringSource; +import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver; +import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteResponse; +import org.w3c.dom.Node; + +public class ScaComponentTest extends TestCase { + + private static Log log = LogFactory.getLog(ScaComponentTest.class); + + protected JBIContainer container; + + protected void setUp() throws Exception { + container = new JBIContainer(); + container.setUseMBeanServer(false); + container.setCreateMBeanServer(false); + container.setMonitorInstallationDirectory(false); + container.setNamingContext(new InitialContext()); + container.setEmbedded(true); + container.init(); + } + + protected void tearDown() throws Exception { + if (container != null) { + container.shutDown(); + } + } + + public void testDeploy() throws Exception { + ScaComponent component = new ScaComponent(); + container.activateComponent(component, "JSR181Component"); + + MockServiceComponent mock = new MockServiceComponent(); + mock.setService(new QName("http://www.quickstockquote.com", "StockQuoteService")); + mock.setEndpoint("StockQuoteServiceJBI"); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + StockQuoteResponse r = new StockQuoteResponse(); + r.setResult(8.23f); + JAXBContext.newInstance(StockQuoteResponse.class).createMarshaller().marshal(r, baos); + mock.setResponseXml(baos.toString()); + ActivationSpec as = new ActivationSpec(); + as.setComponent(mock); + container.activateComponent(as); + + // Start container + container.start(); + + // Deploy SU + component.getServiceUnitManager().deploy("su", getServiceUnitPath("org/apache/servicemix/sca/bigbank")); + component.getServiceUnitManager().init("su", getServiceUnitPath("org/apache/servicemix/sca/bigbank")); + component.getServiceUnitManager().start("su"); + + ServiceMixClient client = new DefaultServiceMixClient(container); + Source req = new StringSource("id"); + Object rep = client.request(new ServiceNameEndpointResolver( + new QName("http://sca.servicemix.apache.org/Bigbank/Account", "AccountService")), + null, null, req); + if (rep instanceof Node) { + rep = new DOMSource((Node) rep); + } + log.info(new SourceTransformer().toString((Source) rep)); + } + + protected String getServiceUnitPath(String name) { + URL url = getClass().getClassLoader().getResource(name + "/sca.module"); + File path = new File(url.getFile()); + path = path.getParentFile(); + return path.getAbsolutePath(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportRequest.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportRequest.java new file mode 100644 index 0000000000..00c55aeffc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportRequest.java @@ -0,0 +1,43 @@ +/* + * 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.servicemix.sca.bigbank.account; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "customerID" }) +@XmlRootElement(name = "AccountReportRequest") +public class AccountReportRequest { + + @XmlElement(name = "CustomerID") + private String customerID; + + public String getCustomerID() { + return customerID; + } + + public void setCustomerID(String customerID) { + this.customerID = customerID; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportResponse.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportResponse.java new file mode 100644 index 0000000000..f52985d2c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountReportResponse.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 org.apache.servicemix.sca.bigbank.account; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "accountSummaries" }) +@XmlRootElement(name = "AccountReportResponse") +public class AccountReportResponse { + + @XmlElement(name = "AccountSummaries") + private List accountSummaries; + + public List getAccountSummaries() { + return accountSummaries; + } + + public void setAccountSummaries(List accountSummaries) { + this.accountSummaries = accountSummaries; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.java new file mode 100644 index 0000000000..5c2997f2c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.java @@ -0,0 +1,27 @@ +/* + * 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.servicemix.sca.bigbank.account; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface AccountService { + + public AccountReportResponse getAccountReport(AccountReportRequest request); +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java new file mode 100644 index 0000000000..f0cad13f5c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java @@ -0,0 +1,93 @@ +/* + * 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.servicemix.sca.bigbank.account; + +import java.util.ArrayList; + +import org.apache.servicemix.sca.bigbank.accountdata.AccountDataService; +import org.apache.servicemix.sca.bigbank.accountdata.CheckingAccount; +import org.apache.servicemix.sca.bigbank.accountdata.SavingsAccount; +import org.apache.servicemix.sca.bigbank.accountdata.StockAccount; +import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteRequest; +import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteResponse; +import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteService; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(interfaces=AccountService.class) +public class AccountServiceImpl implements AccountService { + + @Property + public String currency = "USD"; + + @Reference + public AccountDataService accountDataService; + @Reference + public StockQuoteService stockQuoteService; + + public AccountServiceImpl() { + } + + public AccountReportResponse getAccountReport(AccountReportRequest request) { + AccountReportResponse report = new AccountReportResponse(); + String customerID = request.getCustomerID(); + report.setAccountSummaries(new ArrayList()); + report.getAccountSummaries().add(getCheckAccountSummary(customerID)); + report.getAccountSummaries().add(getSavingsAccountSummary(customerID)); + report.getAccountSummaries().add(getStockAccountSummary(customerID)); + return report; + } + + private AccountSummary getCheckAccountSummary(String customerID) { + CheckingAccount checking = accountDataService.getCheckingAccount(customerID); + AccountSummary summary = new AccountSummary(); + summary.setAccountNumber(checking.getAccountNumber()); + summary.setAccountType("Checking"); + summary.setBalance(checking.getBalance()); + return summary; + } + + private AccountSummary getSavingsAccountSummary(String customerID) { + SavingsAccount savings = accountDataService.getSavingsAccount(customerID); + AccountSummary summary = new AccountSummary(); + summary.setAccountNumber(savings.getAccountNumber()); + summary.setAccountType("Savings"); + summary.setBalance(savings.getBalance()); + return summary; + } + + private AccountSummary getStockAccountSummary(String customerID) { + StockAccount stock = accountDataService.getStockAccount(customerID); + AccountSummary summary = new AccountSummary(); + summary.setAccountNumber(stock.getAccountNumber()); + summary.setAccountType("Stock"); + float quote = getQuote(stock.getSymbol()); + summary.setBalance(quote * stock.getQuantity()); + return summary; + } + + private float getQuote(String symbol) { + StockQuoteRequest req = new StockQuoteRequest(); + req.setSymbol(symbol); + StockQuoteResponse rep = stockQuoteService.getQuote(req); + return rep.getResult(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountSummary.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountSummary.java new file mode 100644 index 0000000000..f6e5a060af --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountSummary.java @@ -0,0 +1,68 @@ +/* + * 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.servicemix.sca.bigbank.account; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "accountNumber", "accountType", "balance" }) +@XmlRootElement(name = "AccountSummary") +public class AccountSummary { + + @XmlElement(name = "AccountNumber") + private String accountNumber; + + @XmlElement(name = "AccountType") + private String accountType; + + @XmlElement(name = "Balance") + private float balance; + + public AccountSummary() { + } + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public String getAccountType() { + return accountType; + } + + public void setAccountType(String accountType) { + this.accountType = accountType; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataService.java new file mode 100644 index 0000000000..972b9dc704 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataService.java @@ -0,0 +1,28 @@ +/* + * 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.servicemix.sca.bigbank.accountdata; + +public interface AccountDataService { + + CheckingAccount getCheckingAccount(String customerID); + + SavingsAccount getSavingsAccount(String customerID); + + StockAccount getStockAccount(String customerID); +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..f9d0c08df7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/AccountDataServiceImpl.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 org.apache.servicemix.sca.bigbank.accountdata; + +public class AccountDataServiceImpl implements AccountDataService { + + public CheckingAccount getCheckingAccount(String customerID) { + + CheckingAccount checkingAccount = new CheckingAccount(); + checkingAccount.setAccountNumber(customerID + "_" + "CHA12345"); + checkingAccount.setBalance(1500.0f); + + return checkingAccount; + } + + public SavingsAccount getSavingsAccount(String customerID) { + + SavingsAccount savingsAccount = new SavingsAccount(); + savingsAccount.setAccountNumber(customerID + "_" + "SAA12345"); + savingsAccount.setBalance(1500.0f); + + return savingsAccount; + } + + public StockAccount getStockAccount(String customerID) { + + StockAccount stockAccount = new StockAccount(); + stockAccount.setAccountNumber(customerID + "_" + "STA12345"); + stockAccount.setSymbol("IBM"); + stockAccount.setQuantity(100); + + return stockAccount; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/CheckingAccount.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/CheckingAccount.java new file mode 100644 index 0000000000..596dcc8d06 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/CheckingAccount.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.servicemix.sca.bigbank.accountdata; + +public class CheckingAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/SavingsAccount.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/SavingsAccount.java new file mode 100644 index 0000000000..c208788ca8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/SavingsAccount.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.servicemix.sca.bigbank.accountdata; + +public class SavingsAccount { + + private String accountNumber; + private float balance; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public float getBalance() { + return balance; + } + + public void setBalance(float balance) { + this.balance = balance; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/StockAccount.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/StockAccount.java new file mode 100644 index 0000000000..1005bceb91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/accountdata/StockAccount.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 org.apache.servicemix.sca.bigbank.accountdata; + +public class StockAccount { + + private String accountNumber; + private String symbol; + private int quantity; + + public String getAccountNumber() { + return accountNumber; + } + + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteRequest.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteRequest.java new file mode 100644 index 0000000000..4f12b18601 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteRequest.java @@ -0,0 +1,43 @@ +/* + * 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.servicemix.sca.bigbank.stockquote; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "symbol" }) +@XmlRootElement(name = "StockQuoteRequest") +public class StockQuoteRequest { + + @XmlElement(name = "Symbol") + private String symbol; + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteResponse.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteResponse.java new file mode 100644 index 0000000000..bf2d7c7c00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteResponse.java @@ -0,0 +1,43 @@ +/* + * 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.servicemix.sca.bigbank.stockquote; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { "result" }) +@XmlRootElement(name = "StockQuoteResponse") +public class StockQuoteResponse { + + @XmlElement(name = "Result") + private float result; + + public float getResult() { + return result; + } + + public void setResult(float result) { + this.result = result; + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteService.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..3fa1558907 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/java/org/apache/servicemix/sca/bigbank/stockquote/StockQuoteService.java @@ -0,0 +1,29 @@ +/* + * 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.servicemix.sca.bigbank.stockquote; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface StockQuoteService { + + public StockQuoteResponse getQuote(StockQuoteRequest stockQuote); +} + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j-tests.properties b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j-tests.properties new file mode 100644 index 0000000000..ec53858ed2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j-tests.properties @@ -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. +# +# The logging properties used during tests.. +# +log4j.rootLogger=DEBUG, out + +log4j.logger.org.apache.activemq=INFO +log4j.logger.org.apache.activemq.spring=WARN +log4j.logger.org.apache.activemq.store.journal=INFO +log4j.logger.org.activeio.journal=INFO + +# CONSOLE appender not used by default +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.out=org.apache.log4j.FileAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.out.file=target/servicemix-test.log +log4j.appender.out.append=true diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j.properties b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j.properties new file mode 100644 index 0000000000..992c894051 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/log4j.properties @@ -0,0 +1,39 @@ +# +# 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. +# +# +# The logging properties used during tests.. +# +log4j.rootLogger=DEBUG, stdout + +log4j.logger.org.apache.activemq=INFO +log4j.logger.org.apache.activemq.spring=WARN +log4j.logger.org.apache.activemq.store.journal=INFO +log4j.logger.org.activeio.journal=INFO + +# CONSOLE appender not used by default +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.out=org.apache.log4j.FileAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.out.file=target/servicemix-test.log +log4j.appender.out.append=true diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl new file mode 100644 index 0000000000..9797a5739c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module new file mode 100644 index 0000000000..ae520dd54e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.servicemix/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module @@ -0,0 +1,56 @@ + + + + + + + + + AccountServiceComponent + + + + + + EURO + + + AccountDataServiceComponent + StockQuoteService + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/pom.xml new file mode 100644 index 0000000000..8b255c7b2f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/pom.xml @@ -0,0 +1,63 @@ + + + + + + org.apache.tuscany.sca.services + parent + 1.0-incubator-M2-SNAPSHOT + + + 4.0.0 + org.apache.tuscany.sca.services.bindings + parent + pom + Tuscany SCA Bindings + + + + full + + true + + + + + sunjars + binding.celtix + binding.axis2 + binding.jsonrpc + binding.rmi + + + + release + + false + + + binding.axis2 + binding.rmi + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/build.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/build.xml new file mode 100644 index 0000000000..e6fec45356 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/build.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/pom.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/pom.xml new file mode 100644 index 0000000000..d227956013 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/sunjars/pom.xml @@ -0,0 +1,102 @@ + + + + + org.apache.tuscany.sca.services.bindings + parent + 1.0-incubator-M2-SNAPSHOT + + 4.0.0 + sunjars + pom + Project to install the Sun jars + + + 1.0 + + + + objectweb + ObjectWeb repo + http://maven.objectweb.org/maven2 + + true + + + false + + + + + + + + + org.codehaus.mojo + dependency-maven-plugin + + + getdeps + validate + + unpack + + + ${project.build.directory}/celtix-install + + + org.objectweb.celtix + celtix-distribution + ${celtix.version} + bin-epl + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + install + install + + run + + + + + + + + + + + + + + + -- cgit v1.2.3