Subversion Repositories SmartDukaan

Rev

Rev 10162 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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