Authored by mali

初始化

@@ -12,93 +12,22 @@ @@ -12,93 +12,22 @@
12 <groupId>com.yoho.ufo</groupId> 12 <groupId>com.yoho.ufo</groupId>
13 <artifactId>ufo-platform-common</artifactId> 13 <artifactId>ufo-platform-common</artifactId>
14 <packaging>jar</packaging> 14 <packaging>jar</packaging>
15 -  
16 - <name>A Camel Route</name> 15 + <name>ufo-platform-common</name>
17 16
18 <properties> 17 <properties>
19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 19 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
21 </properties> 20 </properties>
22 21
23 - <dependencyManagement>  
24 - <dependencies>  
25 - <!-- Camel BOM -->  
26 - <dependency>  
27 - <groupId>org.apache.camel</groupId>  
28 - <artifactId>camel-parent</artifactId>  
29 - <version>2.22.1</version>  
30 - <scope>import</scope>  
31 - <type>pom</type>  
32 - </dependency>  
33 - </dependencies>  
34 - </dependencyManagement>  
35 22
36 <dependencies> 23 <dependencies>
37 -  
38 - <dependency>  
39 - <groupId>org.apache.camel</groupId>  
40 - <artifactId>camel-core</artifactId>  
41 - </dependency>  
42 -  
43 - <!-- logging -->  
44 - <dependency>  
45 - <groupId>org.apache.logging.log4j</groupId>  
46 - <artifactId>log4j-api</artifactId>  
47 - <scope>runtime</scope>  
48 - </dependency>  
49 <dependency> 24 <dependency>
50 - <groupId>org.apache.logging.log4j</groupId>  
51 - <artifactId>log4j-core</artifactId>  
52 - <scope>runtime</scope> 25 + <groupId>com.yoho.core</groupId>
  26 + <artifactId>yoho-core-rest-client-simple</artifactId>
53 </dependency> 27 </dependency>
54 <dependency> 28 <dependency>
55 - <groupId>org.apache.logging.log4j</groupId>  
56 - <artifactId>log4j-slf4j-impl</artifactId>  
57 - <scope>runtime</scope>  
58 - </dependency>  
59 -  
60 - <!-- testing -->  
61 - <dependency>  
62 - <groupId>org.apache.camel</groupId>  
63 - <artifactId>camel-test</artifactId>  
64 - <scope>test</scope> 29 + <groupId>com.yoho.core</groupId>
  30 + <artifactId>yoho-core-rest-server</artifactId>
65 </dependency> 31 </dependency>
66 </dependencies> 32 </dependencies>
67 -  
68 - <build>  
69 - <defaultGoal>install</defaultGoal>  
70 -  
71 - <plugins>  
72 - <plugin>  
73 - <groupId>org.apache.maven.plugins</groupId>  
74 - <artifactId>maven-compiler-plugin</artifactId>  
75 - <version>3.7.0</version>  
76 - <configuration>  
77 - <source>1.8</source>  
78 - <target>1.8</target>  
79 - </configuration>  
80 - </plugin>  
81 - <plugin>  
82 - <groupId>org.apache.maven.plugins</groupId>  
83 - <artifactId>maven-resources-plugin</artifactId>  
84 - <version>3.0.2</version>  
85 - <configuration>  
86 - <encoding>UTF-8</encoding>  
87 - </configuration>  
88 - </plugin>  
89 -  
90 - <!-- Allows the example to be run via 'mvn compile exec:java' -->  
91 - <plugin>  
92 - <groupId>org.codehaus.mojo</groupId>  
93 - <artifactId>exec-maven-plugin</artifactId>  
94 - <version>1.6.0</version>  
95 - <configuration>  
96 - <mainClass>com.yoho.ufo.MainApp</mainClass>  
97 - <includePluginDependencies>false</includePluginDependencies>  
98 - </configuration>  
99 - </plugin>  
100 -  
101 - </plugins>  
102 - </build>  
103 -  
104 </project> 33 </project>
1 package com.yohobuy.ufo.login.service; 1 package com.yohobuy.ufo.login.service;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import com.yohobuy.ufo.constants.PlatformConstant; 4 import com.yohobuy.ufo.constants.PlatformConstant;
4 import com.yohobuy.ufo.login.model.MenuInfoResponseBO; 5 import com.yohobuy.ufo.login.model.MenuInfoResponseBO;
5 import com.yohobuy.ufo.login.model.Response; 6 import com.yohobuy.ufo.login.model.Response;
@@ -10,6 +11,8 @@ import org.slf4j.Logger; @@ -10,6 +11,8 @@ import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.annotation.Value; 12 import org.springframework.beans.factory.annotation.Value;
12 import org.springframework.http.HttpEntity; 13 import org.springframework.http.HttpEntity;
  14 +import org.springframework.http.HttpHeaders;
  15 +import org.springframework.http.MediaType;
