文档章节

OSGI系列 Web-Service

l
 lvk618
发布于 2016/06/15 09:14
字数 1959
阅读 11
收藏 0

一、首先创建一个父亲项目,父亲项目下面有3个儿子模块(webservice)

<?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/maven-v4_0_0.xsd">
    <!--Base -->
    <modelVersion>4.0.0</modelVersion>
    <groupId>jmust.ws</groupId>
    <artifactId>webservice</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <name>Web-Service</name>
    <url>http://common.yy.com/webservice</url>
    <distributionManagement>
        <repository>
            <id>yy</id>
            <name>yy Repository</name>
            <url>http://admin:admin123@0.0.0.0:8080/nexus/content/repositories/yyRepos/</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- 依赖关系管理 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <type>jar</type>
                <scope>test</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.compendium</artifactId>
                <version>4.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-test-blueprint</artifactId>
                <version>2.14.2</version>
            </dependency>
            <dependency>
                 <groupId>org.apache.camel</groupId>
                 <artifactId>camel-core</artifactId>
                 <version>2.15.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <!-- 依赖 -->
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <type>jar</type>
            <scope>test</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <!--子模块 -->
    <modules>
        <module>ws_inter</module>
        <module>ws_impl</module>
        <module>ws_service</module>
    </modules> 

</project>

1、 第一个儿子模块(inter)

