Search in sources :

Example 1 with SERVER_KEY

use of org.apache.dubbo.remoting.Constants.SERVER_KEY in project dubbo by alibaba.

the class RestProtocol method doExport.

@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = getAddr(url);
    Class implClass = ApplicationModel.getProviderModel(url.getServiceKey()).getServiceInstance().getClass();
    RestProtocolServer server = (RestProtocolServer) serverMap.computeIfAbsent(addr, restServer -> {
        RestProtocolServer s = serverFactory.createServer(url.getParameter(SERVER_KEY, DEFAULT_SERVER));
        s.setAddress(url.getAddress());
        s.start(url);
        return s;
    });
    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(SERVER_KEY, DEFAULT_SERVER))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " + "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " + "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }
    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
    server.deploy(resourceDef, impl, contextPath);
    final RestProtocolServer s = server;
    return () -> {
        // TODO due to dubbo's current architecture,
        // it will be called from registry protocol in the shutdown process and won't appear in logs
        s.undeploy(resourceDef);
    };
}
Also used : TIMEOUT_KEY(org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY) DEFAULT_CONNECT_TIMEOUT(org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT) AbstractProxyProtocol(org.apache.dubbo.rpc.protocol.AbstractProxyProtocol) INTERFACE_KEY(org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY) BasicHeaderElementIterator(org.apache.http.message.BasicHeaderElementIterator) SERVER_KEY(org.apache.dubbo.remoting.Constants.SERVER_KEY) SocketConfig(org.apache.http.config.SocketConfig) RequestConfig(org.apache.http.client.config.RequestConfig) COMMA_SPLIT_PATTERN(org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN) BootstrapListener(org.apache.dubbo.remoting.http.servlet.BootstrapListener) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) StringUtils(org.apache.dubbo.common.utils.StringUtils) URL(org.apache.dubbo.common.URL) Map(java.util.Map) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) GetRestful(org.jboss.resteasy.util.GetRestful) LinkedList(java.util.LinkedList) HttpBinder(org.apache.dubbo.remoting.http.HttpBinder) HTTP(org.apache.http.protocol.HTTP) HeaderElementIterator(org.apache.http.HeaderElementIterator) DEFAULT_TIMEOUT(org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) EXTENSION_KEY(org.apache.dubbo.rpc.protocol.rest.Constants.EXTENSION_KEY) ApplicationModel(org.apache.dubbo.rpc.model.ApplicationModel) CONNECTIONS_KEY(org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY) RpcException(org.apache.dubbo.rpc.RpcException) HeaderElement(org.apache.http.HeaderElement) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CONNECT_TIMEOUT_KEY(org.apache.dubbo.remoting.Constants.CONNECT_TIMEOUT_KEY) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ServletManager(org.apache.dubbo.remoting.http.servlet.ServletManager) ProcessingException(javax.ws.rs.ProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) ServletContext(javax.servlet.ServletContext) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Collections(java.util.Collections) RpcException(org.apache.dubbo.rpc.RpcException) BootstrapListener(org.apache.dubbo.remoting.http.servlet.BootstrapListener) ServletContext(javax.servlet.ServletContext)

Aggregations

Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 ServletContext (javax.servlet.ServletContext)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 URL (org.apache.dubbo.common.URL)1 COMMA_SPLIT_PATTERN (org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN)1 DEFAULT_TIMEOUT (org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT)1 INTERFACE_KEY (org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY)1 TIMEOUT_KEY (org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY)1 StringUtils (org.apache.dubbo.common.utils.StringUtils)1 CONNECTIONS_KEY (org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY)1 CONNECT_TIMEOUT_KEY (org.apache.dubbo.remoting.Constants.CONNECT_TIMEOUT_KEY)1 DEFAULT_CONNECT_TIMEOUT (org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT)1 SERVER_KEY (org.apache.dubbo.remoting.Constants.SERVER_KEY)1 HttpBinder (org.apache.dubbo.remoting.http.HttpBinder)1 BootstrapListener (org.apache.dubbo.remoting.http.servlet.BootstrapListener)1