KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > lp > samples > JLinkPointSample


1 /*****************************************************************************
2 ' Copyright 2003 LinkPoint International, Inc. All Rights Reserved.
3 '
4 ' This software is the proprietary information of LinkPoint International, Inc.
5 ' Use is subject to license terms.
6 '
7 '******************************************************************************/

8 package lp.samples;
9
10 import java.io.*;
11 import java.util.*;
12 import lp.txn.JLinkPointTransaction;
13 /**
14  * <p>Title: </p>
15  * <p>Description: </p>
16  * <p>Copyright: Copyright (c) 2003</p>
17  * <p>Company: LinkPoint International</p>
18  * @author Sergey Chudnovsky
19  * @version 1.0
20  */

21  abstract public class JLinkPointSample {
22
23
24
25   public JLinkPointSample(String JavaDoc _clientCertPath, String JavaDoc _configfile,
26                           String JavaDoc _host, String JavaDoc _password, int _port)
27  {
28     clientCertPath = _clientCertPath;
29     password = _password;
30     host = _host;
31     configfile = _configfile;
32     port = _port;
33   }
34
35   public JLinkPointSample()
36   {
37     InputStream is = null;
38     try
39     {
40      is = new FileInputStream("lpcli.prop");
41      Properties ps = new Properties();
42      ps.load(is);
43       clientCertPath = ps.getProperty("ClientCertificatePath","");
44       password = ps.getProperty("Password");
45       host = ps.getProperty("Host");
46       configfile = ps.getProperty("ConfigFile");
47       port = Integer.parseInt((String JavaDoc)ps.get("Port"));
48
49     }
50     catch( IOException e)
51     {
52     System.out.println("Cannot find/load property file 'lpcli.prop'");
53     }
54     finally{
55     if( is != null ) try{ is.close(); } catch (IOException e1){}
56     }
57 /*
58     clientCertPath = "./909005.p12";
59     password = "12345678";
60     host = "api.qa.linkpoint.com";
61     configfile = "909005";
62     port = 1129;
63 */

64   }
65
66   public boolean process()
67   {
68    JLinkPointTransaction txn = new JLinkPointTransaction();
69
70     txn.setClientCertificatePath(clientCertPath);
71     txn.setPassword(password);
72     txn.setHost(host);
73     txn.setPort(port);
74
75     System.out.println("OUTGOING XML:\n"+getOrderXML());
76
77     String JavaDoc sResponse = "";
78     boolean ret=false;
79     try{
80         sResponse = txn.send(getOrderXML());
81        }
82      catch (Exception JavaDoc e)
83      {
84      e.printStackTrace();
85      sResponse = "<r_error>"+e.toString()+"</r_error>";
86      }
87
88     parseResponse(sResponse);
89     printResp();
90
91   return ret;
92   }
93
94   abstract protected String JavaDoc getOrderXML();
95
96
97   protected void parseResponse( String JavaDoc rsp )
98   {
99     R_Time = parseTag("r_time", rsp);
100     R_Ref = parseTag("r_ref", rsp);
101     R_Approved = parseTag("r_approved", rsp);
102     R_Code = parseTag("r_code", rsp);
103     R_Authresr = parseTag("r_authresronse", rsp);
104     R_Error = parseTag("r_error", rsp);
105     R_OrderNum = parseTag("r_ordernum", rsp);
106     R_Message = parseTag("r_message", rsp);
107     R_Score = parseTag("r_score", rsp);
108     R_TDate = parseTag("r_tdate", rsp);
109     R_AVS = parseTag("r_avs", rsp);
110     R_Tax = parseTag("r_tax", rsp);
111     R_Shipping = parseTag("r_shipping", rsp);
112     R_FraudCode = parseTag("r_fraudCode", rsp);
113     R_ESD = parseTag("esd", rsp);
114   }
115
116   protected String JavaDoc parseTag(String JavaDoc tag, String JavaDoc rsp )
117   {
118     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(256);
119     sb.append('<' + tag + '>');
120     int len = sb.length();
121     int idxSt=-1,idxEnd=-1;
122     if( -1 == (idxSt = rsp.indexOf(sb.toString())))
123     { return ""; }
124     idxSt += len;
125     sb.setLength(0);
126     sb.append("</" + tag + '>');
127     if( -1 == (idxEnd = rsp.indexOf(sb.toString(),idxSt)))
128     { return ""; }
129     return rsp.substring(idxSt,idxEnd);
130   }
131
132   public void printResp()
133   {
134     System.out.println("\n****** XML RESPONSE *******");
135     if(R_Time.length() != 0)
136     System.out.println("<r_time>" + R_Time + "</r_time>");
137     if(R_Ref.length() != 0)
138     System.out.println("<r_ref>" + R_Ref + "</r_ref>");
139     if(R_Approved.length() != 0)
140     System.out.println("<r_approved>" + R_Approved + "</r_approved>");
141     if(R_Code.length() != 0)
142     System.out.println("<r_code>" + R_Code + "</r_code>");
143     if(R_OrderNum.length() != 0)
144     System.out.println("<r_ordernum>" + R_OrderNum + "</r_ordernum>");
145     if(R_Error.length() != 0)
146     System.out.println("<r_error>" + R_Error + "</r_error>");
147     if(R_FraudCode.length() != 0)
148     System.out.println("<r_fraudCode>" + R_FraudCode + "</r_fraudCode>");
149     if(R_Authresr.length() != 0)
150     System.out.println("<r_authresponse>" + R_Authresr + "</r_authresponse>");
151     if(R_Message.length() != 0)
152     System.out.println("<r_message>" + R_Message + "</r_message>");
153     if(R_TDate.length() != 0)
154     System.out.println("<r_tdate>" + R_TDate + "</r_tdate>");
155     if(R_Shipping.length() != 0)
156     System.out.println("<r_shipping>" + R_Shipping + "</r_shipping>");
157     if(R_Tax.length() != 0)
158     System.out.println("<r_tax>" + R_Tax + "</r_tax>");
159     if(R_AVS.length() != 0)
160     System.out.println("<r_avs>" + R_AVS + "</r_avs>");
161     if(R_ESD.length() != 0)
162     System.out.println("<esd>" + R_ESD + "</esd>");
163     if(R_Score.length() != 0)
164     System.out.println("<r_score>" + R_Score + "</r_score>");
165
166     System.out.println("\n****** End Of XML RESPONSE ********");
167
168   }
169
170    protected String JavaDoc clientCertPath="";
171    protected String JavaDoc password="";
172    protected String JavaDoc host="";
173    protected String JavaDoc configfile="";
174    protected int port=0;
175
176    // response holders
177
protected String JavaDoc R_Time="";
178    protected String JavaDoc R_Ref="";
179    protected String JavaDoc R_Approved="";
180    protected String JavaDoc R_Code="";
181    protected String JavaDoc R_Authresr="";
182    protected String JavaDoc R_Error="";
183    protected String JavaDoc R_OrderNum="";
184    protected String JavaDoc R_Message="";
185    protected String JavaDoc R_Score="";
186    protected String JavaDoc R_TDate="";
187    protected String JavaDoc R_AVS="";
188    protected String JavaDoc R_FraudCode="";
189    protected String JavaDoc R_ESD="";
190    protected String JavaDoc R_Tax="";
191    protected String JavaDoc R_Shipping="";
192
193 }
Popular Tags