Subversion Repositories SmartDukaan

Rev

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