org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter Java Examples

The following examples show how to use org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (!request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
Example #2
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #3
Source File: HttpProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #4
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #5
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #6
Source File: HttpProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private <T> HttpInvokerServiceExporter createExporter(T impl, Class<?> type) {
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    return httpServiceExporter;
}
 
Example #7
Source File: SpitterConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Bean
public HttpInvokerServiceExporter httpInvokerServiceExporter(
		SpitterService spitterService) {
	HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
	exporter.setService(spitterService);
	exporter.setServiceInterface(SpitterService.class);
	return exporter;
}
 
Example #8
Source File: HttpInvokerConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean(name = "/httpInvoker/userService")
public HttpInvokerServiceExporter httpInvokerServiceExporter() {
    final HttpInvokerServiceExporter invokerService = new HttpInvokerServiceExporter();
    invokerService.setService(userService);
    invokerService.setServiceInterface(UserService.class);
    return invokerService;
}
 
Example #9
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (! request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
Example #10
Source File: HttpProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (! request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
Example #11
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (! request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
Example #12
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void handle(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String uri = request.getRequestURI();
    HttpInvokerServiceExporter skeleton = skeletonMap.get(uri);
    if (! request.getMethod().equalsIgnoreCase("POST")) {
        response.setStatus(500);
    } else {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
        try {
            skeleton.handleRequest(request, response);
        } catch (Throwable e) {
            throw new ServletException(e);
        }
    }
}
 
Example #13
Source File: RemoteServiceScannerRegistrar.java    From seed with Apache License 2.0 4 votes vote down vote up
private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
    for(BeanDefinitionHolder holder : beanDefinitions){
        try {
            //获取每个标注了@RemoteService注解的所有属性及其值,得到一个Map
            MetadataReader metadataReader = this.getMetadataReaderFactory().getMetadataReader(holder.getBeanDefinition().getBeanClassName());
            AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(metadataReader.getAnnotationMetadata().getAnnotationAttributes(RemoteService.class.getName()));
            if(null==annoAttrs || annoAttrs.isEmpty()){
                continue;
            }
            //计算serviceInterface
            Class<?> serviceInterface = annoAttrs.getClass("value");
            if(null == serviceInterface){
                serviceInterface = annoAttrs.getClass("serviceInterface");
            }
            if("java.lang.Class".equals(serviceInterface.getName())){
                throw new IllegalArgumentException("undefined service interface on RemoteService class: " + holder.getBeanDefinition().getBeanClassName());
            }
            //计算服务路径("/" + path + "/" + name)
            String name = annoAttrs.getString("name").trim();
            if(StringUtils.isBlank(name)){
                name = serviceInterface.getSimpleName();
            }
            String path = annoAttrs.getString("path").trim();
            if(StringUtils.isNotBlank(path)){
                if(path.endsWith("/")){
                    name = path + name;
                }else{
                    name = path + "/" + name;
                }
            }
            if(!name.startsWith("/")){
                name = "/" + name;
            }
            //通过Spring提供的HttpInvokerServiceExporter输出服务,该类可以将普通Bean实例输出成远程服务
            //这里是比较关键的:因为我们需要自己设定哪个Bean输出服务,哪个Bean不用输出,所以才自定义注解来实现
            //@RemoteServiceScan和@RemoteService的目的就是找到我们希望输出服务的Bean,然后手工注册Bean并输出
            GenericBeanDefinition definition = new GenericBeanDefinition();
            definition.getPropertyValues().add("service", new RuntimeBeanReference(holder.getBeanName()));
            definition.getPropertyValues().add("serviceInterface", serviceInterface);
            definition.setInitMethodName("afterPropertiesSet");
            definition.setBeanClass(HttpInvokerServiceExporter.class);
            this.registerBeanDefinition(new BeanDefinitionHolder(definition, name), this.getRegistry());
        }catch(IOException e){
            throw new BeanDefinitionStoreException("Failed to read candidate component class: " + holder.getBeanDefinition().getBeanClassName(), e);
        }
    }
}
 
Example #14
Source File: Server.java    From tutorials with MIT License 4 votes vote down vote up
@Bean(name = "/booking") HttpInvokerServiceExporter accountService() {
    HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
    exporter.setService( new CabBookingServiceImpl() );
    exporter.setServiceInterface( CabBookingService.class );
    return exporter;
}