Commit c5e831ad authored by Constantin Jucovschi's avatar Constantin Jucovschi

initial commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
target/
bin/
*~
*.log
felix-cache
.metadata
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sally4-client</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 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. -->
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-client</artifactId>
<version>${sally4.version}</version>
<parent>
<groupId>info.kwarc.sally</groupId>
<artifactId>sally</artifactId>
<version>1.0</version>
<relativePath>..</relativePath>
</parent>
<properties>
<maven-bundle-plugin.version>2.4.0</maven-bundle-plugin.version>
<osgi.version>5.0.0</osgi.version>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${osgi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>${osgi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-activemq</artifactId>
<version>${sally4.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4.comm</groupId>
<artifactId>comm-core</artifactId>
<version>${sally4.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<version>1.11.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stomp</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- BND Maven Plugin Configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.client.impl</Private-Package>
<Import-Package>*;</Import-Package>
<Export-Package>info.kwarc.sally4.client*</Export-Package>
</instructions>
</configuration>
</plugin>
<!-- iPOJO Maven Plugin Configuration : nothing to do -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package info.kwarc.sally4.client;
import org.apache.camel.RoutesBuilder;
public interface SallyClient {
void registerDocument(String docName, String[] interfaces, RoutesBuilder builder);
}
package info.kwarc.sally4.client.impl;
import info.kwarc.sally.comm.core.Registerdocument;
import info.kwarc.sally.comm.core.Registerdocumentresponse;
import info.kwarc.sally4.activemq.ActiveMQService;
import info.kwarc.sally4.client.SallyClient;
import info.kwarc.sally4.components.ProducerConsumerSplitterComponent;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.marshalling.CommUtils;
import java.util.Arrays;
import java.util.UUID;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Property;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
@Component
@Provides(specifications=SallyClient.class)
@Instantiate
public class SallyClientImpl extends RouteBuilder implements SallyClient {
@Requires
ActiveMQService activeMQ;
@Requires
CamelContextProvider camelContextProvider;
CamelContext context;
@Validate
public void start() throws Exception {
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addRoutes(this);
context.start();
}
@Invalidate
public void stop() throws Exception {
context.stop();
}
@Override
public void configure() throws Exception {
DataFormat core = CommUtils.getDataFormat("core", getClass().getClassLoader());
from("direct:sally_register")
.setProperty("origRequest", body())
.marshal(core)
.to("log:foo?showHeaders=true&showProperties=true")
.inOut("activemq:queue:sally_register")
.to("log:foo?showHeaders=true&showProperties=true")
.unmarshal(core)
.bean(method(this, "registerResponse"));
}
public void registerResponse(Exchange e) throws Exception {
Registerdocumentresponse response = e.getIn().getBody(Registerdocumentresponse.class);
Registerdocument req = e.getProperty("origRequest", Registerdocument.class);
RoutesBuilder builder = e.getProperty("builder", RoutesBuilder.class);
CamelContext docContext = new DefaultCamelContext();
docContext.addComponent("activemq", camelContextProvider.getComponent("activemq"));
docContext.addComponent("sally", new ProducerConsumerSplitterComponent("activemq:queue:"+req.getDocumentqueue(), "activemq:queue:"+response.getSallyqueue()));
docContext.addRoutes(builder);
docContext.start();
}
String genUUID(String name) {
name+=Math.random();
if (name.length() == 0) {
name = UUID.randomUUID().toString();
}
name = name.replaceAll("[^a-zA_Z0-9]", "_");
return name;
}
@Override
public void registerDocument(String docName, String[] interfaces, RoutesBuilder builder) {
Registerdocument regDoc = new Registerdocument();
regDoc.setDocumentqueue(genUUID(docName));
regDoc.setEnvironmentid(System.getenv("SALLYENVID"));
regDoc.setUserid("");
regDoc.getInterfaces().addAll(Arrays.asList(interfaces));
getContext().createProducerTemplate().sendBodyAndProperty("direct:sally_register", regDoc, "builder", builder);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment