For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Test Driver- Platform Notification Listener in JAVA (2)

  • Answer ID 891
  • Published 01/29/2007 02:37 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=891
Product
How do I test my notification listener ?

Summary

   By opening up  HttpsURLConnection  to your Java servlet  or jsp based Notification Listener, you can test your listener in your local machine without communicate to eBay Notification server.

   To test whether the Java listener is able to respond with a standard URL status using the attached ListernerTestDriver program, you need to follow these steps:

  1. Subscribe to the specific notifications by setting the ApplicationURL to a URL that starts with mailto in your SetNotificationPreferences request

  2. Save the received email notification in your local file system.

  3. Set listenerURL, notificationEvent and notificationXmlFileName properties in listener.properties file and  execute the java standalone program ListenerTestDriver as below:

  java -cp .;%CLASSPATH% ListenerTestDriver

  Here is the sample output if your listener is running as expected.

  http://localhost:8084/Notification/NotificationServlet
  200 OK


Source Code

/*
© 2007-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/


import java.net.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import java.io.*;
import java.util.Properties;

public class ListenerTestDriver {
     private  static String file = "listerner.properties";
     private  static Properties config;

     public static void main(String[] args) throws Exception{
         config  = new Properties();
         try {
       config.load(new FileInputStream( file));
      } catch (IOException e) {
         System.out.println("listerner.properties file is missing from the current working directory.");
         return;
      }

         String listenerURL = config.getProperty("listenerURL");
         String notificationEvent = config.getProperty("notificationEvent");
         String notificationXmlFileName = config.getProperty("notificationXmlFileName");

         ListenerTestDriver sc = new ListenerTestDriver();
         try {
              //open the connection with the servlet
              URL url = new URL(listenerURL );
              HttpURLConnection conn = (HttpURLConnection)url.openConnection();

              //set-up the connection
              conn.setRequestMethod("POST");
              conn.setDoInput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("PROTOCOL","HTTP/1.1");
              conn.setRequestProperty("Content-Type", "text/xml; charset='utf-8'");
              conn.setRequestProperty("SOAPACTION", "
HTTPS://developer.ebay.com/notification/"+notificationEvent);                   conn.setDoOutput(true);
              conn.setUseCaches(false);

              DataOutputStream out = new DataOutputStream( conn.getOutputStream() );

              String fileContent = sc.readFileIntoString(notificationXmlFileName );


              //send the xml to the servlet
              out.writeBytes(fileContent);
              out.flush();
              out.close();
              conn.disconnect();
              System.out.println(conn.getURL());
              System.out.println(conn.getResponseCode() +" " + conn.getResponseMessage());

          }catch (Exception e){
                e.printStackTrace();
          }

    }

    private String readFileIntoString(String fileName) {
        String fileContentInString = "";
        try {
            File soapFile = new File(fileName);
            byte fileContent[] = new byte[ (int) soapFile.length()];
            FileInputStream soapFileIS = new FileInputStream(soapFile);
            soapFileIS.read(fileContent, 0, fileContent.length);
            fileContentInString = new String(fileContent);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        return fileContentInString;
    }
}

 

File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter