1 |
torben |
1014 |
package dk.thoerup.marketstats; |
2 |
|
|
|
3 |
|
|
import java.io.IOException; |
4 |
|
|
import java.util.List; |
5 |
|
|
|
6 |
|
|
import javax.servlet.ServletException; |
7 |
|
|
import javax.servlet.annotation.WebServlet; |
8 |
|
|
import javax.servlet.http.HttpServlet; |
9 |
|
|
import javax.servlet.http.HttpServletRequest; |
10 |
|
|
import javax.servlet.http.HttpServletResponse; |
11 |
|
|
|
12 |
|
|
import com.gc.android.market.api.MarketSession; |
13 |
|
|
import com.gc.android.market.api.model.Market.AppsRequest; |
14 |
|
|
|
15 |
|
|
@WebServlet(name = "SearchApps", urlPatterns = { "/SearchApps" }) |
16 |
|
|
public class SearchApps extends HttpServlet { |
17 |
|
|
private static final long serialVersionUID = 1L; |
18 |
|
|
|
19 |
|
|
String login; |
20 |
|
|
String password; |
21 |
|
|
|
22 |
|
|
@Override |
23 |
|
|
public void init() throws ServletException { |
24 |
|
|
super.init(); |
25 |
|
|
|
26 |
|
|
login = getServletContext().getInitParameter("login"); |
27 |
|
|
password = getServletContext().getInitParameter("password"); |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
List<AppBean> queryApps(String query) { |
32 |
|
|
MarketSession session = new MarketSession(); |
33 |
|
|
session.login(login,password); |
34 |
torben |
1205 |
session.getContext().setAndroidId("dead00beef"); |
35 |
torben |
1014 |
|
36 |
|
|
|
37 |
|
|
AppsRequest appsRequest = AppsRequest.newBuilder() |
38 |
|
|
.setQuery(query) |
39 |
|
|
.setStartIndex(0) |
40 |
|
|
.setEntriesCount(10) |
41 |
|
|
.setWithExtendedInfo(false) |
42 |
|
|
.build(); |
43 |
|
|
|
44 |
|
|
AppsCallback appsCb = new AppsCallback(); |
45 |
|
|
session.append(appsRequest, appsCb); |
46 |
|
|
session.flush(); |
47 |
|
|
|
48 |
|
|
return appsCb.getResult(); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
53 |
|
|
|
54 |
|
|
String query = request.getParameter("query"); |
55 |
|
|
List<AppBean> apps = queryApps(query); |
56 |
|
|
|
57 |
|
|
request.setAttribute("query", query); |
58 |
|
|
request.setAttribute("apps", apps); |
59 |
|
|
request.getRequestDispatcher("/viewapps.jsp").forward(request, response); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
} |