[JAVA] Solution of component that saves cookie when Talend WebAPI data is acquired

How can I get uniqid when I get data with Talend Web API?

Way of thinking: ・ Uniqid is saved as a cookie -Talend confirms that there is no component that acquires cookies. -Create a java component that acquires cookies by hand.

image: 11.jpg

java source: //変数を定義する String strPonit ="{"uniqid":""; String domainurl = "xxxxxxxxxxxxxxxxxxxxxx"; String content_type = "application/x-www-form-urlencoded"; String apikey = "xxxxxxxxxxxxxxxxxxxxxx"; String login_id ="xxxxxxxxxxxxxxxxxxxxxx"; String login_password ="xxxxxxxxxxxxxxxxxxxxxx"; String udid ="xxxxxxxxxxxxxxxxxxxxxx"; context.put("udid",udid); //画面請求のパラメータ apikey =String.format(apikey, login_id, login_password,udid); java.net.URL url = new java.net.URL(domainurl); java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", content_type); conn.setDoOutput(true); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(apikey); out.flush(); out.close(); java.util.Map<String, List> map = conn.getHeaderFields(); //画面のcookieを取得 context.put("Cookie",map.get("Set-Cookie").get(0)); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { int startPonit = inputLine.indexOf(strPonit) + strPonit.length(); int endPonit = inputLine.indexOf(""",startPonit); //請求の成功したら、画面のuniqidを取得する context.put("uniqid",inputLine.substring(startPonit, endPonit)); //System.out.println(inputLine); } in.close();

image: 12.jpg

HTTP body: "action=list&table=products_class&limit=50000000&offset=0&udid="+(String)context.get("udid")+"&uniqid="+(String)context.get("uniqid")

Note: Jobs are updated to personal GIT (private)

that's all

Recommended Posts

Solution of component that saves cookie when Talend WebAPI data is acquired
LIMIT 11 when data is acquired by irb
When the month of the date is acquired, the January shift
About the solution to the problem that the log of logback is not output when the web application is stopped