| 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();
|
|
|
21 |
public static void main(String... args) throws ClientProtocolException, IOException{
|
| 10882 |
vikram.rag |
22 |
System.out.println("Inside main");
|
| 10162 |
vikram.rag |
23 |
UpdateSDIUsingPanel UDSI = new UpdateSDIUsingPanel();
|
| 10882 |
vikram.rag |
24 |
System.out.println("Created UD Inventory object");
|
|
|
25 |
UDSI.updateInventory(98L,"SDL061548809");
|
|
|
26 |
System.out.println("After calling update inventory");
|
| 10138 |
vikram.rag |
27 |
|
|
|
28 |
}
|
| 10162 |
vikram.rag |
29 |
int updateInventory(long stock,String supc) throws ClientProtocolException, IOException{
|
| 10138 |
vikram.rag |
30 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/inventory/update");
|
|
|
31 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
32 |
nameValuePairs.add(new BasicNameValuePair("availableInventory",
|
|
|
33 |
String.valueOf(stock)));
|
| 10882 |
vikram.rag |
34 |
nameValuePairs.add(new BasicNameValuePair("supc",
|
| 10138 |
vikram.rag |
35 |
supc));
|
|
|
36 |
nameValuePairs.add(new BasicNameValuePair("oper","edit"));
|
|
|
37 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
38 |
HttpResponse response = client.execute(post);
|
|
|
39 |
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
40 |
String line = "";
|
|
|
41 |
while ((line = rd.readLine()) != null) {
|
|
|
42 |
System.out.println(line);
|
|
|
43 |
}
|
|
|
44 |
return 1;
|
|
|
45 |
}
|
|
|
46 |
|
| 10166 |
vikram.rag |
47 |
public void handleLogin() throws ClientProtocolException, IOException{
|
| 10138 |
vikram.rag |
48 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
|
|
|
49 |
HttpResponse response = null;
|
| 10397 |
vikram.rag |
50 |
boolean response_not_null = true;
|
| 10138 |
vikram.rag |
51 |
BufferedReader rd = null;
|
| 10397 |
vikram.rag |
52 |
while(response_not_null){
|
|
|
53 |
try {
|
|
|
54 |
response = client.execute(get);
|
|
|
55 |
} catch (Exception e) {
|
|
|
56 |
e.printStackTrace();
|
|
|
57 |
continue;
|
|
|
58 |
}
|
|
|
59 |
try {
|
|
|
60 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
61 |
} catch (Exception e1) {
|
|
|
62 |
e1.printStackTrace();
|
|
|
63 |
continue;
|
|
|
64 |
}
|
|
|
65 |
response_not_null = false;
|
| 10138 |
vikram.rag |
66 |
}
|
|
|
67 |
String line = "";
|
|
|
68 |
StringBuffer sb = new StringBuffer();
|
|
|
69 |
try {
|
|
|
70 |
while ((line = rd.readLine()) != null) {
|
|
|
71 |
sb.append(line);
|
|
|
72 |
}
|
|
|
73 |
} catch (IOException e) {
|
|
|
74 |
e.printStackTrace();
|
|
|
75 |
}
|
|
|
76 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
|
|
77 |
char[] charArray = sb.toString().toCharArray();
|
|
|
78 |
String lt = "";
|
|
|
79 |
int j=0;
|
|
|
80 |
for(j=i+16;j<=charArray.length;j++){
|
|
|
81 |
|
|
|
82 |
if(charArray[j]==' '){
|
|
|
83 |
break;
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
lt = sb.substring(i+17,j-1);
|
|
|
87 |
System.out.println("LT VALUE " + lt);
|
|
|
88 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
|
|
89 |
charArray = sb.toString().toCharArray();
|
|
|
90 |
String ex = "";
|
|
|
91 |
j=0;
|
|
|
92 |
for(j=i+24;j<=charArray.length;j++){
|
|
|
93 |
if(charArray[j]==' '){
|
|
|
94 |
break;
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
ex = sb.substring(i+24,j-1);
|
|
|
98 |
System.out.println("EXECUTION VALUE " + ex);
|
|
|
99 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
|
|
100 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
101 |
//nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
102 |
//"khushal.bhatia@saholic.com"));
|
|
|
103 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
104 |
"saholic-snapdeal@saholic.com"));
|
|
|
105 |
//nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
106 |
//"sonline"));
|
|
|
107 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
108 |
"bc452ce4"));
|
|
|
109 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
|
|
110 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
|
|
111 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
|
|
112 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
|
|
113 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
114 |
response = client.execute(post);
|
|
|
115 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
116 |
line = "";
|
|
|
117 |
while ((line = rd.readLine()) != null) {
|
|
|
118 |
System.out.println(line);
|
|
|
119 |
}
|
|
|
120 |
get = new HttpGet("http://seller.snapdeal.com/inventory/");
|
|
|
121 |
response = client.execute(get);
|
|
|
122 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
123 |
while ((line = rd.readLine()) != null) {
|
|
|
124 |
//System.out.println(line);
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
}
|