Steps to develop txtweb application

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.

dictionary

 http://localhost:8888/dictionarywelcome to dictionary

http://localhost:8888/dictionary?txtweb-message=god

txtweb parameter

Step 5: Create https://appengine.google.com/

appengine create application

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.

App 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………………!!!

10 comments

  • shiva

    hai.. i would like to create cricket score app..

    how to create.. im a fresher in mca..

    just as like dictonary app or different..

    how scores can send.. should we give any source to txtweb to send score

    • User Avatar Naveen

      import java.io.IOException;

      import org.jsoup.Jsoup;
      import org.jsoup.nodes.Document;
      import org.jsoup.nodes.Element;
      import org.jsoup.select.Elements;

      public class CricketScore {

      /**
      * @param args
      * @throws IOException
      */
      public static void main(String[] args) throws IOException {
      String url = “http://www.espncricinfo.com/”;
      Document document = Jsoup.connect(url).get();

      Elements scores = document.select(“table#international”);
      // System.out.println(scores.toString());

      for (Element score : scores) {
      System.out.println(“scores are : ” + score.text());
      break;
      }
      }

      }

      Note:
      Here we are taking the scores from espn cric info. Just follow the steps given and deploy the above code for cricket scores.

  • shiva

    thanks.. in the above given dictionary code I shoud edit and deploy ah.. or should write code different

    • User Avatar Naveen

      I have given the working program for dictionary, so you can deploy it without changing anything in the logic of the program.

  • shiva

    not for dictionary.. for cricket.. shoud i edit dictionary code or .. or i need to write code again
    for cricket.. if u dont mine .. can u give me total code for cricket app..
    please im a student.. im unable to understand.. please if possible.. send me total code for cricket

    • User Avatar Naveen

      Hi I have given the complete code for the cricket, you dont want to edit anything. You can directly deploy by following above steps.

  • shivagoud

    doget , dopost methos are not avalible in this code.. please donnt mine..
    onle this code or shoud i include above dictionary code also..
    import java.io.IOException;

    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;

    public class CricketScore {

    /**
    * @param args
    * @throws IOException
    */
    public static void main(String[] args) throws IOException {
    String url = “http://www.espncricinfo.com/”;
    Document document = Jsoup.connect(url).get();

    Elements scores = document.select(“table#international”);
    // System.out.println(scores.toString());

    for (Element score : scores) {
    System.out.println(“scores are : ” + score.text());
    break;
    }
    }

    • User Avatar Naveen

      You have to convert it to either get or post based on your requirements,

      The dictionary program which is given here is executable txtweb program. Cricket score program gives the logic, you have to replace the dictionary logic with cricket score logic and deploy it.

  • shivagoud

    thank u very much..
    it same as @cricket
    for cricket scores only..
    so i need to use only one method

  • User Avatar Aravind

    Neat n crisp content!! Good work Naveen 🙂

Leave a Reply