Skip to content

Commit

Permalink
Added Java project to consumer OSGi-exported demo service. New project
Browse files Browse the repository at this point in the history
is examples/ecf.example.demo.consumer
  • Loading branch information
scottslewis committed Sep 2, 2019
1 parent 667238b commit f12139c
Show file tree
Hide file tree
Showing 34 changed files with 1,007 additions and 2 deletions.
36 changes: 36 additions & 0 deletions examples/ecf.example.demo.consumer/.classpath
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/org.eclipse.ecf.examples.provider.dubbo.demo.api_1.0.0.201908301123.jar"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/dubbo-cluster-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-common-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-config-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-configcenter-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-container-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-filter-cache-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-filter-validation-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-metadata-report-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-monitor-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-registry-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-remoting-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-remoting-netty4-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-rpc-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-rpc-dubbo-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-rpc-injvm-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-serialization-api-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/dubbo-serialization-hessian2-2.7.4-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/hessian-lite-3.2.5.jar"/>
<classpathentry kind="lib" path="lib/javassist-3.24.1-GA.jar"/>
<classpathentry kind="lib" path="lib/netty-all-4.1.25.Final.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions examples/ecf.example.demo.consumer/.gitignore
@@ -0,0 +1,2 @@
/bin/
/target/
23 changes: 23 additions & 0 deletions examples/ecf.example.demo.consumer/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ecf.example.demo.consumer</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.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=ISO-8859-1
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,39 @@
<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
<endpoint-description>
<property name="ecf.endpoint.id" value-type="String" value="dubbo%3A%2F%2F192.168.0.52%3A20880%2Forg.eclipse.ecf.examples.provider.dubbo.demo.api.DemoService%3Fanyhost%3Dtrue%26application%3Decf-remoteservice-application%26bind.ip%3D192.168.0.52%26bind.port%3D20880%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dorg.eclipse.ecf.examples.provider.dubbo.demo.api.DemoService%26methods%3DsayHello%26pid%3D8804%26register%3Dtrue%26release%3D2.7.4-SNAPSHOT%26side%3Dprovider%26timestamp%3D1567463539696"/>
<property name="ecf.endpoint.id.ns" value-type="String" value="ecf.namespace.dubbo"/>
<property name="ecf.endpoint.ts" value-type="Long" value="1567463539386"/>
<property name="ecf.rsvc.id" value-type="Long" value="1"/>
<property name="endpoint.framework.uuid" value-type="String" value="b22ca7cf-b450-4a44-9d87-c3d56b9b9c32"/>
<property name="endpoint.id" value-type="String" value="422a7c71-10d3-40d0-ab5c-2c76496edda4"/>
<property name="endpoint.package.version.org.eclipse.ecf.examples.provider.dubbo.demo.api" value-type="String" value="1.0.0"/>
<property name="endpoint.service.id" value-type="Long" value="39"/>
<property name="objectClass" value-type="String">
<array>
<value>org.eclipse.ecf.examples.provider.dubbo.demo.api.DemoService</value>
</array>
</property>
<property name="remote.configs.supported" value-type="String">
<array>
<value>ecf.dubbo.server</value>
</array>
</property>
<property name="remote.intents.supported" value-type="String">
<array>
<value>osgi.basic</value>
<value>passByValue</value>
<value>exactlyOnce</value>
<value>ordered</value>
<value>osgi.async</value>
<value>osgi.private</value>
<value>dubbo</value>
</array>
</property>
<property name="service.imported" value-type="String" value="true"/>
<property name="service.imported.configs" value-type="String">
<array>
<value>ecf.dubbo.server</value>
</array>
</property>
</endpoint-description>
</endpoint-descriptions>
73 changes: 73 additions & 0 deletions examples/ecf.example.demo.consumer/pom.xml
@@ -0,0 +1,73 @@
<?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 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">
<parent>
<groupId>org.eclipse.ecf.provider.dubbo</groupId>
<artifactId>org.eclipse.ecf.provider.dubbo.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ecf.example.demo.consumer</artifactId>

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
flatten-maven-plugin
</artifactId>
<versionRange>
[1.1.0,)
</versionRange>
<goals>
<goal>flatten</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,61 @@
package ecf.example.demo.consumer;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.eclipse.ecf.examples.provider.dubbo.demo.api.DemoService;

public class ConsumerApplication {

static String getUrlFromFirstEndpointDescription(InputStream ins) throws Exception {
EndpointDescriptionParser parser = new EndpointDescriptionParser();
parser.parse(ins);
String urlString = (String) parser.getEndpointDescriptions().get(0).getProperties().get("ecf.endpoint.id");
return URLDecoder.decode(urlString, StandardCharsets.UTF_8.name());
}

static InputStream getInputStream(String[] args) throws Exception {
InputStream ins = null;
if (args.length > 0) {
ins = new FileInputStream(args[0]);
} else {
System.out.println("Waiting for console input of endpointdescription.xml. To complete input, enter empty line");
StringBuffer buf = new StringBuffer();
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
while (true) {
String line = reader.readLine();
if (line != null && line.length() > 0)
buf.append(line).append("\n");
else
break;
}
ins = new ByteArrayInputStream(buf.toString().getBytes());
}
return ins;
}

public static void main(String[] args) throws Exception {
String urlString = getUrlFromFirstEndpointDescription(getInputStream(args));
System.out.println("Parsed endpoint description and got dubbo url="+urlString);
// Now we have dubbo url, we setup ReferenceConfig
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
reference.setUrl(urlString);
reference.setInterface(DemoService.class);
// get service
DemoService service = reference.get();
// Make remote sayHello call
String message = service.sayHello("ecf dubbo java client");
// Print out message
System.out.println("Received message: "+message);
}

}

0 comments on commit f12139c

Please sign in to comment.