-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'ebbdd8a3e64fbf848ef94796d31eee5b6d29ef77'
# Conflicts: # pom.xml
- Loading branch information
Showing
85 changed files
with
4,377 additions
and
3,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/ec/survey/controller/EuCaptchaApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.ec.survey.controller; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.CookieHandler; | ||
import java.net.CookieManager; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.List; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
@RequestMapping("/EuCaptchaApi") | ||
public class EuCaptchaApiController extends BasicController { | ||
|
||
@RequestMapping(value = "/captchaImg", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody String captchaImg(String locale, String capitalized, HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
sessionService.initializeProxy(); | ||
|
||
CookieManager cookieManager = new CookieManager(); | ||
CookieHandler.setDefault(cookieManager); | ||
|
||
URL url = new URL(captchaserverprefixtarget + "captchaImg?locale=" + locale + "&capitalized=" + capitalized); | ||
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); | ||
conn.setRequestMethod("GET"); | ||
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); | ||
|
||
String xjwtString = conn.getHeaderField("x-jwtString"); | ||
response.setHeader("x-jwtString", xjwtString); | ||
|
||
List<String> cookies = conn.getHeaderFields().get("set-cookie"); | ||
response.addHeader("original-cookie", cookies == null ? "" : String.join("#", cookies)); | ||
|
||
return readData(conn); | ||
} | ||
|
||
@RequestMapping(value = "/reloadCaptchaImg/{captchaId}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody String reloadCaptchaImg(@PathVariable String captchaId, HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
sessionService.initializeProxy(); | ||
|
||
CookieManager cookieManager = new CookieManager(); | ||
CookieHandler.setDefault(cookieManager); | ||
|
||
String locale = request.getParameter("locale"); | ||
String capitalized = request.getParameter("capitalized"); | ||
URL url = new URL(captchaserverprefixtarget + "reloadCaptchaImg/" + captchaId + "?locale=" + locale + "&capitalized=" + capitalized); | ||
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); | ||
conn.setRequestMethod("GET"); | ||
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); | ||
|
||
String xjwtString = request.getHeader("x-jwtstring"); | ||
conn.setRequestProperty("x-jwtString", xjwtString); | ||
|
||
String[] cookies = request.getHeader("original-cookie").split("#"); | ||
for (String cookie : cookies) { | ||
conn.addRequestProperty("Cookie", cookie); | ||
} | ||
|
||
xjwtString = conn.getHeaderField("x-jwtString"); | ||
response.setHeader("x-jwtString", xjwtString); | ||
|
||
return readData(conn); | ||
} | ||
|
||
private String readData(HttpURLConnection conn) throws IOException { | ||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); | ||
StringBuilder sb = new StringBuilder(); | ||
for (int c; (c = in.read()) >= 0;) { | ||
sb.append((char)c); | ||
} | ||
in.close(); | ||
return sb.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.