//package com.carolinacustom; /* Decompiled by Mocha from UPS_Shipping_Calculator.class */ /* Originally compiled from UPS_Shipping_Calculator.java */ //import com.allaire.cfx.*; import java.io.*; import java.net.Socket; import javax.net.SocketFactory; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class UPS_Shipping_Calculator { public static final String UPS_NEXT_DAY_AIR = "01"; public static final String UPS_2ND_DAY_AIR = "02"; public static final String UPS_GROUND = "03"; public static final String UPS_WORLDWIDE_EXPRESS = "07"; public static final String UPS_WORLDWIDE_EXPEDITED = "08"; public static final String UPS_STANDARD = "11"; public static final String UPS_3_DAY_SELECT = "12"; public static final String UPS_NEXT_DAY_AIR_SAVER = "13"; public static final String UPS_NEXT_DAY_EARLY_AM = "14"; public static final String UPS_WORLDWIDE_EXPRESS_PLUS = "54"; public static final String UPS_2ND_DAY_AIR_AM = "59"; public static final String UPS_EXPRESS_SAVER = "65"; public String server; public int port; public String protocol; private String UPS_request; private String UPS_response; private int num_rated_shipments; String[] service_code; float[] shipping_cost; //----------------------------------------------------------------------------------- public UPS_Shipping_Calculator() { server="www.ups.com"; port=443; protocol="HTTPS"; } //----------------------------------------------------------------------------------- public UPS_Shipping_Calculator(String new_server, int new_port, String new_protocol) { server=new_server; port=new_port; protocol=new_protocol; } //----------------------------------------------------------------------------------- public void set_server(String new_server) { server=new_server; } //----------------------------------------------------------------------------------- public void set_port(int new_port) { port=new_port; } //----------------------------------------------------------------------------------- public void set_protocol(String new_protocol) { protocol=new_protocol; } //----------------------------------------------------------------------------------- public void communicate_request_to_UPS() throws Exception { System.out.println(server); if (protocol.equals("HTTP")) doHTTPSocket(); else if (protocol.equals("Other")) doOtherSocket(); else { if (!protocol.equals("HTTPS")) throw new Exception("Invalid value for PROTOCOL Attribute. Only HTTP, HTTPS and Other are valid values."); doHTTPSSocket(); } } //----------------------------------------------------------------------------------- void doHTTPSocket() throws Exception { BufferedReader bufferedReader; UPS_response = ""; Socket socket = new Socket(server, port); PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))); printWriter.println(UPS_request); printWriter.println(); printWriter.flush(); String string; for (bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); (string = bufferedReader.readLine()) != null; ) UPS_response = UPS_response + string + "\r\n"; bufferedReader.close(); printWriter.close(); socket.close(); } //----------------------------------------------------------------------------------- void doOtherSocket() throws Exception { BufferedReader bufferedReader; UPS_response = ""; Socket socket = new Socket(server, port); PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))); printWriter.println(UPS_request); printWriter.println(); printWriter.flush(); String string; for (bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); (string = bufferedReader.readLine()) != null; ) UPS_response = UPS_response + string + "\r\n"; bufferedReader.close(); printWriter.close(); socket.close(); } //----------------------------------------------------------------------------------- void doHTTPSSocket() throws Exception { BufferedReader bufferedReader; UPS_response = ""; SSLSocketFactory sSLSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault(); SSLSocket sSLSocket = (SSLSocket)sSLSocketFactory.createSocket(server, port); sSLSocket.startHandshake(); PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sSLSocket.getOutputStream()))); printWriter.println(UPS_request); printWriter.println(); printWriter.flush(); String string; for (bufferedReader = new BufferedReader(new InputStreamReader(sSLSocket.getInputStream())); (string = bufferedReader.readLine()) != null; ) UPS_response = UPS_response + string + "\r\n"; bufferedReader.close(); printWriter.close(); sSLSocket.close(); } //----------------------------------------------------------------------------------- public void set_UPS_request(String shipto_zipcode, String shipto_country, String cart_weight) { String crln = new String("\r\n"); String double_quote = new String("\""); String http_header; String xml_request; xml_request = "" + crln + "" + crln + " 4B8431F95EDBD4B0" + crln + " scdemarc" + crln + " d0gEYE$!" + crln + "" + crln + "" + crln + "" + crln + " " + crln + " " + crln + " Rating and Service" + crln + " 1.0001" + crln + " " + crln + " Rate" + crln + " shop" + crln + " " + crln + " " + crln + " 01" + crln + " " + crln + " " + crln + " " + crln + "
" + crln + " 28328" + crln + " US" + crln + "
" + crln + "
" + crln + " " + crln + "
" + crln + " " + shipto_zipcode + "" + crln + " " + shipto_country + "" + crln + "
" + crln + "
" + crln + " " + crln + " " + crln + " 02" + crln + " " + crln + " " + crln + " " + cart_weight + "" + crln + " " + crln + " LBS" + crln + " " + crln + " " + crln + " " + crln + "
" + crln + "
" + crln; http_header = "POST /ups.app/xml/Rate HTTP/1.0" + crln + "Content-Length: " + xml_request.length() + crln + "Content-type: application/x-www-form-urlencoded" + crln + crln; UPS_request = http_header + xml_request; } //----------------------------------------------------------------------------------- public String get_UPS_request() { return(UPS_request); } //----------------------------------------------------------------------------------- public String get_UPS_response() { return(UPS_response); } //----------------------------------------------------------------------------------- public void extract_rated_shipments_from_UPS_response() { int result, search_index=0; int n, begin_index, end_index; num_rated_shipments=0; result = UPS_response.indexOf("", search_index); while(result != -1) { num_rated_shipments++; search_index = result + 1; result = UPS_response.indexOf("", search_index); } service_code = new String[num_rated_shipments]; shipping_cost = new float[num_rated_shipments]; search_index=0; for (n=0; n", search_index); begin_index = UPS_response.indexOf("", search_index) + 6; end_index = UPS_response.indexOf("", search_index); service_code[n] = UPS_response.substring(begin_index, end_index); search_index = UPS_response.indexOf("", search_index); begin_index = UPS_response.indexOf("", search_index) + 15; end_index = UPS_response.indexOf("", search_index); shipping_cost[n] = (Float.valueOf(UPS_response.substring(begin_index, end_index))).floatValue(); } } //----------------------------------------------------------------------------------- public int get_num_rated_shipments() { return(num_rated_shipments); } //----------------------------------------------------------------------------------- public String get_service_code(int n) { return(service_code[n]); } //----------------------------------------------------------------------------------- public float get_shipping_cost(int n) { return(shipping_cost[n]); } //----------------------------------------------------------------------------------- public float get_shipping_cost(String desired_service_code) { int n; for (n=0; n