diff options
Diffstat (limited to 'sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany')
6 files changed, 340 insertions, 0 deletions
diff --git a/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/JBIBinding.java new file mode 100644 index 0000000000..04781d6d69 --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/JBIBindingLoader.java new file mode 100644 index 0000000000..8b6806a731 --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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 <binding.jbi> elements. + */ +@Scope("MODULE") +public class JBIBindingLoader extends LoaderExtension<JBIBinding> { + + 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/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixBuilder.java new file mode 100644 index 0000000000..227d56d0b7 --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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<JBIBinding> { + + protected Class<JBIBinding> getBindingType() { + return JBIBinding.class; + } + + @SuppressWarnings( { "unchecked" }) + public SCAObject build(CompositeComponent parent, BoundServiceDefinition<JBIBinding> 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<JBIBinding> boundReferenceDefinition, + DeploymentContext deploymentContext) { + + + ServiceMixReference serviceMixReference = new ServiceMixReference(null, parent, wireService, null, null); + + return serviceMixReference; + + } +} diff --git a/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixInvoker.java new file mode 100644 index 0000000000..5ad2aae7b5 --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixReference.java new file mode 100644 index 0000000000..e9898f8f15 --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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<T> extends ReferenceExtension<T> { + + private final String uri; + + public ServiceMixReference(String name, + CompositeComponent<?> parent, + WireService wireService, + String uri, + Class<T> 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/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java b/sandbox/old/contrib/binding-servicemix/binding/src/main/java/org/apache/tuscany/servicemix/ServiceMixService.java new file mode 100644 index 0000000000..ae7e9e3f1b --- /dev/null +++ b/sandbox/old/contrib/binding-servicemix/binding/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<T> extends ServiceExtension<T> { + + public ServiceMixService(String name, CompositeComponent parent, WireService wireService, Class<T> service) { + super(name, service, parent, wireService); + } + + public void start() { + super.start(); + } + + public void stop() { + super.stop(); + } + +} |