You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by so...@apache.org on 2024/11/08 13:57:51 UTC

(dubbo-spi-samples) branch main updated: feat: add spi-protocol-rest-samples (#19)

This is an automated email from the ASF dual-hosted git repository.

songxiaosheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-samples.git


The following commit(s) were added to refs/heads/main by this push:
     new 4e1ddf2  feat: add spi-protocol-rest-samples (#19)
4e1ddf2 is described below

commit 4e1ddf2f9a4b9a2bb7ae7fa71a1e275a209fb36a
Author: ZeruiYang <ze...@gmail.com>
AuthorDate: Fri Nov 8 21:57:47 2024 +0800

    feat: add spi-protocol-rest-samples (#19)
    
    * feat: add spi-protocol-rest-samples
    
    * feat: add spi-protocol-rest-samples
    
    * fix: modify the provider's port
    
    * fix: modify the provider's port to 8310
    
    * fix: modify the provider's port to 8310
    
    * fix: modify the provider's port to 20800
    
    * fix: modify the pipeline test
    
    * Revert "fix: modify the pipeline test"
    
    This reverts commit d8f2c6569bd18afe16f781386c9c7f59ae7304b6.
    
    * fix: modify the test
    
    * fix: modify the pom.xml
    
    * fix: change thr port to 20880
    
    * fix: change the url to dubbo-samples-spi-rest
    
    * fix: add the application/json
    
    * fix: add the application/json
    
    * fix: add http header x-dubbo-service-protocol
    
    * fix: change the format of json
    
    * fix: Abandon the use of HTTP requests and use consumer instead.
    
    * fix: Abandon the use of HTTP requests and use consumer instead.
    
    * fix: retry sending the request using http
    
    * fix: increase requests for json and xml
    
    * fix: add license
    
    * fix: add dependency in pom.xml
---
 .../samples-spi-protocol/pom.xml                   |   1 +
 .../case-configuration.yml                         |  41 +++
 .../samples-spi-protocol-rest/case-versions.conf   |  25 ++
 .../samples-spi-protocol-rest/pom.xml              | 184 ++++++++++++
 .../spi/protocol/rest/EmbeddedZooKeeper.java       | 312 +++++++++++++++++++++
 .../dubbo/samples/spi/protocol/rest/MyObject.java  |  35 +++
 .../samples/spi/protocol/rest/MyXmlObject.java     |  39 +++
 .../samples/spi/protocol/rest/RestConsumer.java    |  60 ++++
 .../samples/spi/protocol/rest/RestProvider.java    |  37 +++
 .../samples/spi/protocol/rest/api/DemoService.java |  49 ++++
 .../spi/protocol/rest/impl/DemoServiceImpl.java    |  56 ++++
 .../src/main/resources/log4j2.xml                  |  29 ++
 .../src/main/resources/spring/http-consumer.xml    |  33 +++
 .../src/main/resources/spring/http-provider.xml    |  37 +++
 .../src/test/java/DemoServiceIT.java               | 109 +++++++
 15 files changed, 1047 insertions(+)

diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/pom.xml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/pom.xml
index 837d4a8..1fd0fde 100644
--- a/2-dubbo-spi-protocol-samples/samples-spi-protocol/pom.xml
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/pom.xml
@@ -15,6 +15,7 @@
     <modules>
         <module>samples-spi-protocol-http</module>
         <module>samples-spi-protocol-rmi</module>
+        <module>samples-spi-protocol-rest</module>
     </modules>
 
     <properties>
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-configuration.yml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-configuration.yml
new file mode 100644
index 0000000..732f13b
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-configuration.yml
@@ -0,0 +1,41 @@
+# 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.
+
+services:
+  dubbo-samples-spi-rest:
+    type: app
+    basedir: .
+    mainClass: org.apache.dubbo.samples.spi.protocol.rest.RestProvider
+    systemProps:
+      - zookeeper.address=dubbo-samples-spi-rest
+      - zookeeper.port=2181
+      - rest.port=20880
+    checkPorts:
+      - 20880
+    checkLog: "dubbo service started"
+
+  dubbo-samples-spi-rest-test:
+    type: test
+    basedir: .
+    tests:
+      - "**/*IT.class"
+    systemProps:
+      - zookeeper.address=dubbo-samples-spi-rest
+      - zookeeper.port=2181
+    waitPortsBeforeRun:
+      - dubbo-samples-spi-rest:2181
+      - dubbo-samples-spi-rest:20880
+    depends_on:
+      - dubbo-samples-spi-rest
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-versions.conf b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-versions.conf
new file mode 100644
index 0000000..4b1b28d
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/case-versions.conf
@@ -0,0 +1,25 @@
+#
+#
+#   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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version= 3.2*
+spring.version=4.*, 5.*
+java.version= [>= 8]
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/pom.xml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/pom.xml
new file mode 100644
index 0000000..0fc0f07
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/pom.xml
@@ -0,0 +1,184 @@
+<?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">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>samples-spi-protocol</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>samples-spi-protocol-rest</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <zookeeper.version>3.8.4</zookeeper.version>
+        <metrics.version>4.1.12.1</metrics.version>
+        <servlet.version>3.1.0</servlet.version>
+        <snappy.version>1.1.10.5</snappy.version>
+        <jackson.version>2.15.3</jackson.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-framework-bom</artifactId>
+                <version>${spring.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-bom</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo.extensions</groupId>
+                <artifactId>dubbo-extensions-bom</artifactId>
+                <version>${spi.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.zookeeper</groupId>
+                <artifactId>zookeeper</artifactId>
+                <version>${zookeeper.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <artifactId>logback-core</artifactId>
+                        <groupId>ch.qos.logback</groupId>
+                    </exclusion>
+                    <exclusion>
+                        <artifactId>logback-classic</artifactId>
+                        <groupId>ch.qos.logback</groupId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context-support</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-impl</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jaxb</groupId>
+            <artifactId>jaxb-runtime</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo.extensions</groupId>
+            <artifactId>dubbo-rpc-rest</artifactId>
+            <version>3.3.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+            <version>2.1.1</version>
+        </dependency>
+
+        <!-- Netty dependencies -->
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-all</artifactId>
+            <version>4.1.92.Final</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>${metrics.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.xerial.snappy</groupId>
+            <artifactId>snappy-java</artifactId>
+            <version>${snappy.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/EmbeddedZooKeeper.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..e046914
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/EmbeddedZooKeeper.java
@@ -0,0 +1,312 @@
+/*
+ *
+ *   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.dubbo.samples.spi.protocol.rest;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.ServerSocket;
+import java.util.List;
+import java.util.Properties;
+import java.util.Random;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ * <p>
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+    private static final Random RANDOM = new Random();
+
+    /**
+     * Logger.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+    /**
+     * ZooKeeper client port. This will be determined dynamically upon startup.
+     */
+    private final int clientPort;
+
+    /**
+     * Whether to auto-start. Default is true.
+     */
+    private boolean autoStartup = true;
+
+    /**
+     * Lifecycle phase. Default is 0.
+     */
+    private int phase = 0;
+
+    /**
+     * Thread for running the ZooKeeper server.
+     */
+    private volatile Thread zkServerThread;
+
+    /**
+     * ZooKeeper server.
+     */
+    private volatile ZooKeeperServerMain zkServer;
+
+    /**
+     * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+     */
+    private ErrorHandler errorHandler;
+
+    private boolean daemon = true;
+
+    /**
+     * Construct an EmbeddedZooKeeper with a random port.
+     */
+    public EmbeddedZooKeeper() {
+        clientPort = findRandomPort(30000, 65535);
+    }
+
+    /**
+     * Construct an EmbeddedZooKeeper with the provided port.
+     *
+     * @param clientPort port for ZooKeeper server to bind to
+     */
+    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+        this.clientPort = clientPort;
+        this.daemon = daemon;
+    }
+
+    /**
+     * Returns the port that clients should use to connect to this embedded server.
+     *
+     * @return dynamically determined client port
+     */
+    public int getClientPort() {
+        return this.clientPort;
+    }
+
+    /**
+     * Specify whether to start automatically. Default is true.
+     *
+     * @param autoStartup whether to start automatically
+     */
+    public void setAutoStartup(boolean autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isAutoStartup() {
+        return this.autoStartup;
+    }
+
+    /**
+     * Specify the lifecycle phase for the embedded server.
+     *
+     * @param phase the lifecycle phase
+     */
+    public void setPhase(int phase) {
+        this.phase = phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int getPhase() {
+        return this.phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isRunning() {
+        return (zkServerThread != null);
+    }
+
+    /**
+     * Start the ZooKeeper server in a background thread.
+     * <p>
+     * Register an error handler via {@link #setErrorHandler} in order to handle
+     * any exceptions thrown during startup or execution.
+     */
+    @Override
+    public synchronized void start() {
+        if (zkServerThread == null) {
+            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+            zkServerThread.setDaemon(daemon);
+            zkServerThread.start();
+        }
+    }
+
+    /**
+     * Shutdown the ZooKeeper server.
+     */
+    @Override
+    public synchronized void stop() {
+        if (zkServerThread != null) {
+            // The shutdown method is protected...thus this hack to invoke it.
+            // This will log an exception on shutdown; see
+            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+            try {
+                Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+                shutdown.setAccessible(true);
+                shutdown.invoke(zkServer);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+            // It is expected that the thread will exit after
+            // the server is shutdown; this will block until
+            // the shutdown is complete.
+            try {
+                zkServerThread.join(5000);
+                zkServerThread = null;
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+                // abandoning zk thread
+                zkServerThread = null;
+            }
+        }
+    }
+
+    /**
+     * Stop the server if running and invoke the callback when complete.
+     */
+    @Override
+    public void stop(Runnable callback) {
+        stop();
+        callback.run();
+    }
+
+    /**
+     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+     * is provided, only error-level logging will occur.
+     *
+     * @param errorHandler the {@link ErrorHandler} to be invoked
+     */
+    public void setErrorHandler(ErrorHandler errorHandler) {
+        this.errorHandler = errorHandler;
+    }
+
+    /**
+     * Runnable implementation that starts the ZooKeeper server.
+     */
+    private class ServerRunnable implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                Properties properties = new Properties();
+                File file = new File(System.getProperty("java.io.tmpdir")
+                        + File.separator + UUID.randomUUID());
+                file.deleteOnExit();
+                properties.setProperty("dataDir", file.getAbsolutePath());
+                properties.setProperty("clientPort", String.valueOf(clientPort));
+
+                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+                quorumPeerConfig.parseProperties(properties);
+
+                zkServer = new ZooKeeperServerMain();
+                ServerConfig configuration = new ServerConfig();
+                configuration.readFrom(quorumPeerConfig);
+                
+                System.setProperty("zookeeper.admin.enableServer", "false");
+
+                zkServer.runFromConfig(configuration);
+            } catch (Exception e) {
+                if (errorHandler != null) {
+                    errorHandler.handleError(e);
+                } else {
+                    logger.error("Exception running embedded ZooKeeper", e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Workaround for SocketUtils.findRandomPort() deprecation.
+     *
+     * @param min min port
+     * @param max max port
+     * @return a random generated available port
+     */
+    private static int findRandomPort(int min, int max) {
+        if (min < 1024) {
+            throw new IllegalArgumentException("Max port shouldn't be less than 1024.");
+        }
+
+        if (max > 65535) {
+            throw new IllegalArgumentException("Max port shouldn't be greater than 65535.");
+        }
+
+        if (min > max) {
+            throw new IllegalArgumentException("Min port shouldn't be greater than max port.");
+        }
+
+        int port = 0;
+        int counter = 0;
+
+        // Workaround for legacy JDK doesn't support Random.nextInt(min, max).
+        List<Integer> randomInts = RANDOM.ints(min, max + 1)
+                .limit(max - min)
+                .mapToObj(Integer::valueOf)
+                .collect(Collectors.toList());
+
+        do {
+            if (counter > max - min) {
+                throw new IllegalStateException("Unable to find a port between " + min + "-" + max);
+            }
+
+            port = randomInts.get(counter);
+            counter++;
+        } while (isPortInUse(port));
+
+        return port;
+    }
+
+    private static boolean isPortInUse(int port) {
+        try (ServerSocket ignored = new ServerSocket(port)) {
+            return false;
+        } catch (IOException e) {
+            // continue
+        }
+        return true;
+    }
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyObject.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyObject.java
new file mode 100644
index 0000000..51e4b34
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyObject.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.dubbo.samples.spi.protocol.rest;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class MyObject {
+
+    @JsonProperty
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyXmlObject.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyXmlObject.java
new file mode 100644
index 0000000..78caedc
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/MyXmlObject.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.dubbo.samples.spi.protocol.rest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "MyXmlObject")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class MyXmlObject {
+    @XmlElement
+    private String value;
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestConsumer.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestConsumer.java
new file mode 100644
index 0000000..77ad23b
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestConsumer.java
@@ -0,0 +1,60 @@
+/*
+ *
+ *   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.dubbo.samples.spi.protocol.rest;
+
+
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+public class RestConsumer {
+
+    protected static final String HOST = System.getProperty("zookeeper.address", "localhost");
+
+    protected static String toUri(String path) {
+        return "http://" + HOST + ":20880/" + path;
+    }
+
+    public static void main(String[] args) {
+
+        RestTemplate restTemplate = new RestTemplate();
+
+        // create form data
+        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
+        map.add("number", "1");
+
+        // set the request header
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+
+        // create a request entity
+        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
+
+        // send a post request
+        ResponseEntity<String> response = restTemplate.postForEntity(toUri("demo/sayHello"), requestEntity, String.class);
+
+        System.out.println("Response: " + response.getBody());
+
+    }
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestProvider.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestProvider.java
new file mode 100644
index 0000000..7e42887
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/RestProvider.java
@@ -0,0 +1,37 @@
+/*
+ *
+ *   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.dubbo.samples.spi.protocol.rest;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class RestProvider {
+
+    public static void main(String[] args) throws Exception {
+        new EmbeddedZooKeeper(2181, false).start();
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/http-provider.xml");
+        context.start();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
+    }
+
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/api/DemoService.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/api/DemoService.java
new file mode 100644
index 0000000..f717d19
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/api/DemoService.java
@@ -0,0 +1,49 @@
+/*
+ *
+ *   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.dubbo.samples.spi.protocol.rest.api;
+
+
+import org.apache.dubbo.samples.spi.protocol.rest.MyObject;
+import org.apache.dubbo.samples.spi.protocol.rest.MyXmlObject;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/demo")
+public interface DemoService {
+        @POST
+        @Path("/sayHello")
+        String sayHello(String name);
+
+        @POST
+        @Path("/sayJson")
+        @Consumes(MediaType.APPLICATION_JSON)
+        @Produces(MediaType.TEXT_PLAIN)
+        String sayJson(MyObject obj);
+
+        @POST
+        @Path("/sayXml")
+        @Consumes(MediaType.TEXT_XML)
+        @Produces(MediaType.TEXT_PLAIN)
+        String sayXml(MyXmlObject obj);
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/impl/DemoServiceImpl.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..a15e0de
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/java/org/apache/dubbo/samples/spi/protocol/rest/impl/DemoServiceImpl.java
@@ -0,0 +1,56 @@
+/*
+ *
+ *   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.dubbo.samples.spi.protocol.rest.impl;
+
+import org.apache.dubbo.samples.spi.protocol.rest.MyObject;
+import org.apache.dubbo.samples.spi.protocol.rest.MyXmlObject;
+import org.apache.dubbo.samples.spi.protocol.rest.api.DemoService;
+import org.apache.dubbo.rpc.RpcContext;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DemoServiceImpl implements DemoService {
+    @Override
+    public String sayHello(String name) {
+        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name +
+                ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
+    }
+
+    @Override
+    public String sayJson(MyObject obj) {
+        // Assuming MyObject has a method getName() that returns a String
+        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + obj.getName() +
+                ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+        return "Hello " + obj.getName();
+    }
+
+
+    @Override
+    public String sayXml(MyXmlObject obj) {
+        // Assuming MyXmlObject has a method getValue() that returns a String
+        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + obj.getValue() +
+                ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+        return "Hello " + obj.getValue();
+    }
+
+
+}
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/log4j2.xml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..69e1321
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/log4j2.xml
@@ -0,0 +1,29 @@
+<?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.
+  -->
+<Configuration status="WARN">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT" follow="true">
+            <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="info">
+            <AppenderRef ref="Console"/>
+        </Root>
+    </Loggers>
+</Configuration>
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-consumer.xml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-consumer.xml
new file mode 100644
index 0000000..1d787e1
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-consumer.xml
@@ -0,0 +1,33 @@
+<?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.
+  ~
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+       xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+    <context:property-placeholder/>
+
+    <dubbo:application name="http-consumer"/>
+
+    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+    <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.spi.protocol.rest.api.DemoService" />
+</beans>
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-provider.xml b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-provider.xml
new file mode 100644
index 0000000..5c1738c
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/main/resources/spring/http-provider.xml
@@ -0,0 +1,37 @@
+<?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.
+  ~
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+       xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+    <context:property-placeholder/>
+
+    <dubbo:application name="rest-provider"/>
+
+    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+    <dubbo:protocol name="rest" id="rest" port="${rest.port:20880}"/>
+
+    <bean id="demoService" class="org.apache.dubbo.samples.spi.protocol.rest.impl.DemoServiceImpl"/>
+
+    <dubbo:service interface="org.apache.dubbo.samples.spi.protocol.rest.api.DemoService" ref="demoService" protocol="rest"/>
+</beans>
diff --git a/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/test/java/DemoServiceIT.java b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/test/java/DemoServiceIT.java
new file mode 100644
index 0000000..7d9dd62
--- /dev/null
+++ b/2-dubbo-spi-protocol-samples/samples-spi-protocol/samples-spi-protocol-rest/src/test/java/DemoServiceIT.java
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+
+import org.apache.dubbo.samples.spi.protocol.rest.MyObject;
+import org.apache.dubbo.samples.spi.protocol.rest.MyXmlObject;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Arrays;
+
+public class DemoServiceIT {
+
+    protected static final String HOST = System.getProperty("zookeeper.address", "localhost");
+
+    protected static String toUri(String path) {
+        return "http://" + HOST + ":20880/" + path;
+    }
+
+    @Test
+    public void test() {
+        RestTemplate restTemplate = new RestTemplate();
+
+        // Create form data
+        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
+        map.add("number", "world");
+
+        // Set the request header
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+
+        // create a request entity
+        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
+
+        // send a post request
+        ResponseEntity<String> response = restTemplate.postForEntity(toUri("demo/sayHello"), requestEntity, String.class);
+
+        System.out.println("Response: " + response.getBody());
+        Assert.assertTrue(response.getBody().startsWith("Hello world"));
+    }
+
+    @Test
+    public void testPostJson() {
+        RestTemplate restTemplate = new RestTemplate();
+
+        MyObject myObject = new MyObject();
+        myObject.setName("world");
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+
+        HttpEntity<MyObject> requestEntity = new HttpEntity<>(myObject, headers);
+
+        ResponseEntity<String> response = restTemplate.postForEntity(toUri("demo/sayJson"), requestEntity, String.class);
+
+        System.out.println("Response: " + response.getBody());
+        Assert.assertTrue(response.getBody().contains("Hello world"));
+    }
+
+
+    @Test
+    public void testPostXml() {
+
+        RestTemplate restTemplate = new RestTemplate();
+        restTemplate.setMessageConverters(Arrays.asList(
+                new Jaxb2RootElementHttpMessageConverter(),
+                new StringHttpMessageConverter()
+        ));
+
+        MyXmlObject xmlObject = new MyXmlObject();
+        xmlObject.setValue("world");
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.TEXT_XML);
+
+        HttpEntity<MyXmlObject> requestEntity = new HttpEntity<>(xmlObject, headers);
+
+        ResponseEntity<String> response = restTemplate.postForEntity(toUri("demo/sayXml"), requestEntity, String.class);
+
+        System.out.println("Response: " + response.getBody());
+        Assert.assertTrue(response.getBody().contains("Hello world"));
+    }
+
+
+}