Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
git commit -m init
  • Loading branch information
fangp committed Apr 13, 2018
1 parent 2d0e166 commit 034f0a6
Show file tree
Hide file tree
Showing 72 changed files with 3,466 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*/target
*.iml
/.idea
.idea
*.class
target/
.project
.settings/
.classpath
logs
42 changes: 42 additions & 0 deletions api-gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>spring-cloud</artifactId>
<groupId>com.github.peng</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>api-gateway</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.peng.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

/**
* Created by fp295 on 2018/4/10.
*/
@EnableZuulProxy
@SpringCloudApplication
public class ApiGatewayApplication {
public static void main(String[] args){
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
16 changes: 16 additions & 0 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
spring:
cloud:
consul:
host: 127.0.0.1
port: 8500
discovery:
prefer-ip-address: true
application:
name: api-gateway
server:
port: 21000
zuul:
routes:
main-data:
path: /main-data/api/**
serviceId: main-data
21 changes: 21 additions & 0 deletions auth-center/auth-center-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>auth-center</artifactId>
<groupId>com.github.peng</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>auth-center-api</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.peng.auth.api.config;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;


public class RedisObjectSerializer implements RedisSerializer {

static final byte[] EMPTY_ARRAY = new byte[0];

private Converter<Object, byte[]> serializer = new SerializingConverter();
private Converter<byte[], Object> deserializer = new DeserializingConverter();

@Override
public byte[] serialize(Object o) throws SerializationException {
if(o == null)
return EMPTY_ARRAY;
try {
return serializer.convert(o);
}catch (Exception e){
return EMPTY_ARRAY;
}

}

@Override
public Object deserialize(byte[] bytes) throws SerializationException {
if(isEmpty(bytes))
return null;
try {
return deserializer.convert(bytes);
}catch (Exception e){
throw new SerializationException("Cannot deserialize", e);
}
}

private boolean isEmpty(byte[] bytes){
return (bytes == null || bytes.length == 0) ;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.peng.auth.api.pojo;

public enum ResponseCode {

SUCCESS(1200, "success."),
ERROR(1201, "error."),
PARA_ERROR(1202, "parameters error.");

ResponseCode(Integer code, String message) {
this.code = code;
this.message = message;
}

private Integer code;

private String message;

public Integer getCode() {
return code;
}

public void setCode(Integer code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
51 changes: 51 additions & 0 deletions auth-center/auth-center-provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>auth-center</artifactId>
<groupId>com.github.peng</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>auth-center-provider</artifactId>
<packaging>jar</packaging>


<dependencies>
<dependency>
<groupId>com.github.peng</groupId>
<artifactId>auth-center-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.peng</groupId>
<artifactId>main-data-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.peng.auth.provider;

import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;

/**
* Created by fp295 on 2018/4/2.
*/
@SpringCloudApplication
public class AuthCenterProviderApplication {
public static void main(String[] args){
SpringApplication.run(AuthCenterProviderApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.peng.auth.provider.config.redis;

import com.peng.auth.api.config.RedisObjectSerializer;
import com.peng.main.api.mapper.model.BaseModuleResources;
import com.peng.main.api.mapper.model.BaseRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
* Created by fp295 on 2018/4/12.
*/
@Configuration
public class RedisAuthConfiguration {

@Autowired
private JedisConnectionFactory con;

@Bean
public RedisTemplate<String, BaseRole> baseRoleTemplate() {
RedisTemplate<String, BaseRole> template = new RedisTemplate();
template.setConnectionFactory(con);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisObjectSerializer());
return template;
}

@Bean
public RedisTemplate<String, BaseModuleResources> baseModelTemplate() {
RedisTemplate<String, BaseModuleResources> template = new RedisTemplate();
template.setConnectionFactory(con);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisObjectSerializer());
return template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server:
context-path: /auth
port: 21001
spring:
cloud:
consul:
host: 127.0.0.1
port: 8500
discovery:
prefer-ip-address: true
health-check-path: ${server.context-path}/health
tags: management.context-path=${server.context-path}
application:
name: auth-center
redis:
database: 0
host: 127.0.0.1
port: 6379
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.peng.auth.provider;

import com.peng.main.api.mapper.model.BaseRole;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Created by fp295 on 2018/4/12.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {

@Autowired
private RedisTemplate<String, BaseRole> baseRoleTemplate;

@Test
public void test() throws Exception {

BaseRole baseRole = new BaseRole();
baseRole.setId("id");
baseRole.setRoleCode("code");
baseRoleTemplate.opsForValue().set(baseRole.getId(), baseRole);
Assert.assertEquals(baseRole.getRoleCode(), baseRoleTemplate.opsForValue().get(baseRole.getId()).getRoleCode());

}

}
19 changes: 19 additions & 0 deletions auth-center/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>spring-cloud</artifactId>
<groupId>com.github.peng</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>auth-center-provider</module>
<module>auth-center-api</module>
</modules>
<artifactId>auth-center</artifactId>


</project>
Loading

0 comments on commit 034f0a6

Please sign in to comment.