Txtweb development steps:
Txtweb is a sms based platform, means that you can get everthing simply messaging to 92665 92665.
Format: @kilometre source destination
Eg: @kilometre chennai bangalore
send the above formatted message to 92665 92665 (No additional charge, but ensure you have put sms pack already)
Then it will reply like “Distance: 346 km Time: 5 hours 15 mins”.
Step 1: Create a account in txtweb (www.txtweb.com). Login to txtweb and click “create a new service” and reserve the keyword. After creating the keyword they will give “App key”.
The given App key will be used in the below dictionary program (refer the program – bold content).
Step 2: Ensure you have installed the required plugins, if you have not installed please read and get install the below links,
http://ngdeveloper.com/txtweb-world/
Step 3: Create a File -> New -> Web Application Project
Project Name: Dictionary
Package: com.ngdeveloper.com
and paste the below code,
[java]
package com.ngdeveloper.com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@SuppressWarnings("serial")
public class DictionaryServlet extends HttpServlet {
private static final String APPKEY_NAME = "txtweb-appkey";
private static final String APPKEY_CONTENT = <strong>"2a129c1c-ac5a-48eb-962a-985a3f93828f"</strong>;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
processRequest(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
processRequest(req, resp);
}
public void processRequest(HttpServletRequest request,
HttpServletResponse response) {
String txtWebResponse = null;
String txtWebMessage = request.getParameter("txtweb-message");
if (txtWebMessage == null || txtWebMessage.isEmpty()) {
txtWebResponse = getWelcomeMessage();
sendResponse(response, txtWebResponse);
return;
}
String[] parameters = txtWebMessage.split(" ");
if (parameters.length != 1) {
txtWebResponse = getWelcomeMessage();
sendResponse(response, txtWebResponse);
return;
}
txtWebResponse = "";
// String searchWord = URLEncoder.encode(parameters[0], "UTF-8");
// String sourceUrlString="http://en.wiktionary.org/wiki/" + searchWord;
String input_name = parameters[0];
try {
String url = "http://www.mydictionary.net/english/?word="+input_name+"";
Document document = Jsoup.connect(url).get();
Elements india = document.select("tbody").select("tr").after("td");
List mylist = new ArrayList();
for (Element answerer : india) {
mylist.add(answerer.text().toString());
}
String first = (String)mylist.get(4);
//String second = (String)mylist.get(5);
txtWebResponse = first+" \n";
} catch (Exception e) {
txtWebResponse = "Sorry, Try again with different words";
}
if (!txtWebResponse.isEmpty()) {
sendResponse(response, txtWebResponse);
return;
}
txtWebResponse = getNothingFoundMessage(txtWebMessage);
sendResponse(response, txtWebResponse);
return;
}
private void sendResponse(HttpServletResponse response, String smsResponse) {
try {
PrintWriter out = response.getWriter();
String smsResponse1 = "<html><head><title>Dictionary TxtWeb!</title>"
+ "<meta http-equiv=’Content-Type’ content=’text/html; charset=UTF-8′ />"
+ "<meta name=’" + APPKEY_NAME + "’ content=’" + APPKEY_CONTENT + "’ />"
+ "</head><body>" + smsResponse + "</body></html>";
out.println(smsResponse1);
} catch (IOException e) {
}
}
private String getWelcomeMessage() {
return "<html><body>Welcome to Dictionary \n\n"
+ "Reply with your search keyword.\n\n"
+ "(Powered by Intuit TxtWeb and Wiktionary)</body></html>";
}
private String getNothingFoundMessage(String txtWebMessage) {
return "<html><body>No word found: "
+ txtWebMessage + "\n\n"
+ "Reply with your search keyword.\n\n"
+ "(Powered by Intuit TxtWeb and Wiktionary) )</body></html>";
}
}
[/java]
Step 4: Right click on the project Run As -> Web Application
Then open the internet explorer and type this address “http://localhost:8888/”. Now you will be able to see the project.
http://localhost:8888/dictionary
http://localhost:8888/dictionary?txtweb-message=god
Step 5: Create https://appengine.google.com/
Create Application.
Step 6: Enter the Application Id which we have created in the above step as like below in the eclipse,
Right click on the project -> Properties and enter the Application Id.
Step 7: Now Right click on the project -> Google -> Deploy to App Engine.
Now the dictionary application will be deployed to the appengine which we have created, it will be like,
http://agn-meaningofword.appspot.com/dictionary
Step 7: Copy the deployed application url and paste it in the url of txtweb.
Step 8: Now you will be able to use the deployed application from your mobile.
send @meaningofword god to “92665 92665”
eg: @meaningofword – keyword which we have created.
Thanks for reading this post………………!!!