+44(0) 1234 567 890 info@domainname.com

2012-11-30

Hướng dẫn xây dựng Web Service sử dụng Axis2 trên Eclipse


Mục đích: trong hướng dẫn này chúng ta sẽ tạo một webservice cung cấp dịch vụ lấy kết quả xổ số. (Dữ liệu được lấy từ RSS của trang xskt.com.vn)

Bước 0: Cấu hình cài đặt Axis2 trên Eclipse
  • Tải gói Axis2-1.4 từ trang http://ws.apache.org/axis2/download/1_4/download.cgi
  • Tải gói phiên bản “Standard Binary Distribution”, giải nén và lưu nhớ vị trí đó
  • Mở Eclipse → Vào Windows → Mục Preferences ta sẽ được như hình sau:
  • Ta chọn Webservices → Chọn Axis2 Preferences
  • Chọn đường dẫn tới thư mục Axis2 mà chúng ta đã giải nén ở bước trên, chúng sẽ được một màn hình thông báo “Axis2 runtime loaded sucessfully” như sau:

  • Click chọn OK
Bước 1: Tạo một web project
  • Vào File → New → Projects... → Chọn Web → Chọn Dynamic Web Project
  • Tartget runtime ở đây ta chọn Apache Tomcat 7.0 (đã được cấu hình trước đó) 
  • Dynamic web module version ta chọn 2.5 để có thể sử dụng Axis2
  • Mục Configuation


  • Chọn OK và sau đó Finish để tiến hành tạo web project

Bước 2: Xây dựng Interface định nghĩa các phương thức mà chúng ta sẽ cung cấp dịch vụ web
  • Ta đặt tên Interface này là KetQuaXoSoInterface

package hcmute.kqsx;

import java.util.ArrayList;

public interface KetQuaXoSoInterface {
       /**
        * @return một ArrayList<String> chứa danh sách các miền
        */
       public ArrayList<String> getDanhSachMien();
       /**
        * @param tenMien: tên miền
        * @return một ArrayList<String> chứa danh sách các tỉnh theo miền đưa vào
        */
       public ArrayList<String> getDanhSachTinh(String tenMien);
       /**
        * @param tenMien:tên miền
        * @param tenTinh:tên tỉnh
        * @return một ArrayList<String> chứa danh sách ngày có kết quả xổ số
        */
       public ArrayList<String> getDanhSachNgay(String tenMien, String tenTinh);
       /**
        * @param tenMien:tên miền
        * @param tenTinh:tên tỉnh
        * @param ngayXoSo:ngày xổ số
        * @return ArrayList<String> chứa danh sách kết quả xổ số
        */
       public ArrayList<String> getDanhSachKetQua(String tenMien, String tenTinh, String ngayXoSo);
}


Bước 3: Tiến hành hiện thực Interface ta vừa tạo
  • Ta đặt tên lớp này là KetQuaXoSoModel