(1)pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>jmust.ws</groupId>
        <artifactId>webservice</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <groupId>jmust.ws.webservice</groupId>
    <artifactId>inter</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0</version>
    <name>ws-inter</name>
    <url>http://maven.apache.org</url>
    <distributionManagement>
        <repository>
            <id>jmust</id>
            <name>jmust Repository</name>
            <url>http://admin:admin123@192.168.1.65:8081/nexus/content/repositories/JMustRepos/</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-blueprint</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>    
    </dependencies>
    <build>
        <plugins>
            <!-- to generate the MANIFEST-FILE of the bundle -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.5.4</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Vendor>yy</Bundle-Vendor>
                        <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
                        <Bundle-Name>${project.groupId}.${project.ArtifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Export-Package>jmust.ws.webservice.inter;version="1.0.0"</Export-Package>
                        <Import-Package>
                            org.osgi.framework,org.slf4j
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

(2) 接口定义

@WebService
public interface Calculator {
    @WebMethod
    public String getVersion(String request);
    
    @WebMethod  
    public Long add(Integer a, Integer b);  
      
    @WebMethod  
    public Long subtract(Integer a, Integer b);  
      
    @WebMethod  
    public Long multiply(Integer a, Integer b);
}

2、第二个儿子模块

(1)pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>jmust.ws</groupId>
        <artifactId>webservice</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <groupId>jmust.ws.webservice</groupId>
    <artifactId>impl</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0</version>
    <name>ws-impl</name>
    <url>http://maven.apache.org</url>
    <distributionManagement>
        <repository>
            <id>jmust</id>
            <name>jmust Repository</name>
            <url>http://admin:admin123@192.168.1.65:8081/nexus/content/repositories/JMustRepos/</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.14.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>3.0.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jmust.ws.webservice</groupId>
            <artifactId>inter</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- to generate the MANIFEST-FILE of the bundle -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.5.4</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Vendor>yy</Bundle-Vendor>
                        <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
                        <Bundle-Name>${project.groupId}.${project.ArtifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Export-Package>jmust.ws.webservice.impl;version="1.0.0"</Export-Package>
                        <Import-Package>
                            jmust.ws.webservice.inter
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

(2) blueprint.xml

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf" 
           xmlns:cxfcore="http://cxf.apache.org/blueprint/core" 
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
           xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
>

  <bean id="wsImplBean" class="jmust.ws.webservice.impl.CalculatorImpl">
          <!-- <property name="userName" value="lvkun"/> -->
  </bean>
  
  <service id="wsService" ref="wsImplBean" interface="jmust.ws.webservice.inter.Calculator">
  </service>

</blueprint>

(3) 接口实现

public class CalculatorImpl implements Calculator{

    @Override
    public String getVersion(String request) {
        // TODO Auto-generated method stub
        System.out.println(request);
        return "1.0.0";
    }

    @Override
    public Long add(Integer a, Integer b) {
        // TODO Auto-generated method stub
        System.out.println(a+","+b);
        return Long.valueOf(a+b);
    }

    @Override
    public Long subtract(Integer a, Integer b) {
        // TODO Auto-generated method stub
        System.out.println(a+","+b);
        return Long.valueOf(a - b);
    }

    @Override
    public Long multiply(Integer a, Integer b) {
        // TODO Auto-generated method stub
        System.out.println(a + ", " + b);  
        return Long.valueOf(a * b);  
    }

}

3、 第三个儿子模块(service)

(1)pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>jmust.ws</groupId>
        <artifactId>webservice</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <groupId>jmust.ws.webservice</groupId>
    <artifactId>service</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0</version>
    <name>ws-service</name>
    <url>http://maven.apache.org</url>
    <distributionManagement>
        <repository>
            <id>jmust</id>
            <name>jmust Repository</name>
            <url>http://admin:admin123@192.168.1.65:8081/nexus/content/repositories/JMustRepos/</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-blueprint</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.14.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>3.0.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>jmust.ws.webservice</groupId>
            <artifactId>inter</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- to generate the MANIFEST-FILE of the bundle -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.5.4</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Vendor>yy</Bundle-Vendor>
                        <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
                        <Bundle-Name>${project.groupId}.${project.ArtifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Export-Package>jmust.ws.webservice.service;version="1.0.0"</Export-Package>
                        <Import-Package>
                            org.osgi.framework,org.slf4j,org.apache.camel,org.apache.cxf.message,
                            jmust.ws.webservice.inter
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

(2) blueprint.xml

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:cxfcore="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd  
                                http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
                                http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
                                http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">

    <reference id="GWService" interface="jmust.ws.webservice.inter.Calculator" />

    <bean id="calcProcessor" class="jmust.ws.webservice.service.CalculatorProcessor">
        <property name="gwService" ref="GWService" />
    </bean>
    
    <camel-cxf:cxfEndpoint id="calcWSEndpoint"
        serviceClass="jmust.ws.webservice.inter.Calculator" address="http://127.0.0.1:9911/ws/calc"
        bindingId="http://www.w3.org/2003/05/soap/bindings/HTTP/">
    </camel-cxf:cxfEndpoint>
    <camelContext id="ACamelContext"
        xmlns="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
        
        <!-- 处理web-service请求  方式一-->
        <route>
            <from uri="calcWSEndpoint" />
            <setHeader headerName="CamelBeanMethodName">
                <simple>${in.header.operationName}</simple>
            </setHeader>
            <setHeader headerName="CamelBeanMultiParameterArray">
                <constant>true</constant>
            </setHeader>
            <to uri="bean:GWService" />
        </route>
        
        <!-- 处理web-service请求  方式二 -->
        <!-- <route>
            <from uri="calcWSEndpoint"/>
            <to uri="bean:calcProcessor"/>
        </route> -->
        
        <!-- 测试 -->
        <route>
            <from uri="jetty:http://127.0.0.1:8080/jetty" />
            <to uri="log:aa" />
        </route>
    </camelContext>
</blueprint>

(3) Processor

public class CalculatorProcessor implements Processor{

    private static final Logger log = LoggerFactory.getLogger(CalculatorProcessor.class);
    private Calculator gwService;
    
    public Calculator getGwService() {
        return gwService;
    }

    public void setGwService(Calculator gwService) {
        this.gwService = gwService;
    }

    /**
     * 根据operatioNname 去执行相应的逻辑,然后设置相应的返回值(一定要和接口的返回值一致)
     */
    @Override
    public void process(Exchange exchange) throws Exception {
        // TODO Auto-generated method stub
        MessageContentsList args = exchange.getIn().getBody(MessageContentsList.class);  
        String method = exchange.getIn().getHeader("operatioNname", String.class);  
        if("getVersion".equals(method))  
        {  
            exchange.getOut().setBody("2.14.1");  
            return;  
        }  
          
        Object arg1 = args.get(0);  
        Object arg2 = args.get(1);  
        Integer a = Integer.valueOf(arg1.toString());  
        Integer b = Integer.valueOf(arg2.toString());  
        if("add".equals(method))  
        {  
            exchange.getOut().setBody(gwService.add(a, b));  
        }  
        else if("subtract".equals(method))  
        {  
            exchange.getOut().setBody(gwService.subtract(a, b));  
        }  
        else if("multiply".equals(method))  
        {  
            exchange.getOut().setBody(gwService.multiply(a, b));  
        }  
    }
}

完毕!

本文转载自:http://blog.csdn.net/lk10207160511/article/details/50363745

l
粉丝 3
博文 80
码字总数 792
作品 0
广州
私信 提问
利用 R-OSGi 实现分布式 OSGi 应用

OSGi(Open Service Gateway Initiative)是业界中最知名的 Java 模块化技术规范,其核心设计思想是面向服务的组件模型(Service-Oriented Component Model)。OSGi 发展至今已经得到了众多企...

IBMdW
2012/06/27
1K
2
OSGi 4.2 规范正式发布

OSGi 联盟 前天 发布了 OSGi 4.2 规范。虽然早期草稿已经早己可用,但这是最终规范发布版本。 一些 OSGi 实现,例如 Equinox 3.5 与 Felix 2.0 早已针对 OSGi 4.2 规范做了一些兼容实现,但当...

红薯
2009/09/26
2.3K
0
OSGI学习手册

1 概述 本文是关于OSGI学习的一些资源介绍, 基本的脉络是按照自己的学习进程来的, 希望对进入OSGI学习的人有所启发。 本人具备的学习基础有: 1. Java RCP开发经验, 这个并不是必须, 实质上学...

晨曦之光
2012/03/09
323
0
JBossOSGi-1.1.0 发布

JBossOSGi-1.1.0 发布了,下载地址:jboss-osgi-installer-1.1.0.jar 这是一个 OSGi Core 4.2 的框架,该版本主要是在 AS7 的集成方面上进行全面完善。 同时还包含如下改进: Concurrency op...

红薯
2012/03/09
313
0
使用 Felix 和 Struts2 开发 Web 应用

Open Service Gateway Initiative(OSGi) 是一个针对 Java 动态模块开发的规范。基于中间件的 OSGi 技术提供了一个面向服务,基于组件的开发环境,并提供标准化的方式来管理整个软件生命周期。...

小编辑
2010/07/13
3.3K
4

没有更多内容

加载失败,请刷新页面

加载更多

nginx学习笔记

中间件位于客户机/ 服务器的操作系统之上,管理计算机资源和网络通讯。 是连接两个独立应用程序或独立系统的软件。 web请求通过中间件可以直接调用操作系统,也可以经过中间件把请求分发到多...

码农实战
今天
5
0
Spring Security 实战干货:玩转自定义登录

1. 前言 前面的关于 Spring Security 相关的文章只是一个预热。为了接下来更好的实战,如果你错过了请从 Spring Security 实战系列 开始。安全访问的第一步就是认证(Authentication),认证...

码农小胖哥
今天
9
0
JAVA 实现雪花算法生成唯一订单号工具类

import lombok.SneakyThrows;import lombok.extern.slf4j.Slf4j;import java.util.Calendar;/** * Default distributed primary key generator. * * <p> * Use snowflake......

huangkejie
昨天
12
0
PhotoShop 色调:RGB/CMYK 颜色模式

一·、 RGB : 三原色:红绿蓝 1.通道:通道中的红绿蓝通道分别对应的是红绿蓝三种原色(RGB)的显示范围 1.差值模式能模拟三种原色叠加之后的效果 2.添加-颜色曲线:调整图像RGB颜色----R色增强...

东方墨天
昨天
11
1
将博客搬至CSDN

将博客搬至CSDN

算法与编程之美
昨天
13
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部