content/references/java-chassis/en_US/transports/rest-over-servlet/index.html (533 lines of code) (raw):

<!DOCTYPE html> <html class="writer-html5" lang="en" > <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="shortcut icon" href="../../img/favicon.ico" /> <title>REST over Servlet - ServiceComb Java Chassis Developers Guide</title> <link rel="stylesheet" href="../../css/theme.css" /> <link rel="stylesheet" href="../../css/theme_extra.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" /> <script> // Current page data var mkdocs_page_name = "REST over Servlet"; var mkdocs_page_input_path = "transports/rest-over-servlet.md"; var mkdocs_page_url = null; </script> <script src="../../js/jquery-3.6.0.min.js" defer></script> <!--[if lt IE 9]> <script src="../../js/html5shiv.min.js"></script> <![endif]--> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script> </head> <body class="wy-body-for-nav" role="document"> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav"> <div class="wy-side-scroll"> <div class="wy-side-nav-search"> <a href="../.." class="icon icon-home"> ServiceComb Java Chassis Developers Guide </a><div role="search"> <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get"> <input type="text" name="q" placeholder="Search docs" title="Type search term here" /> </form> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> <ul> <li class="toctree-l1"><a class="reference internal" href="../..">Introduction</a> </li> </ul> <p class="caption"><span class="caption-text">Getting Started</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../start/terminology/">Glossary</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/architecture/">Architecture</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/development-environment/">Development environment</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/first-sample/">Develop the first microservice</a> </li> </ul> <p class="caption"><span class="caption-text">Development Service Provider</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/definition/service-definition/">Service definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/define-contract/">Service contract definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/code-first/">Implicit API definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/swagger-annotation/">Use Swagger annotations</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/springmvc/">Develop with SpringMVC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/jaxrs/">Develop with JAX-RS</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/transparent-rpc/">Develop with Transparent RPC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/interface-constraints/">Interface definition and data type</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/listen-address-and-publish-address/">Service listening address and publishing address</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/thread-pool/">Thread pool</a> </li> <li class="toctree-l1"><a class="reference internal" href="#">Service Configuration</a> <ul> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/ratelimite-strategy/">Rate Limiting Policy</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/downgrade-strategy/">Fallback Policy</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/parameter-validator/">Parameter Validator</a> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/bootup/">Boot-up Process</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/access-log-configuration/">Access Log Configuration</a> </li> </ul> <p class="caption"><span class="caption-text">Writing Service Consumer</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/common-configuration/">Consumer common configuration</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-resttemplate/">Using Rest Template</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-AsyncRestTemplate/">Using AsyncRestTemplate</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/develop-consumer-using-rpc/">Using with RPC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/with-contract/">Contract</a> </li> <li class="toctree-l1"><a class="reference internal" href="#">Invoke control</a> <ul> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/circuit-breaker/">Circuit Breaker</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/flow-control/">Flow Control</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/fault-injection/">Fault Injection</a> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/3rd-party-service-invoke/">Invoke 3rd-party REST services</a> </li> </ul> <p class="caption"><span class="caption-text">Transports</span></p> <ul class="current"> <li class="toctree-l1 current"><a class="reference internal current" href="./">REST over Servlet</a> <ul class="current"> <li class="toctree-l2"><a class="reference internal" href="#path-for-external-access">Path for external access</a> </li> <li class="toctree-l2"><a class="reference internal" href="#maven-dependencies">maven dependencies</a> </li> <li class="toctree-l2"><a class="reference internal" href="#configurations">Configurations</a> </li> <li class="toctree-l2"><a class="reference internal" href="#configuration-example-for-typical-scenarios">Configuration example for typical scenarios</a> </li> <li class="toctree-l2"><a class="reference internal" href="#things-to-notice-with-servlet-filter">Things to notice with servlet filter</a> </li> <li class="toctree-l2"><a class="reference internal" href="#configuration-items">Configuration items</a> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../rest-over-vertx/">REST over Vertx</a> </li> <li class="toctree-l1"><a class="reference internal" href="../highway-rpc/">Highway</a> </li> <li class="toctree-l1"><a class="reference internal" href="../http2/">HTTP2</a> </li> </ul> <p class="caption"><span class="caption-text">General Development</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../general-development/visit-sc/">Access Service Center</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/metrics/">Metrics</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/microservice-invocation-chain/">Microservice invocation chain</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/customized-tracing/">Customized-Tracing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/local-develop-test/">Local development and testing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/http-filter/">Http Filter</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/file-upload/">File Uploading</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/file-download/">File Downloading</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/reactive/">Reactive Programing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/dnsconfig/">DNS Custom Configuration</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/dai-li-she-zhi/">Proxy Settings</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/report-framework-version/">Report framework version</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/cross-app-invocation/">Cross-application invocation</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/secret-field/">Customized serialization and deserialization</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/context/">Using Context to pass control messages</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/produceprocess/">Return value serialization extension</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/CORS/">CORS mechanism</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/AlarmEvent/">Get fuse and instance isolation alarm event information</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/shutdown/">Shutdown gracefully</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/error-handling/">Handling exceptions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/multienvironment/">Multi-environment isolation between microservice instances</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../general-development/thread-model/">Thread Model</a> </li> </ul> <p class="caption"><span class="caption-text">Configuration</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../config/general-config/">General config</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../config/inject-config/">Configuration injection</a> </li> </ul> <p class="caption"><span class="caption-text">Service Capability Open</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../edge/open-service/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/by-servicecomb-sdk/">Using Edge Service</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/nginx/">Using confd and Nginx as edge services</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/zuul/">Use zuul as edge services</a> </li> </ul> <p class="caption"><span class="caption-text">Service Packing and Running</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../packaging/standalone/">Standalone mode</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../packaging/web-container/">WEB container mode</a> </li> </ul> <p class="caption"><span class="caption-text">Micro Service Security</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../security/tls/">Using TLS</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../security/rsa/">Using RSA certification</a> </li> </ul> <p class="caption"><span class="caption-text">Using java chassis in Spring Boot</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/components-for-spring-boot/">spring boot starter for java-chassis</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/java-application/">JAVA application development</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/web-application/">Web development method development</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-between-java-web/">The difference between JAVA application method and Web development method</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-spring-mvc/">The difference in Spring MVC mode</a> </li> </ul> <p class="caption"><span class="caption-text">Handlers reference</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/intruduction/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/loadbalance/">Load Balancing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/publickey/">Public key authentication</a> </li> </ul> <p class="caption"><span class="caption-text">FAQ</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/question_answer/">Q & A</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/faq/">FAQ</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/interface-compatibility/">Micro Service Interface Compatibility FAQ</a> </li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu"> <i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="../..">ServiceComb Java Chassis Developers Guide</a> </nav> <div class="wy-nav-content"> <div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation"> <ul class="wy-breadcrumbs"> <li><a href="../.." class="icon icon-home" alt="Docs"></a> &raquo;</li> <li>Transports &raquo;</li> <li>REST over Servlet</li> <li class="wy-breadcrumbs-aside"> </li> </ul> <hr/> </div> <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div class="section" itemprop="articleBody"> <h1 id="rest-over-servlet">REST over Servlet</h1> <p>The REST over Servlet mode applications runs in web container. You need to create a new servlet project to wrap the microservices, pack them into war packages, and load them into the web container to run.</p> <h2 id="path-for-external-access">Path for external access</h2> <p>Not like running as a standalone process, when the microservice runs in the web container, the web root and servlet url pattern will be different.</p> <p>For the traditional development framework, the consumer needs to perceive the complete url of the service; for example, the web root is /mywebapp, the url pattern is /rest, and the business-level path is /application, then consumer must access the service via the url /mywebapp/rest/application.</p> <p>So when the deployment pattern changes, like from web container to a standalone process, the consumer or producer have to modify the code to adapt to the changes.</p> <p>It is recommended to use ServiceComb's deployment decoupling feature. Whether it is a consumer or a producer, the application don't perceive the web root and url pattern in the code, while ServiceComb will automatically adapt them for the producer instance at runtime.</p> <p>For some legacy systems, if users expect to use restTemplate.getForObject("cse://serviceName/mywebapp/rest/application"...) without too many changes, then the path of the interface should be defined as /mywebapp/rest/application:</p> <pre><code>@RestSchema(schemaId = &quot;test&quot;) @RequestMapping(path = &quot;/mywebapp/rest/application&quot;) </code></pre> <p>However, it is still recommended to use a deployment-independent way to write the code, which introduces less code modifications when the deployment pattern changes.</p> <h2 id="maven-dependencies">maven dependencies</h2> <pre><code class="language-xml">&lt;dependency&gt; &lt;groupId&gt;org.apache.servicecomb&lt;/groupId&gt; &lt;artifactId&gt;transport-rest-servlet&lt;/artifactId&gt; &lt;/dependency&gt; </code></pre> <h2 id="configurations">Configurations</h2> <p>When integrating with servlet, there are a few concepts involved:</p> <ul> <li> <p>Start spring context<br /> Note the following startup methods cannot be used at the same time, just choose one of them. </p> </li> <li> <p>Without SpringMVC UI or RestController</p> </li> </ul> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath*:META-INF/spring/*.bean.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.apache.servicecomb.transport.rest.servlet.RestServletContextListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt;</code></p> <p>The <code>classpath*:META-INF/spring/*.bean.xml</code> configured in contextConfigLocation is optional, because the ServiceComb will ensure that it is included in the load path.</p> <p>This is just an example to indicate that the user can customize the contextConfigLocation.</p> <ul> <li>Use SpringMVC UI or RestController, and org.apache.servicecomb.transport.rest.servlet.CseDispatcherServlet exists</li> </ul> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;servlet&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.servicecomb.transport.rest.servlet.CseDispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;yourUrlPattern&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt;</code></p> <p><strong>Note</strong><br /> This servlet is not the processing entry of ServiceComb, but the processing entry of UI or RestController.</p> <ul> <li> <p>Use SpringMVC's UI or RestController, and there is no org.apache.servicecomb.transport.rest.servlet.CseDispatcherServlet</p> <p>In this case, the application class should inherit SpringMVC's DispatcherServlet, and then configure its implementation classes in CseDispatcherServlet's way.</p> </li> </ul> <p><code>@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent){ setContextClass(CseXmlWebApplicationContext.class); return super.createWebApplicationContext(parent); }</code></p> <ul> <li>ServiceComb servlet </li> </ul> <p>The url pattern can be set according to the business logic. The following <code>/rest/*</code> is just an example, not a fixed value.</p> <p>Url pattern must end with <code>/*</code></p> <p>The following two declarations types can not be used at the same time.</p> <ul> <li>Standard declaration</li> </ul> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;servlet&gt; &lt;servlet-name&gt;RestServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.servicecomb.transport.rest.servlet.RestServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;async-supported&gt;true&lt;/async-supported&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;RestServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt;</code></p> <ul> <li>Quick declaration </li> </ul> <p><code>yaml servicecomb.rest.servlet.urlPattern: /rest/*</code></p> <p>Specify urlPattern in the microservice.yaml file. When ServiceComb starts, it will automatically create RestServlet and set the corresponding urlPattern.</p> <h2 id="configuration-example-for-typical-scenarios">Configuration example for typical scenarios</h2> <ul> <li>Standard declaration in pure ServiceComb mode</li> </ul> <p>web.xml: </p> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;listener&gt; &lt;listener-class&gt;org.apache.servicecomb.transport.rest.servlet.RestServletContextListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;RestServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.servicecomb.transport.rest.servlet.RestServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;async-supported&gt;true&lt;/async-supported&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;RestServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt;</code></p> <ul> <li>Quick declaration in pure ServiceComb mode web.xml: </li> </ul> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;listener&gt; &lt;listener-class&gt;org.apache.servicecomb.transport.rest.servlet.RestServletContextListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt;</code></p> <p>microservice.yaml:</p> <p><code>yaml servicecomb.rest.servlet.urlPattern: /rest/*</code></p> <ul> <li>SpringMVC or RestController provide web services, ServiceComb proxy the requests as consumer</li> </ul> <p>web.xml:</p> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;servlet&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.servicecomb.transport.rest.servlet.CseDispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;yourUrlPattern&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt;</code></p> <p>microservice.yaml: Servicecomb.rest.address and servicecomb.rest.servlet.urlPattern are not configured</p> <ul> <li>SpringMVC UI/RestController and ServiceComb provide services at the same time web.xml:</li> </ul> <p><code>xml &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;servlet&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.servicecomb.transport.rest.servlet.CseDispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;SpringMVCServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;yourUrlPattern&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt;</code></p> <p>microservice.yaml: </p> <p><code>yaml servicecomb: rest: servlet: urlPattern: /rest/* address: 0.0.0.0:8080</code></p> <h2 id="things-to-notice-with-servlet-filter">Things to notice with servlet filter</h2> <p>RestServlet works in asynchronous mode. According to the servlet 3.0 standard, the entire work chain must be asynchronous. Therefore, the servlet filter should be set to be asynchronous when it's added to the chain:</p> <pre><code class="language-xml">&lt;filter&gt; ...... &lt;async-supported&gt;true&lt;/async-supported&gt; &lt;/filter&gt; </code></pre> <h2 id="configuration-items">Configuration items</h2> <p>The related items for REST over Servlet in the microservice.yaml are described below:</p> <p>Table1-1 REST over Servlet Configuration Items</p> <table> <thead> <tr> <th align="left">Configuration Item</th> <th align="left">Default Value</th> <th align="left">Required</th> <th align="left">Description</th> </tr> </thead> <tbody> <tr> <td align="left">servicecomb.rest.address</td> <td align="left">0.0.0.0:8080</td> <td align="left">No</td> <td align="left">The service listening address<br>Should be the same with the web container's listening address</td> </tr> <tr> <td align="left">servicecomb.rest.server.timeout</td> <td align="left">-1</td> <td align="left">No</td> <td align="left">Server aync servlet timeout in milliseconds, suggest set to -1</td> </tr> <tr> <td align="left">servicecomb.rest.server.requestWaitInPoolTimeout</td> <td align="left">30000</td> <td align="left">No</td> <td align="left">for sync business logic, timeout in milliseconds for waiting in executor queue</td> </tr> <tr> <td align="left">servicecomb.rest.servlet.urlPattern</td> <td align="left"></td> <td align="left">No</td> <td align="left">Used to simplify servlet+servlet mapping config<br>This item is used only when servlet+servlet mapping is not configured in web.xml.The format is:/* or /path/*, where path can be nested</td> </tr> </tbody> </table> </div> </div><footer> <div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation"> <a href="../../build-consumer/3rd-party-service-invoke/" class="btn btn-neutral float-left" title="Invoke 3rd-party REST services"><span class="icon icon-circle-arrow-left"></span> Previous</a> <a href="../rest-over-vertx/" class="btn btn-neutral float-right" title="REST over Vertx">Next <span class="icon icon-circle-arrow-right"></span></a> </div> <hr/> <div role="contentinfo"> <!-- Copyright etc --> </div> Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <div class="rst-versions" role="note" aria-label="Versions"> <span class="rst-current-version" data-toggle="rst-current-version"> <span><a href="../../build-consumer/3rd-party-service-invoke/" style="color: #fcfcfc">&laquo; Previous</a></span> <span><a href="../rest-over-vertx/" style="color: #fcfcfc">Next &raquo;</a></span> </span> </div> <script>var base_url = '../..';</script> <script src="../../js/theme_extra.js" defer></script> <script src="../../js/theme.js" defer></script> <script src="../../search/main.js" defer></script> <script defer> window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; </script> </body> </html>