Subversion Repositories SmartDukaan

Rev

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