0

I was trying to implement TrueMD API as documented at:http://www.truemd.in/api/documentation#javasdk. I downloaded TrueMD.jar and added to library of a java web servlet application using Netbeans8.0. I was able to get drug suggestions but not their details. I tried the following code:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String drugdetail = request.getParameter("drug");
        TrueMDAPI.key="3abb58c093fd817e9cddae75b3de2b";  

    try{ 
        Medicine medicine= TrueMDAPI.getMedicineData(drugdetail);
        printMedicine(medicine);         
       }finally {            
        out.close();
     }
 }
private static void printMedicine(Medicine medicine){   
 System.out.println("manufacturer :"+medicine.getManufacturer());
 System.out.println("brand :"+medicine.getBrand());
 System.out.println("category :"+medicine.getCategory());
 System.out.println("d_class :"+medicine.getDClass());
 System.out.println("unit_type :"+medicine.getUnitType());
 System.out.println("unit_qty :"+medicine.getUnitQty());
 System.out.println("package_type :"+medicine.getPackageType());
 System.out.println("package_qty :"+medicine.getPackageQty());
 System.out.println("package_price :"+medicine.getPackagePrice());
 System.out.println("unit_price :"+medicine.getUnitPrice());
 System.out.println("generic_id :"+medicine.getGenericId());

}

I request you to help me find the problem. Thanks in advance.

1 Answers1

0

Before the piece of code

try{ 
        Medicine medicine= TrueMDAPI.getMedicineData(drugdetail);
        printMedicine(medicine);         
       }finally {            
        out.close();
     }

try pasting:

try {
            drugdetail = URLEncoder.encode(drugdetail, "UTF-8");
        } catch (UnsupportedEncodingException ignored) {
            // Can be safely ignored because UTF-8 is always supported
        }

I hope this helps.

Yash
  • 26
  • 1
  • 4
  • Thanks for the lead. I needed to remove leading or trailing empty spaces. Then replace white space with + before I can connect to database. Please check the following link:http://stackoverflow.com/questions/10786042/java-url-encoding – user2339074 Nov 10 '14 at 10:21