Tag - 微服务

跨域 TYK MicroService 微服务    2017-07-19 21:39:10    3
浏览器端报错:

"NetworkError: 403 Forbidden - http://192.168.10.147:8080/mytest/helloworld"
helloworld
已阻止跨源请求:同源策略禁止读取位于 http://192.168.10.147:8080/mytest/helloworld 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。

tomcat报错:

192.168.10.147 - - [02/Mar/2016:19:13:41 +0800] "OPTIONS /testjersey/rest/helloworld HTTP/1.1" 403 107
192.168.10.147 - - [02/Mar/2016:19:14:50 +0800] "GET /testjersey/rest/helloworld HTTP/1.1" 200 23


解析:

关于跨域,我使用的是如下地址的方案:http://blog.csdn.net/gsying1474/article/details/49664883
但是在配置方面,在web.xml中,部分配置如下
<init-param>
    <param-name>cors.supportedHeaders</param-name>
    <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>

而tyk中使用了Authorization在头部信息中,

解决办法:
    在init-param配置中,“cors.supportedHeaders”配置添加Authorization即可
 
 

 

by 刘迎光@萤火虫工作室 
OpenBI交流群:495266201 
MicroService 微服务交流群:217722918 
mail: liuyg#liuyingguang.cn 
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

jersey java 拦截器 微服务 MicroService    2017-07-19 21:37:32    13
1、web.xml配置
    <servlet>
        <servlet-name>Rest_Servlet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>cn.firewarm.testRestShiro.rest</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
            <param-value>cn.firewarm.testRestShiro.filter.TestFilter</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

2、TestFilter代码
public class TestFilter implements ContainerRequestFilter {
    public ContainerRequest filter(ContainerRequest request) {
        if(判断条件){
            return request;
        }else{
            Response response = Response.ok("error").status(401).type(MediaType.APPLICATION_JSON).build();  
            throw new WebApplicationException(response); // Throw new UnAuthor
jetty jersey 微服务 MicroService    2017-07-19 21:36:34    14

材料:

    Docker
    java+jersey 的demo:https://git.coding.net/firewarm/jetty-jersey.git
    jenkins:详细信息参考文章:http://blog.csdn.net/gsying1474/article/details/51126522

创建一个maven风格的项目,源码管理选择git,填上如上demo的地址,然后添加“post-build step”


填写参数,这里主要我暂时不需要push到registry上,所以选择跳过



都填写完毕后,构建即可,构建完成后,运行docker
# docker run -d -p 8090:8080 test-jetty

待启动完成后,访问地址:http://192.168.10.136:8090/jetty-jersey/status
返回RUNNING则表示构建部署成功了

 

by 刘迎光@萤火虫工作室 
OpenBI交流群:495266201 
MicroService 微服务交流群:217722918 
mail: liuyg#liuyingguang.cn 
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

docker 微服务 MicroService    2017-07-19 21:30:08    28
本项目是将restful项目打包成可执行的war包,在docker中执行

环境介绍:

    docker    1.10.3
    jetty    8
    jersey    1.19

关键配置:
1、pom.xml配置
<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <systemProperties>
                    </systemProperties>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </pl
微服务 MicroService nodejs http 反向代理    2017-07-19 20:20:45    4

最近在做微服务相关产品,其中需要有API网关相关产品,虽然早有研究过API网关产品TYK,但是感觉其太重,想起之前研究开源BI产品saiku的时候,记得其有NodeJS的代理代码,于是看了下,颇有启发,略微修改了一些,拿出来跟大家分享下,虽然简单,不可用于生产,但是对于学习还是不错的

package.json

  1. {
  2. "name": "SmartHttpProxy",
  3. "description": "An simplest Http Proxy",
  4. "version": "0.0.1",
  5. "author": "liuyg@liuyingguang.cn",
  6. "license": {
  7. "type": "Apache License Version 2"
  8. },
  9. "main": "server.js",
  10. "scripts": {
  11. "start": "node server.js 8088 127.0.0.1 80 / "
  12. },
  13. "dependencies": {
  14. "express": "~4.13.4"
  15. }
  16. }

server.js

  1. /*
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either e
2/4