package hcmute.kqsx;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class KetQuaXoSoModel implements KetQuaXoSoInterface {

      String strPath = "http://localhost:8080/KetQuaXoSoServer/ketquasoxo.xml";
      Document dom;

      public KetQuaXoSoModel() {
             // strPath = "ketquaxoso.xml";
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             try {

                    // Using factory get an instance of document builder
                    DocumentBuilder db = dbf.newDocumentBuilder();

                    // parse using builder to get DOM representation of the XML file
                    dom = db.parse(strPath);

             } catch (ParserConfigurationException pce) {
                    pce.printStackTrace();
             } catch (SAXException se) {
                    se.printStackTrace();
             } catch (IOException ioe) {
                    ioe.printStackTrace();
             }
      }

      @Override
      public ArrayList<String> getDanhSachMien() {
             ArrayList<String> list = new ArrayList<String>();
             Element docEle = dom.getDocumentElement();

             NodeList nl = docEle.getElementsByTagName("mien");
             if (nl != null && nl.getLength() > 0) {
                    for (int i = 0; i < nl.getLength(); i++) {

                           Element el = (Element) nl.item(i);
                           String temp = el.getAttribute("tenmien");
                           list.add(temp);
                    }
             }
             return list;
      }

      @Override
      public ArrayList<String> getDanhSachTinh(String tenMien) {
             ArrayList<String> list = new ArrayList<String>();
             Element docEle = dom.getDocumentElement();

             NodeList nl = docEle.getElementsByTagName("mien");
             if (nl != null && nl.getLength() > 0) {
                    for (int i = 0; i < nl.getLength(); i++) {

                           String temp = "";
                           Element el = (Element) nl.item(i);
                           if (el.getAttribute("tenmien").equals(tenMien)) {
                                 NodeList nl1 = el.getElementsByTagName("tinh");
                                 if (nl1 != null) {
                                        for (int j = 0; j < nl1.getLength(); j++) {
                                               Element el1 = (Element) nl1.item(j);
                                               temp = el1.getAttribute("tentinh");
                                               list.add(temp);
                                        }
                                 }

                           }
                    }
             }


Bước 4: Xây dựng các phương thức để tiến hành cung cấp dịch vụ web
  • Tạo Class KetQuaXoSo
  • package hcmute.kqsx;

    import java.util.ArrayList;

    /**
     * @author ChuwxNTC
     */
    public class KetQuaXoSo {
           public ArrayList<String> getDanhSachMien() {
                  return new KetQuaXoSoModel().getDanhSachMien();
           }

           public ArrayList<String> getDanhSachTinh(String tenMien) {
                  return new KetQuaXoSoModel().getDanhSachTinh(tenMien);
           }

           public ArrayList<String> getDanhSachNgay(String tenMien, String tenTinh) {
                  return new KetQuaXoSoModel().getDanhSachNgay(tenMien, tenTinh);
           }

           public ArrayList<String> getDanhSachKetQua(String tenMien, String tenTinh,
                         String ngayXoSo) {
                  return new KetQuaXoSoModel().getDanhSachKetQua(tenMien, tenTinh, ngayXoSo);
           }

    }

Bước 5: Tạo file ketquaxoso.xml để lưu danh sách tỉnh đường dẫn RSS đến trang xskt.com.vn
<?xml version="1.0" encoding="UTF-8"?>
<ketquasoxo>

       <mien tenmien="Miền Bắc">
          <tinh tentinh="Phú Yên" link="http://xskt.com.vn/rss-feed/phu-yen-xspy.rss" />
       </mien>

       <mien tenmien="Miền Trung">
          <tinh tentinh="Quảng Ngãi" link="http://xskt.com.vn/rss-feed/quang-ngai-xsqng.rss" />
          <tinh tentinh="Bình Định" link="http://xskt.com.vn/rss-feed/binh-dinh-xsbdi.rss" />
          <tinh tentinh="Phú Yên" link="http://xskt.com.vn/rss-feed/phu-yen-xspy.rss" />
       </mien>

       <mien tenmien="Miền Nam">
          <tinh tentinh="Đồng Tháp" link="http://xskt.com.vn/rss-feed/dong-thap-xsdt.rss" />
          <tinh tentinh="Hậu Giang" link="http://xskt.com.vn/rss-feed/hau-giang-xshg.rss" />
       </mien>

</ketquasoxo>


Bước 6: Tiến hành xây dựng webservice
  • Chọn lớp KetQuaXoSo vừa tạo: Vào File → New → Projects... → Chọn Web → Chọn Dynamic Web Project
  • Click chuột phải chọn New → Others… → Mục Web service → Chọn Web service

  • Ta được như hình sau:


  • Ta chỉnh chọn Web service runtime là Apache Axis2 như sau:


  • Chọn Next

  • Sau đó ta Start server


  • Click Finish

Bước 7: Kiểm tra hoạt động web service


  • Nếu kết quả hiển thự như màn hình này thì mọi thứ đang hoạt động tốt
  • Click chọn Service ta sẽ được danh sách các dịch vụ mà ta cung cấp




Tổng kết: Như vậy là qua hướng dẫn này bạn đã tạo được một web service cung cấp dịch vụ lấy kết quả xổ số kiến thiết. Trong bài tiếp theo mình sẽ hướng dẫn các bạn cách gọi một web service từ Android.
3 comments

2012-03-11

Ready to Apply for Jobs?!!!


Dear all,
Today's topic is how to successfully seek work: picking the right jobs and presenting yourself as the right candidate on every job application.

You have a job application quota, so put your efforts into the jobs that best suit your skills. As we've discussed, make sure you not only can do the job, but that your profile and cover letterstrongly communicate that to the client. When a client asks for more information, or invites you to interview, respond promptly - clients respect contractors who show an active interest the job that they have posted.

Look for a good match between yourself, the work and the client. Seek out clients with good feedback, whose job postings clearly communicate what they need.

One more thing to consider: Is the job hourly or fixed-price?

Hourly work contributes more to your work history and shows future clients that you have established a track record on oDesk. Additionally, only hourly work is covered by the oDesk Guarantee. However, fixed-price jobs are often easier to get as a new contractor. You might start with fixed-price jobs, but you should look to the greater potential of hourly work as soon as you've developed some work history on oDesk.

We have now completed our "Getting Started" series. All the tips and resources we have shared in these emails are available as in oDesk QuickStart Guide for you to review any time.

Send by ChuwxNTC@gmail.com

Thanks,
The oDesk Team 
1 comment

2012-03-10

How to have a good cover letter?


Dear all,
Today I focus on cover letters. What are they? And why should you care?

The cover letter is a brief introduction that accompanies your job application. It's your chance to express your interest in the job and explain why you are the right person to hire. Clients tell us that the cover letter plays a big role in their hiring decisions.

Here is how a client sees your job application. Notice how job candidates (you!) are listed.

When the client hovers over your name and job application, he can see the first paragraph of your cover letter for his particular job, without leaving the list of candidates. Make sure that those first few lines capture his attention and demonstrate your enthusiasm and excellent fit for his job.

What your cover letter should do:
  • Introduce yourself and express interest in the job.
  • Briefly state why you are a good candidate. Focus on your most relevant experience, specific skills and portfolio items.
  • Indicate when you'd be available to discuss the job and to start. Don't include contact info - wait for the client to request an interview.
  • Include any specific information the client requested in their job posting. This will show a potential client that you read the job posting fully and considered it carefully before applying.
Take a look at this sample cover letter for a basic model, and review this list of tips.

Cover letter basics:
  • Keep the letter to 300 words or less.
  • Use spell-check and ask a friend with good spelling and grammar skills to review it before submitting.
  • Do not use a generic template: If the letter isn't written specifically for the job, the client will likely ignore you in favor of contractors who took the time to write a customized cover letter for the position.

Thanks,
Send by ChuwxNTC!
Messager from The oDesk Team.


Good luck to you!...
No comments

Giới thiệu về tác giả

&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;body&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Your browser does not handle frames!&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/body&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; No comments