13 import org.springframework.http.ResponseEntity; 16 import org.springframework.http.ResponseEntity;
14 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
15 import org.springframework.util.LinkedMultiValueMap; 18 import org.springframework.util.LinkedMultiValueMap;
@@ -46,22 +49,25 @@ public class LoginService { @@ -46,22 +49,25 @@ public class LoginService {
46 String url = erpDomain + PlatformConstant.ERP_LOGIN_URL; 49 String url = erpDomain + PlatformConstant.ERP_LOGIN_URL;
47 logger.info("enter login with loginName={}, url is {}", loginName, url); 50 logger.info("enter login with loginName={}, url is {}", loginName, url);
48 51
49 - MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();  
50 - param.add("account", loginName);  
51 - param.add("password", password);  
52 - HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(param, null); 52 + HttpHeaders headers = new HttpHeaders();
  53 + MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
  54 + headers.setContentType(type);
  55 + headers.add("Accept", MediaType.APPLICATION_JSON.toString());
  56 + JSONObject jsonObj = new JSONObject();
  57 + jsonObj.put("account", loginName);
  58 + jsonObj.put("password", password);
  59 + HttpEntity<String> formEntity = new HttpEntity<String>(jsonObj.toString(), headers);
53 60
54 - ResponseEntity<Response> responseResponseEntity = restTemplate.postForEntity(url, requestEntity, Response.class); 61 + ResponseEntity<Object> responseResponseEntity = restTemplate.postForEntity(url, formEntity, Object.class);
  62 + Map<String, Object> body = (Map<String, Object>) responseResponseEntity.getBody();
  63 + Map<String, Object> data = (Map<String, Object>) body.get("data");
55 64
56 65
57 logger.info("login success with loginName={}, responseResponseEntity={}", loginName, responseResponseEntity); 66 logger.info("login success with loginName={}, responseResponseEntity={}", loginName, responseResponseEntity);
58 UserInfoResponseBO user = new UserInfoResponseBO(); 67 UserInfoResponseBO user = new UserInfoResponseBO();
59 - Response body = responseResponseEntity.getBody();  
60 - Object data = body.getData();  
61 68
62 logger.info("login success with loginName={}, data={}", loginName, data); 69 logger.info("login success with loginName={}, data={}", loginName, data);
63 -  
64 - setUser((Map<String, Object>) data, user); 70 + setUser(data, user);
65 return new Response<>(user); 71 return new Response<>(user);
66 } 72 }
67 73
@@ -94,6 +94,15 @@ @@ -94,6 +94,15 @@
94 94
95 <dependency> 95 <dependency>
96 <groupId>com.yoho.core</groupId> 96 <groupId>com.yoho.core</groupId>
  97 + <artifactId>yoho-core-rest-client-simple</artifactId>
  98 + </dependency>
  99 + <dependency>
  100 + <groupId>com.yoho.core</groupId>
  101 + <artifactId>yoho-core-rest-server</artifactId>
  102 + </dependency>
  103 +
  104 + <dependency>
  105 + <groupId>com.yoho.core</groupId>
97 <artifactId>yoho-core-cache</artifactId> 106 <artifactId>yoho-core-cache</artifactId>
98 </dependency> 107 </dependency>
99 108