Subversion Repositories SmartDukaan

Rev

Rev 20640 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.bluedart.impl;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.GregorianCalendar;
import java.util.List;

import javax.xml.bind.JAXBElement;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import com.bluedart.entities.ArrayOfDimension;
import com.bluedart.entities.CommodityDetail;
import com.bluedart.entities.Consignee;
import com.bluedart.entities.Dimension;
import com.bluedart.entities.ObjectFactory;
import com.bluedart.entities.Services;
import com.bluedart.entities.Shipper;
import com.bluedart.entities.UserProfile;
import com.bluedart.entities.WayBillGenerationRequest;
import com.bluedart.entities.WayBillGenerationResponse;
import com.bluedart.enums.ProductType;
import com.bluedart.tempuri.IWayBillGeneration;
import com.bluedart.tempuri.WayBillGeneration;
import com.providers.logistics.Provider;

import in.shop2020.model.v1.order.Order;

public class Bluedart implements Provider{
        
        private final String LOGIN_ID = "FA316326";
        private final String LICENCE_KEY = "5f1740fdfb8196e7980faea7fe52dd0d";
        private UserProfile userProfile;
        private static Bluedart bluedart;
        
        static{
                synchronized(Bluedart.class){
                        bluedart = new Bluedart();
                        bluedart.createProfile();
                }
        }
        
        private void createProfile(){
                userProfile = new UserProfile();
        }
        
        private static Bluedart getBluedartService(){
                return bluedart;
        }
        

