| 10138 |
vikram.rag |
1 |
package in.shop2020;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.IOException;
|
|
|
5 |
import java.io.InputStreamReader;
|
|
|
6 |
import java.io.UnsupportedEncodingException;
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
import org.apache.http.HttpResponse;
|
|
|
11 |
import org.apache.http.NameValuePair;
|
|
|
12 |
import org.apache.http.client.ClientProtocolException;
|
|
|
13 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
14 |
import org.apache.http.client.methods.HttpGet;
|
|
|
15 |
import org.apache.http.client.methods.HttpPost;
|
|
|
16 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
17 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
18 |
|
|
|
19 |
public class UpdateSDIUsingPanel {
|
|
|
20 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
| 13888 |
manish.sha |
21 |
public static void main(String... args) throws ClientProtocolException, IOException, InterruptedException{
|
| 10882 |
vikram.rag |
22 |
System.out.println("Inside main");
|
| 10162 |
vikram.rag |
23 |
UpdateSDIUsingPanel UDSI = new UpdateSDIUsingPanel();
|
| 13888 |
manish.sha |
24 |
UDSI.handleLogin();
|
| 10882 |
vikram.rag |
25 |
System.out.println("Created UD Inventory object");
|
| 13888 |
manish.sha |
26 |
UDSI.updateInventory(32L,"SDL689893640");
|
| 10882 |
vikram.rag |
27 |
System.out.println("After calling update inventory");
|
| 10138 |
vikram.rag |
28 |
|
|
|
29 |
}
|
| 13888 |
manish.sha |
30 |
int updateInventory(long stock,String supc) throws ClientProtocolException, IOException, InterruptedException{
|
| 10138 |
vikram.rag |
31 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/inventory/update");
|
|
|
32 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
| 13878 |
manish.sha |
33 |
System.out.println("Calling update inventory: Supc: "+supc+ " to be update stock: "+ stock);
|
| 13860 |
manish.sha |
34 |
nameValuePairs.add(new BasicNameValuePair("changedField",
|
|
|
35 |
"inventory"));
|
|
|
36 |
nameValuePairs.add(new BasicNameValuePair("changedValue",
|
| 10138 |
vikram.rag |
37 |
String.valueOf(stock)));
|
| 10882 |
vikram.rag |
38 |
nameValuePairs.add(new BasicNameValuePair("supc",
|
| 10138 |
vikram.rag |
39 |
supc));
|
|
|
40 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
41 |
HttpResponse response = client.execute(post);
|
|
|
42 |
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
43 |
String line = "";
|
|
|
44 |
while ((line = rd.readLine()) != null) {
|
| 13889 |
manish.sha |
45 |
System.out.println("Response of Inventory Update: "+line);
|
| 10138 |
vikram.rag |
46 |
}
|
| 13888 |
manish.sha |
47 |
Thread.sleep(1000);
|
| 10138 |
vikram.rag |
48 |
return 1;
|
|
|
49 |
}
|
|
|
50 |
|
| 10166 |
vikram.rag |
51 |
public void handleLogin() throws ClientProtocolException, IOException{
|
| 13853 |
manish.sha |
52 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
| 10138 |
vikram.rag |
53 |
HttpResponse response = null;
|
| 10397 |
vikram.rag |
54 |
boolean response_not_null = true;
|
| 10138 |
vikram.rag |
55 |
BufferedReader rd = null;
|
| 10397 |
vikram.rag |
56 |
while(response_not_null){
|
|
|
57 |
try {
|
|
|
58 |
response = client.execute(get);
|
|
|
59 |
} catch (Exception e) {
|
|
|
60 |
e.printStackTrace();
|
|
|
61 |
continue;
|
|
|
62 |
}
|
|
|
63 |
try {
|
|
|
64 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
65 |
} catch (Exception e1) {
|
|
|
66 |
e1.printStackTrace();
|
|
|
67 |
continue;
|
|
|
68 |
}
|
|
|
69 |
response_not_null = false;
|
| 10138 |
vikram.rag |
70 |
}
|
|
|
71 |
String line = "";
|
|
|
72 |
StringBuffer sb = new StringBuffer();
|
|
|
73 |
try {
|
|
|
74 |
while ((line = rd.readLine()) != null) {
|
|
|
75 |
sb.append(line);
|
|
|
76 |
}
|
|
|
77 |
} catch (IOException e) {
|
|
|
78 |
e.printStackTrace();
|
|
|
79 |
}
|
|
|
80 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
|
|
81 |
char[] charArray = sb.toString().toCharArray();
|
|
|
82 |
String lt = "";
|
|
|
83 |
int j=0;
|
|
|
84 |
for(j=i+16;j<=charArray.length;j++){
|
|
|
85 |
|
|
|
86 |
if(charArray[j]==' '){
|
|
|
87 |
break;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
lt = sb.substring(i+17,j-1);
|
|
|
91 |
System.out.println("LT VALUE " + lt);
|
|
|
92 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
|
|
93 |
charArray = sb.toString().toCharArray();
|
|
|
94 |
String ex = "";
|
|
|
95 |
j=0;
|
|
|
96 |
for(j=i+24;j<=charArray.length;j++){
|
|
|
97 |
if(charArray[j]==' '){
|
|
|
98 |
break;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
ex = sb.substring(i+24,j-1);
|
|
|
102 |
System.out.println("EXECUTION VALUE " + ex);
|
|
|
103 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
|
|
104 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
105 |
//nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
106 |
//"khushal.bhatia@saholic.com"));
|
|
|
107 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
108 |
"saholic-snapdeal@saholic.com"));
|
|
|
109 |
//nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
110 |
//"sonline"));
|
|
|
111 |
nameValuePairs.add(new BasicNameValuePair("password",
|
| 11266 |
vikram.rag |
112 |
"snapsaholic"));
|
| 10138 |
vikram.rag |
113 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
|
|
114 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
|
|
115 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
|
|
116 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
|
|
117 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
118 |
response = client.execute(post);
|
|
|
119 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
120 |
line = "";
|
|
|
121 |
while ((line = rd.readLine()) != null) {
|
|
|
122 |
System.out.println(line);
|
|
|
123 |
}
|
|
|
124 |
get = new HttpGet("http://seller.snapdeal.com/inventory/");
|
|
|
125 |
response = client.execute(get);
|
|
|
126 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
127 |
while ((line = rd.readLine()) != null) {
|
| 13860 |
manish.sha |
128 |
System.out.println(line);
|
| 10138 |
vikram.rag |
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
}
|