diff options
Diffstat (limited to '')
26 files changed, 1700 insertions, 0 deletions
diff --git a/sandbox/old/contrib/binding-hessian/binding/LICENSE.txt b/sandbox/old/contrib/binding-hessian/binding/LICENSE.txt new file mode 100755 index 0000000000..0084319535 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/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/sandbox/old/contrib/binding-hessian/binding/NOTICE.txt b/sandbox/old/contrib/binding-hessian/binding/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/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/sandbox/old/contrib/binding-hessian/binding/pom.xml.off b/sandbox/old/contrib/binding-hessian/binding/pom.xml.off new file mode 100755 index 0000000000..8c34615f7f --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/pom.xml.off @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + + <parent> + <groupId>org.apache.tuscany.sca.hessian</groupId> + <artifactId>hessian</artifactId> + <version>2.0-alpha2-incubating-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.hessian</groupId> + <artifactId>hessian-binding</artifactId> + <version>2.0-alpha2-incubating-SNAPSHOT</version> + <name>Apache Tuscany Hessian Binding</name> + <description></description> + <packaging>jar</packaging> +</project> diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Channel.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Channel.java new file mode 100644 index 0000000000..45b108e4b4 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Channel.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.hessian; + +import org.apache.tuscany.spi.wire.Message; + +/** + * Channels dispatch service invocations over a transport + * + * @version $Rev$ $Date$ + */ +public interface Channel { + + /** + * Dispatches the service invocation + * + * @param operation the service operation to invoke + * @param returnType the expected return type or null + * @param message the message containing the invocation payload + * @return the response message + * @throws InvocationException if an error occurs during the invocation + */ + Message send(String operation, Class<?> returnType, Message message) throws InvocationException; + + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Destination.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Destination.java new file mode 100644 index 0000000000..a7622f86e8 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/Destination.java @@ -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. + */ +package org.apache.tuscany.hessian; + +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; + +/** + * Responsible for receiving invocations for a service endpoint from a transport + * + * @version $Rev$ $Date$ + */ +public interface Destination { + + /** + * Dispatches to the service endpoint + * + * @param in the input stream containing the invocation payload + * @param out the output stream to write the response to + * @throws InvocationException if an error occurs invoking the service + */ + void invoke(AbstractHessianInput in, AbstractHessianOutput out) throws InvocationException; +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/DestinationCreationException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/DestinationCreationException.java new file mode 100644 index 0000000000..316920d6dd --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/DestinationCreationException.java @@ -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. + */ +package org.apache.tuscany.hessian; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Thrown when an error creating a destination is encountered + * + * @version $Rev$ $Date$ + */ +public abstract class DestinationCreationException extends WiringException { + + public DestinationCreationException(String message) { + super(message); + } + + protected DestinationCreationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/HessianException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/HessianException.java new file mode 100644 index 0000000000..fbde279be0 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/HessianException.java @@ -0,0 +1,51 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.tuscany.hessian; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Base checked exception for the Hessian binding extension + * + * @version $Rev$ $Date$ + */ +public abstract class HessianException extends TuscanyException { + protected HessianException() { + } + + protected HessianException(String message) { + super(message); + } + + protected HessianException(String message, String identifier) { + super(message, identifier); + } + + protected HessianException(String message, Throwable cause) { + super(message, cause); + } + + protected HessianException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected HessianException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvalidDestinationException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvalidDestinationException.java new file mode 100644 index 0000000000..aa116293c1 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvalidDestinationException.java @@ -0,0 +1,36 @@ +/* + * 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.hessian; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class InvalidDestinationException extends WiringException { + public InvalidDestinationException(String message, Throwable cause) { + super(message, null, null, cause); + } + + public InvalidDestinationException(String message, String identifier) { + super(message, identifier, null, null); + } + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvocationException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvocationException.java new file mode 100644 index 0000000000..7456d1baa8 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvocationException.java @@ -0,0 +1,46 @@ +/* + * 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.hessian; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Raised when an error performing a service invocation is encountered + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class InvocationException extends TuscanyException { + + public InvocationException(String message, String identifier) { + super(message, identifier); + } + + public InvocationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public InvocationException(String message, Throwable cause) { + super(message, cause); + } + + public InvocationException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvokerInterceptor.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvokerInterceptor.java new file mode 100644 index 0000000000..53eb5f46b3 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/InvokerInterceptor.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.hessian; + +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; + +/** + * Dispatches a service invocation to a Channel + * + * @version $Rev$ $Date$ + */ +public class InvokerInterceptor implements Interceptor { + private String operation; + private Channel channel; + + /** + * Creates the interceptor. + * + * @param operation the service operation the interceptor dispatches for + * @param channel the channel to dispatch to + */ + public InvokerInterceptor(String operation, Channel channel) { + this.operation = operation; + this.channel = channel; + } + + public boolean isOptimizable() { + return false; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + return channel.send(operation, null, msg); + } catch (InvocationException e) { + msg.setBodyWithFault(e); + return msg; + } + } + + public void setNext(Interceptor next) { + throw new IllegalStateException("This interceptor must be the last one in an target interceptor chain"); + } + + public Interceptor getNext() { + return null; + } + + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/ServletHostNotFoundException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/ServletHostNotFoundException.java new file mode 100644 index 0000000000..195642019e --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/ServletHostNotFoundException.java @@ -0,0 +1,28 @@ +package org.apache.tuscany.hessian;/* + * 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. + */ + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class ServletHostNotFoundException extends DestinationCreationException { + public ServletHostNotFoundException(String message) { + super(message); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/TypeNotFoundException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/TypeNotFoundException.java new file mode 100644 index 0000000000..a2d417ff58 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/TypeNotFoundException.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.hessian; + +/** + * Denotes a missing or not found type + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class TypeNotFoundException extends DestinationCreationException { + + public TypeNotFoundException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/HttpChannel.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/HttpChannel.java new file mode 100644 index 0000000000..e6077e8003 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/HttpChannel.java @@ -0,0 +1,220 @@ +/* + * 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.hessian.channel; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; + +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; + +import com.caucho.hessian.client.HessianRuntimeException; +import com.caucho.hessian.io.HessianInput; +import com.caucho.hessian.io.HessianOutput; +import org.apache.tuscany.hessian.Channel; +import org.apache.tuscany.hessian.InvocationException; + +/** + * A channel implementation that uses HTTP as the transport protocol + * + * @version $Rev$ $Date$ + */ +public class HttpChannel implements Channel { + private URL destinationUrl; + private boolean chunkedPost; + private String basicAuth; + private String user; + private String password; + private int readTimeout; + + public HttpChannel(URL url) { + this.destinationUrl = url; + } + + public Message send(String operation, Class<?> returnType, Message message) throws InvocationException { + URLConnection conn; + try { + conn = openConnection(destinationUrl); + } catch (IOException e) { + throw new InvocationException(e); + } + if (chunkedPost && conn instanceof HttpURLConnection) { + HttpURLConnection httpConn = (HttpURLConnection) conn; + httpConn.setChunkedStreamingMode(8 * 1024); + } + + OutputStream os; + try { + os = conn.getOutputStream(); + } catch (IOException e) { + throw new HessianRuntimeException(e); + } + + try { + HessianOutput out = new HessianOutput(os); + Object[] args; + Object payload = message.getBody(); + if (payload != null && !payload.getClass().isArray()) { + args = new Object[]{payload}; + } else { + args = (Object[]) payload; + } + out.call(operation, args); + out.flush(); + + InputStream is = null; + if (conn instanceof HttpURLConnection) { + HttpURLConnection httpConn = (HttpURLConnection) conn; + int code = httpConn.getResponseCode(); + if (code != 200) { + StringBuffer sb = new StringBuffer(); + int ch; + + try { + is = httpConn.getInputStream(); + + if (is != null) { + while ((ch = is.read()) >= 0) { + sb.append((char) ch); + } + + is.close(); + } + + is = httpConn.getErrorStream(); + if (is != null) { + while ((ch = is.read()) >= 0) { + sb.append((char) ch); + } + } + } catch (FileNotFoundException e) { + throw new InvocationException(e); + } catch (IOException e) { + if (is == null) { + throw new InvocationException("Invocation exception", String.valueOf(code), e); + } + } + + if (is != null) { + is.close(); + } + throw new InvocationException("Invocation exception", sb.toString()); + } + } + is = conn.getInputStream(); + + HessianInput in = new HessianInput(is); + // FIXME handle faults + Object reply = in.readReply(returnType); + Message msg = new MessageImpl(); + msg.setBody(reply); + return msg; + } catch (RuntimeException e) { + if (conn instanceof HttpURLConnection) { + ((HttpURLConnection) conn).disconnect(); + } + throw e; + } catch (Throwable e) { + if (conn instanceof HttpURLConnection) { + ((HttpURLConnection) conn).disconnect(); + } + + throw new InvocationException(e); + } + } + + protected URLConnection openConnection(URL url) throws IOException { + URLConnection conn = url.openConnection(); + + conn.setDoOutput(true); + + if (readTimeout > 0) { + conn.setReadTimeout(readTimeout); + } + + conn.setRequestProperty("Content-Type", "x-application/hessian"); + + if (basicAuth != null) + conn.setRequestProperty("Authorization", basicAuth); + else if (user != null && password != null) { + basicAuth = "Basic " + base64(user + ":" + password); + conn.setRequestProperty("Authorization", basicAuth); + } + + return conn; + } + + private String base64(String value) { + StringBuffer cb = new StringBuffer(); + + int i = 0; + for (i = 0; i + 2 < value.length(); i += 3) { + long chunk = (int) value.charAt(i); + chunk = (chunk << 8) + (int) value.charAt(i + 1); + chunk = (chunk << 8) + (int) value.charAt(i + 2); + + cb.append(encode(chunk >> 18)); + cb.append(encode(chunk >> 12)); + cb.append(encode(chunk >> 6)); + cb.append(encode(chunk)); + } + + if (i + 1 < value.length()) { + long chunk = (int) value.charAt(i); + chunk = (chunk << 8) + (int) value.charAt(i + 1); + chunk <<= 8; + + cb.append(encode(chunk >> 18)); + cb.append(encode(chunk >> 12)); + cb.append(encode(chunk >> 6)); + cb.append('='); + } else if (i < value.length()) { + long chunk = (int) value.charAt(i); + chunk <<= 16; + + cb.append(encode(chunk >> 18)); + cb.append(encode(chunk >> 12)); + cb.append('='); + cb.append('='); + } + + return cb.toString(); + } + + public static char encode(long d) { + d &= 0x3f; + if (d < 26) + return (char) (d + 'A'); + else if (d < 52) + return (char) (d + 'a' - 26); + else if (d < 62) + return (char) (d + '0' - 52); + else if (d == 62) + return '+'; + else + return '/'; + } + + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/LocalChannel.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/LocalChannel.java new file mode 100644 index 0000000000..783750940a --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/channel/LocalChannel.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.hessian.channel; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; + +import com.caucho.hessian.io.HessianInput; +import com.caucho.hessian.io.HessianOutput; +import org.apache.tuscany.hessian.Channel; +import org.apache.tuscany.hessian.InvocationException; +import org.apache.tuscany.hessian.destination.LocalDestination; + +/** + * A channel implementation that uses an in-VM transport + * + * @version $Rev$ $Date$ + */ +public class LocalChannel implements Channel { + private LocalDestination destination; + + public LocalChannel(LocalDestination destination) { + this.destination = destination; + } + + public Message send(String operation, Class<?> returnType, Message message) throws InvocationException { + Object payload = message.getBody(); + Object[] args; + if (payload != null && !payload.getClass().isArray()) { + args = new Object[]{payload}; + } else { + args = (Object[]) payload; + } + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + HessianOutput output = new HessianOutput(baos); + output.call(operation, args); + output.close(); + ByteArrayInputStream bas = new ByteArrayInputStream(baos.toByteArray()); + HessianInput input = new HessianInput(bas); + + ByteArrayOutputStream returnOutputStream = new ByteArrayOutputStream(); + HessianOutput returnOutput = new HessianOutput(returnOutputStream); + destination.invoke(input, returnOutput); + ByteArrayInputStream returnStream = new ByteArrayInputStream(returnOutputStream.toByteArray()); + HessianInput in = new HessianInput(returnStream); + // FIXME handle faults + Object reply = in.readReply(returnType); + Message msg = new MessageImpl(); + msg.setBody(reply); + return msg; + } catch (Throwable e) { + throw new InvocationException(e); + } + + + } + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/HessianBindingComponent.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/HessianBindingComponent.java new file mode 100644 index 0000000000..8ae69bfb46 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/HessianBindingComponent.java @@ -0,0 +1,112 @@ +/* + * 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.hessian.component; + +import java.net.MalformedURLException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.hessian.Channel; +import org.apache.tuscany.hessian.DestinationCreationException; +import org.apache.tuscany.hessian.InvalidDestinationException; +import org.apache.tuscany.hessian.InvokerInterceptor; +import org.apache.tuscany.hessian.ServletHostNotFoundException; +import org.apache.tuscany.hessian.channel.HttpChannel; +import org.apache.tuscany.hessian.channel.LocalChannel; +import org.apache.tuscany.hessian.destination.HttpDestination; +import org.apache.tuscany.hessian.destination.LocalDestination; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Wire; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * Binding component for hessian transport. + */ +public class HessianBindingComponent { + + public static String LOCAL_SCHEME = "hessianLocal"; + public static String HTTP_SCHEME = "http"; + private URI uri; + private ServletHost servletHost; + private Map<URI, LocalDestination> destinations; + + public HessianBindingComponent(@Property(name = "uri") + URI uri, @Reference(name = "servletHost") + ServletHost host) { + this.uri = uri; + this.servletHost = host; + destinations = new HashMap<URI, LocalDestination>(); + } + + public void createEndpoint(URI endpointUri, Wire wire, ClassLoader loader) throws DestinationCreationException { + if (LOCAL_SCHEME.equals(endpointUri.getScheme())) { + LocalDestination destination = new LocalDestination(wire, loader); + destinations.put(uri, destination); + } else if (HTTP_SCHEME.equals(endpointUri.getScheme())) { + if (servletHost == null) { + throw new ServletHostNotFoundException("ServletHost is was not found"); + } + HttpDestination destination = new HttpDestination(wire, loader); + // FIXME mapping + servletHost.registerMapping(endpointUri.getPath(), destination); + } else { + throw new UnsupportedOperationException("Unsupported scheme"); + } + } + + public void bindToEndpoint(URI endpointUri, Wire wire) throws InvalidDestinationException { + Channel channel = createChannel(endpointUri); + for (Map.Entry<PhysicalOperationDefinition, InvocationChain> entry : wire.getPhysicalInvocationChains() + .entrySet()) { + String name = entry.getKey().getName(); + InvokerInterceptor interceptor = new InvokerInterceptor(name, channel); + entry.getValue().addInterceptor(interceptor); + } + } + + /** + * Creates a Channel to the service at the given URI + * + * @param uri the service uri + * @return the channel + * @throws InvalidDestinationException if an error is encountered creating + * the channel + */ + private Channel createChannel(URI uri) throws InvalidDestinationException { + if (LOCAL_SCHEME.equals(uri.getScheme())) { + LocalDestination destination = destinations.get(uri); + if (destination != null) { + throw new InvalidDestinationException("Destination not found", uri.toString()); + } + return new LocalChannel(destination); + } else if (HTTP_SCHEME.equals(uri.getScheme())) { + try { + return new HttpChannel(uri.toURL()); + } catch (MalformedURLException e) { + throw new InvalidDestinationException("URI must be a valid URL ", e); + } + } + throw new UnsupportedOperationException("Unsupported scheme"); + } + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/WireBindException.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/WireBindException.java new file mode 100644 index 0000000000..5efbefeade --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/component/WireBindException.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.hessian.component; + +import org.apache.tuscany.hessian.HessianException; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class WireBindException extends HessianException { + + public WireBindException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/AbstractDestination.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/AbstractDestination.java new file mode 100644 index 0000000000..baae50677a --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/AbstractDestination.java @@ -0,0 +1,115 @@ +/* + * 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.hessian.destination; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; +import org.apache.tuscany.hessian.Destination; +import org.apache.tuscany.hessian.InvocationException; +import org.apache.tuscany.hessian.TypeNotFoundException; + +/** + * Base implementation of a Destination + * + * @version $Rev$ $Date$ + */ +public class AbstractDestination implements Destination { + protected Map<String, ChainHolder> chains; + private ClassLoader loader; + + protected AbstractDestination(Wire wire, ClassLoader loader) throws TypeNotFoundException { + this.loader = loader; + chains = new HashMap<String, ChainHolder>(); + for (Map.Entry<PhysicalOperationDefinition, InvocationChain> entry : wire.getPhysicalInvocationChains() + .entrySet()) { + PhysicalOperationDefinition operation = entry.getKey(); + String operationName = operation.getName(); + InvocationChain chain = entry.getValue(); + List<String> params = operation.getParameters(); + Class<?>[] paramTypes = new Class<?>[params.size()]; + // load the param types in the target's classloader + for (int i = 0; i < params.size(); i++) { + String param = params.get(i); + try { + paramTypes[i] = loader.loadClass(param); + } catch (ClassNotFoundException e) { + throw new TypeNotFoundException("Operation parameter type not found", operationName, e); + } + } + AbstractDestination.ChainHolder holder = + new AbstractDestination.ChainHolder(paramTypes, chain); + chains.put(operationName, holder); + } + } + + public void invoke(AbstractHessianInput in, AbstractHessianOutput out) throws InvocationException { + ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); + try { + // ensure serialization is done on the target classloader + Thread.currentThread().setContextClassLoader(loader); + in.readCall(); + String m = in.readMethod(); + ChainHolder holder = chains.get(m); + if (holder == null) { + out.startReply(); + out.writeFault("OperationNotFound", "The service has no method named: " + m, null); + out.completeReply(); + return; + } + Class<?>[] paramType = holder.types; + Object[] values = new Object[paramType.length]; + for (int n = 0; n < paramType.length; n++) { + values[n] = in.readObject(paramType[n]); + } + in.completeCall(); + Message msg = new MessageImpl(); + InvocationChain chain = holder.chain; + Message ret = chain.getHeadInterceptor().invoke(msg); + out.startReply(); + Object o = ret.getBody(); + out.writeObject(o); + out.completeReply(); + } catch (IOException e) { + throw new InvocationException(e); + } finally { + Thread.currentThread().setContextClassLoader(oldLoader); + } + } + + protected class ChainHolder { + Class<?>[] types; + InvocationChain chain; + + public ChainHolder(Class<?>[] types, InvocationChain chain) { + this.types = types; + this.chain = chain; + } + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/HttpDestination.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/HttpDestination.java new file mode 100644 index 0000000000..cd6281e8bd --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/HttpDestination.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.hessian.destination; + +import java.io.IOException; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.apache.tuscany.spi.wire.Wire; + +import com.caucho.hessian.io.HessianInput; +import com.caucho.hessian.io.HessianOutput; +import org.apache.tuscany.hessian.InvocationException; +import org.apache.tuscany.hessian.TypeNotFoundException; + +/** + * A Destination implementation which receives requests over HTTP using a servlet engine + * + * @version $Rev$ $Date$ + */ +public class HttpDestination extends AbstractDestination implements Servlet { + + public HttpDestination(Wire wire, ClassLoader loader) + throws TypeNotFoundException { + super(wire, loader); + } + + public void service(ServletRequest req, ServletResponse resp) + throws ServletException, IOException { + try { + invoke(new HessianInput(req.getInputStream()), new HessianOutput(resp.getOutputStream())); + } catch (InvocationException e) { + throw new ServletException(e); + } + } + + public void init(ServletConfig servletConfig) throws ServletException { + + } + + public ServletConfig getServletConfig() { + return null; + } + + public String getServletInfo() { + return null; + } + + public void destroy() { + + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/LocalDestination.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/LocalDestination.java new file mode 100644 index 0000000000..55946f96e7 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/destination/LocalDestination.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.hessian.destination; + +import org.apache.tuscany.spi.wire.Wire; + +import org.apache.tuscany.hessian.TypeNotFoundException; + +/** + * A Destination implementation which receives requests over an in-VM transport + * + * @version $Rev$ $Date$ + */ +public class LocalDestination extends AbstractDestination { + + public LocalDestination(Wire wire, ClassLoader loader) throws TypeNotFoundException { + super(wire, loader); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/loader/HessianBindingLoader.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/loader/HessianBindingLoader.java new file mode 100644 index 0000000000..181733973d --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/loader/HessianBindingLoader.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.hessian.loader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.hessian.model.logical.HessianBindingDefinition; +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.model.ModelObject; +import org.osoa.sca.annotations.Reference; + +/** + * Loader for hessian binding. + * + * @version $Revision$ $Date$ + */ +public class HessianBindingLoader extends LoaderExtension<HessianBindingDefinition> { + + /** + * Qualified name of the binding. + */ + public static final QName BINDING_HESSIAN = + new QName("http://tuscany.apache.org/xmlns/binding/hessian/2.0-alpha2-incubating-SNAPSHOT", "binding.hessian"); + + /** + * Injects the loader registry. + * + * @param loaderRegistry Loader registry. + */ + protected HessianBindingLoader(@Reference(name = "loaderRegistry") + LoaderRegistry loaderRegistry) { + super(loaderRegistry); + } + + /** + * Gets the qualified name of the binding element. + */ + @Override + public QName getXMLType() { + return BINDING_HESSIAN; + } + + /** + * Loads the binding from the XML. + */ + public HessianBindingDefinition load(ModelObject arg0, XMLStreamReader arg1, DeploymentContext arg2) + throws XMLStreamException, LoaderException { + // TODO populate the model object + return new HessianBindingDefinition(); + } + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/logical/HessianBindingDefinition.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/logical/HessianBindingDefinition.java new file mode 100644 index 0000000000..74c305254c --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/logical/HessianBindingDefinition.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.tuscany.hessian.model.logical; + +import org.apache.tuscany.spi.model.BindingDefinition; + +/** + * @version $Revision$ $Date$ + */ +public class HessianBindingDefinition extends BindingDefinition { + +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireSourceDefinition.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireSourceDefinition.java new file mode 100644 index 0000000000..e24432d513 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireSourceDefinition.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.hessian.model.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; + +/** + * @version $Rev$ $Date$ + */ +public class HessianWireSourceDefinition extends PhysicalWireSourceDefinition { + private URI endpointUri; + + public URI getEndpointUri() { + return endpointUri; + } + + public void setEndpointUri(URI endpointUri) { + this.endpointUri = endpointUri; + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireTargetDefinition.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireTargetDefinition.java new file mode 100644 index 0000000000..52dd8728f1 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/model/physical/HessianWireTargetDefinition.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.hessian.model.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; + +/** + * @version $Rev$ $Date$ + */ +public class HessianWireTargetDefinition extends PhysicalWireTargetDefinition { + private URI endpointUri; + + public URI getEndpointUri() { + return endpointUri; + } + + public void setEndpointUri(URI endpointUri) { + this.endpointUri = endpointUri; + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/wire/HessianWireAttacher.java b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/wire/HessianWireAttacher.java new file mode 100644 index 0000000000..0ca3132d11 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/main/java/org/apache/tuscany/hessian/wire/HessianWireAttacher.java @@ -0,0 +1,58 @@ +/* + * 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.hessian.wire; + +import java.net.URI; + +import org.apache.tuscany.hessian.DestinationCreationException; +import org.apache.tuscany.hessian.InvalidDestinationException; +import org.apache.tuscany.hessian.component.HessianBindingComponent; +import org.apache.tuscany.hessian.model.physical.HessianWireSourceDefinition; +import org.apache.tuscany.hessian.model.physical.HessianWireTargetDefinition; +import org.apache.tuscany.spi.builder.physical.WireAttacher; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.wire.Wire; +import org.osoa.sca.annotations.Reference; + +/** + * @version $Rev$ $Date$ + */ +public class HessianWireAttacher<C extends Component> implements + WireAttacher<C, HessianWireSourceDefinition, HessianWireTargetDefinition> { + + private HessianBindingComponent bindingComponent; + + public HessianWireAttacher(@Reference(name="bindingComponent") HessianBindingComponent bindingComponent) { + this.bindingComponent = bindingComponent; + } + + public void attach(C source, Component target, Wire wire, HessianWireSourceDefinition definition) + throws DestinationCreationException { + URI endpointUri = definition.getEndpointUri(); + // FIXME classloader + bindingComponent.createEndpoint(endpointUri, wire, null); + + } + + public void attach(C component, Wire wire, HessianWireTargetDefinition definition) + throws InvalidDestinationException { + URI endpointUri = definition.getEndpointUri(); + bindingComponent.bindToEndpoint(endpointUri, wire); + } +} diff --git a/sandbox/old/contrib/binding-hessian/binding/src/test/java/org/apache/tuscany/hessian/integration/HessianLocalSendReceiveTestCase.java b/sandbox/old/contrib/binding-hessian/binding/src/test/java/org/apache/tuscany/hessian/integration/HessianLocalSendReceiveTestCase.java new file mode 100644 index 0000000000..f0fc6b93f0 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/binding/src/test/java/org/apache/tuscany/hessian/integration/HessianLocalSendReceiveTestCase.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.tuscany.hessian.integration; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +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.MessageImpl; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.apache.tuscany.hessian.channel.LocalChannel; +import org.apache.tuscany.hessian.destination.LocalDestination; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class HessianLocalSendReceiveTestCase extends TestCase { + + public void testInvokeVoidReturn() throws Exception { + Interceptor interceptor = EasyMock.createMock(Interceptor.class); + EasyMock.expect(interceptor.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); + EasyMock.replay(interceptor); + + PhysicalOperationDefinition operation = new PhysicalOperationDefinition(); + operation.setName("hello"); + + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); + EasyMock.replay(chain); + + Map<PhysicalOperationDefinition, InvocationChain> chains = + new HashMap<PhysicalOperationDefinition, InvocationChain>(); + chains.put(operation, chain); + + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.getPhysicalInvocationChains()).andReturn(chains); + EasyMock.replay(wire); + ClassLoader loader = getClass().getClassLoader(); + LocalDestination destination = new LocalDestination(wire, loader); + LocalChannel channel = new LocalChannel(destination); + channel.send("hello", null, new MessageImpl()); + EasyMock.verify(interceptor); + } + +} diff --git a/sandbox/old/contrib/binding-hessian/pom.xml.off b/sandbox/old/contrib/binding-hessian/pom.xml.off new file mode 100644 index 0000000000..cd642e0c01 --- /dev/null +++ b/sandbox/old/contrib/binding-hessian/pom.xml.off @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + + <parent> + <groupId>org.apache.tuscany</groupId> + <artifactId>sca</artifactId> + <version>1.0-incubating</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.hessian</groupId> + <artifactId>hessian</artifactId> + <version>2.0-alpha2-incubating-SNAPSHOT</version> + + <packaging>pom</packaging> + <name>Tuscany Hessian Binding Extension </name> + <modules> + <module>binding</module> + </modules> + <!-- definition of repositories where the parent pom can be found --> + <repositories> + <repository> + <id>apache.snapshots</id> + <name>Apache Snapshot Repository</name> + <url>http://people.apache.org/repo/m2-snapshot-repository</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + <repository> + <id>apache.incubator</id> + <name>Apache Incubator Repository</name> + <url>http://people.apache.org/repo/m2-incubating-repository/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + <repository> + <id>objectstyle</id> + <url>http://www.objectstyle.org/maven2/</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>2.0-alpha2-incubating-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>com.caucho</groupId> + <artifactId>hessian</artifactId> + <version>3.0.20</version> + </dependency> + + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymockclassextension</artifactId> + <version>2.2</version> + </dependency> + + <!-- junit version --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + </dependency> + + + </dependencies> + +</project> |