        public String getAirwayBillNo(List<Order> orders) throws MalformedURLException {
                System.setProperty(
                                "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump",
                                "true");

                
                UserProfile userProfile = new UserProfile();
                WayBillGenerationRequest wayBillGenerationRequest = new WayBillGenerationRequest();

                ObjectFactory objectFactory= new ObjectFactory();

                Consignee consignee = new Consignee();
                JAXBElement<String> address1Value = objectFactory
                                .createConsigneeConsigneeAddress1("Flat201,MIG76");
                JAXBElement<String> address2Value = objectFactory
                                .createConsigneeConsigneeAddress2("DRC phase-2,HyderNagar");
                JAXBElement<String> address3Value = objectFactory
                                .createConsigneeConsigneeAddress3("HyderNagar,Hyderabad-500072");
                JAXBElement<String> attentionValue = objectFactory
                                .createConsigneeConsigneeAttention("Mr.");
                JAXBElement<String> mobileValue = objectFactory
                                .createConsigneeConsigneeMobile("09666712227");
                JAXBElement<String> nameValue = objectFactory
                                .createConsigneeConsigneeName("Nagesh Chintala");
                JAXBElement<String> pincodeValue = objectFactory
                                .createConsigneeConsigneePincode("400025");

                consignee.setConsigneeAddress1(address1Value);
                consignee.setConsigneeAddress2(address2Value);
                consignee.setConsigneeAddress3(address3Value);
                consignee.setConsigneeAttention(attentionValue);
                consignee.setConsigneeMobile(mobileValue);
                consignee.setConsigneeName(nameValue);
                consignee.setConsigneePincode(pincodeValue);
                consignee.setConsigneeTelephone(objectFactory
                                .createConsigneeConsigneeTelephone("1111111111"));
                consignee.setConsigneeMobile(objectFactory
                                .createConsigneeConsigneeMobile("1111111111"));
                JAXBElement<Consignee> consigneeValue = objectFactory
                                .createConsignee(consignee);

                wayBillGenerationRequest.setConsignee(consigneeValue);

                Services services = new Services();

                services.setActualWeight(1.0);
                services.setCollectableAmount(0.0);

                CommodityDetail commodityDetail = new CommodityDetail();
                        
                commodityDetail.setCommodityDetail1(objectFactory
                                .createCommodityDetailCommodityDetail1("Commodity 1"));
                commodityDetail.setCommodityDetail2(objectFactory
                                .createCommodityDetailCommodityDetail2("Commodity 2"));
                commodityDetail.setCommodityDetail3(objectFactory
                                .createCommodityDetailCommodityDetail3("Commodity 3"));
                //services.setCommodity(objectFactory
                                //.createCommodityDetail(commodityDetail)); 
                
                services.setCommodity(objectFactory
                                .createServicesCommodity(commodityDetail));  
                
                services.setCreditReferenceNo(objectFactory 
                                .createServicesCreditReferenceNo("12345abdnn"));
                services.setDeclaredValue(1.0);

                ArrayOfDimension arrayOfDimension = new ArrayOfDimension();
                Dimension d = new Dimension();
                d.setBreadth(1.0);
                d.setCount(1);
                d.setHeight(1.0);
                d.setLength(1.0);                
                arrayOfDimension.getDimension().add(d);
                 
                services.setDimensions(objectFactory
                                .createServicesDimensions(arrayOfDimension));
                
                services.setInvoiceNo(objectFactory.createServicesInvoiceNo("12345"));
                services.setPackType(objectFactory.createServicesPackType(""));

                GregorianCalendar c = new GregorianCalendar();
                c.set(2014,11 ,4);
                // c.setTime(yourDate);
                XMLGregorianCalendar date2;
                try {
                        date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                        services.setPickupDate(date2);
                } catch (DatatypeConfigurationException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                services.setPickupTime(objectFactory.createServicesPickupTime("1800"));
                services.setPieceCount(1);
                services.setProductCode(objectFactory.createServicesProductCode("A"));
                services.setProductType(ProductType.DUTIABLES);
                services.setSpecialInstruction(objectFactory
                                .createServicesSpecialInstruction("1"));
                services.setSubProductCode(objectFactory
                                .createServicesSubProductCode(""));

                wayBillGenerationRequest.setServices(objectFactory
                                .createServices(services));

                Shipper shipper = new Shipper();
                shipper.setCustomerAddress1(objectFactory
                                .createShipperCustomerAddress1("1"));
                shipper.setCustomerAddress2(objectFactory
                                .createShipperCustomerAddress2("1"));
                shipper.setCustomerAddress3(objectFactory
                                .createShipperCustomerAddress3("1"));
                shipper.setCustomerCode(objectFactory
                                .createShipperCustomerCode("525755"));
                shipper.setCustomerMobile(objectFactory
                                .createShipperCustomerMobile("1111111111"));
                shipper.setCustomerEmailID(objectFactory
                                .createShipperCustomerEmailID("a@b.com"));
                shipper.setCustomerName(objectFactory.createShipperCustomerName("xyz"));
                shipper.setCustomerPincode(objectFactory
                                .createShipperCustomerPincode("110074"));
                shipper.setCustomerTelephone(objectFactory
                                .createShipperCustomerTelephone("1111111111"));
                shipper.setIsToPayCustomer(false);
                shipper.setOriginArea(objectFactory.createShipperOriginArea("DEL"));
                shipper.setSender(objectFactory.createShipperSender("xyz"));
                shipper.setVendorCode(objectFactory.createShipperVendorCode(""));

                wayBillGenerationRequest.setShipper(objectFactory
                                .createShipper(shipper));

                //JAXBElement<String> apiValue = objectFactory
                //              .createUserProfileApiType("S");
                JAXBElement<String> custcodeValue = objectFactory
                                .createUserProfileCustomercode("316326");
                JAXBElement<String> licencekeyValue = objectFactory
                                .createUserProfileLicenceKey("5f1740fdfb8196e7980faea7fe52dd0d");
                JAXBElement<String> loginidValue = objectFactory
                                .createUserProfileLoginID("FA316326");
                JAXBElement<String> versionValue = objectFactory
                                .createUserProfileVersion("1.3");

                //userProfile.setApiType(apiValue);
                userProfile.setArea(objectFactory.createUserProfileArea("FAR"));
                userProfile.setCustomercode(custcodeValue);
                userProfile.setPassword(objectFactory.createUserProfilePassword(""));
                userProfile.setIsAdmin(objectFactory.createUserProfileIsAdmin("Y"));
                userProfile.setLicenceKey(licencekeyValue);
                userProfile.setLoginID(loginidValue);
                userProfile.setVersion(versionValue);

                com.bluedart.tempuri.ObjectFactory objectFactory1 = new com.bluedart.tempuri.ObjectFactory();
                JAXBElement<UserProfile> userProfileValue = objectFactory1
                                .createGenerateWayBillProfile(userProfile);

                JAXBElement<WayBillGenerationRequest> wayBillGenerationRequestValue = objectFactory
                                .createWayBillGenerationRequest(wayBillGenerationRequest);
                
                
                URL u = new URL("http://netconnect.bluedart.com/Demo/ShippingAPI/WayBill/WayBillGeneration.svc?wsdl"); 
                 
                WayBillGeneration iway1 = new WayBillGeneration(u, new QName("http://tempuri.org/","WayBillGeneration"));
                
                IWayBillGeneration iway = iway1.getWSHttpBindingIWayBillGeneration();
        
                
                WayBillGenerationResponse response = iway.generateWayBill(
                                wayBillGenerationRequest, userProfile);

                System.out.println("response--" + response);
                System.out.println("awb "+response.getAWBNo().getValue());
                System.out.println(response.getStatus().getValue().getWayBillGenerationStatus());
                return "";

        }
        
        
        public static void main(String[] args) throws MalformedURLException {
                Bluedart bl_ser = getBluedartService();
                bl_ser.getAirwayBillNo(null);
        }

}