Example usage for org.apache.commons.codec.binary Hex encodeHex

List of usage examples for org.apache.commons.codec.binary Hex encodeHex

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex encodeHex.

Prototype

public static char[] encodeHex(byte[] data) 

Source Link

Document

Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.

Usage

From source file:GetCustomObjects.java

public static void main(String[] args) {
    System.out.println("Executing Get Custom Objects");
    try {/*from   w  w  w.  ja va2  s  . co  m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetCustomObjects request = new ParamsGetCustomObjects();
        request.setObjTypeName("RoadShow");

        ArrayOfAttribute arrayOfAttribute = new ArrayOfAttribute();

        Attribute attr = new Attribute();
        attr.setAttrName("MKTOID");
        attr.setAttrValue("1090177");
        arrayOfAttribute.getAttributes().add(attr);

        JAXBElement<ArrayOfAttribute> attributes = new ObjectFactory()
                .createParamsGetCustomObjectsCustomObjKeyList(arrayOfAttribute);
        request.setCustomObjKeyList(attributes);

        SuccessGetCustomObjects result = port.getCustomObjects(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessGetCustomObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:GetCampaignsForSource.java

public static void main(String[] args) {
    System.out.println("Executing Get Campaigns For Source");
    try {/*from w  w w  . ja  v a  2s .co  m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetCampaignsForSource request = new ParamsGetCampaignsForSource();

        request.setSource(ReqCampSourceType.MKTOWS);

        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<String> name = objectFactory.createParamsGetCampaignsForSourceName("Trigger");
        request.setName(name);

        JAXBElement<Boolean> exactName = objectFactory.createParamsGetCampaignsForSourceExactName(false);
        request.setExactName(exactName);

        SuccessGetCampaignsForSource result = port.getCampaignsForSource(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetCampaignsForSource.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:GetTags.java

public static void main(String[] args) {

    System.out.println("Executing Get Tags");
    try {//from w w  w. ja  va2  s. co  m
        URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL");
        String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
        String marketoSecretKey = "27272727aa";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetTags request = new ParamsGetTags();
        ArrayOfTag tags = new ArrayOfTag();

        Tag tag = new Tag();
        tag.setType("Content Channel");
        /*
        ArrayOfString values = new ArrayOfString();
        values.getStringItems().add("SEM");
        values.getStringItems().add("Email");
                 
        tag.setValues(values);
        tags.getTags().add(tag);
                 
        request.setTagList(tags);
        */

        SuccessGetTags result = port.getTags(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessGetTags.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:GetLeadActivity.java

public static void main(String[] args) {
    System.out.println("Executing Get Lead Activity");
    try {/*from ww  w  . j a va  2s . c o  m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetLeadActivity request = new ParamsGetLeadActivity();
        LeadKey key = new LeadKey();
        key.setKeyType(LeadKeyRef.EMAIL);
        key.setKeyValue("t@t.com");
        request.setLeadKey(key);

        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<Integer> batchSize = objectFactory.createParamsGetLeadActivityBatchSize(10);
        request.setBatchSize(batchSize);

        ActivityTypeFilter atv = new ActivityTypeFilter();
        ArrayOfActivityType aatt = new ArrayOfActivityType();

        aatt.getActivityTypes().add(ActivityType.VISIT_WEBPAGE);
        aatt.getActivityTypes().add(ActivityType.FILL_OUT_FORM);

        atv.setIncludeTypes(aatt);
        JAXBElement<ActivityTypeFilter> typeFilter = objectFactory
                .createParamsGetLeadActivityActivityFilter(atv);
        request.setActivityFilter(typeFilter);

        SuccessGetLeadActivity result = port.getLeadActivity(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetLeadActivity.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:DeleteCustomObjects.java

public static void main(String[] args) {
    System.out.println("Executing Delete Custom Objects");
    try {/*w  w w  . j av a2 s .  c o m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsDeleteCustomObjects request = new ParamsDeleteCustomObjects();
        request.setObjTypeName("RoadShow");

        ArrayOfAttribute arrayOfAttribute = new ArrayOfAttribute();

        Attribute attr = new Attribute();
        attr.setAttrName("MKTOID");
        attr.setAttrValue("1090177");
        arrayOfAttribute.getAttributes().add(attr);

        Attribute attr2 = new Attribute();
        attr2.setAttrName("rid");
        attr2.setAttrValue("123456");
        arrayOfAttribute.getAttributes().add(attr2);

        ArrayOfKeyList keyList = new ArrayOfKeyList();
        keyList.getKeyLists().add(arrayOfAttribute);

        request.setCustomObjKeyLists(keyList);
        SuccessDeleteCustomObjects result = port.deleteCustomObjects(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessDeleteCustomObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:ListOperation.java

public static void main(String[] args) {

    System.out.println("Executing List Operation");
    try {/*from   w  ww  .  ja v  a  2 s .c om*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsListOperation request = new ParamsListOperation();
        request.setListOperation(ListOperationType.ISMEMBEROFLIST);

        ListKey listKey = new ListKey();
        listKey.setKeyType(ListKeyType.MKTOLISTNAME);
        listKey.setKeyValue("Trav-Test-List");
        request.setListKey(listKey);

        LeadKey key = new LeadKey();
        key.setKeyType(LeadKeyRef.IDNUM);
        key.setKeyValue("87710");

        LeadKey key2 = new LeadKey();
        key2.setKeyType(LeadKeyRef.IDNUM);
        key2.setKeyValue("1089946");

        ArrayOfLeadKey leadKeys = new ArrayOfLeadKey();
        leadKeys.getLeadKeies().add(key);
        leadKeys.getLeadKeies().add(key2);

        request.setListMemberList(leadKeys);

        JAXBElement<Boolean> strict = new ObjectFactory().createParamsListOperationStrict(false);
        request.setStrict(strict);

        SuccessListOperation result = port.listOperation(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessListOperation.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:RequestCampaign.java

public static void main(String[] args) {
    System.out.println("Executing Request Campaign");
    try {/*  w  ww. ja  va  2 s  . co m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsRequestCampaign request = new ParamsRequestCampaign();

        request.setSource(ReqCampSourceType.MKTOWS);

        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<Integer> campaignId = objectFactory.createParamsRequestCampaignCampaignId(4496);
        request.setCampaignId(campaignId);

        ArrayOfLeadKey leadKeyList = new ArrayOfLeadKey();
        LeadKey key = new LeadKey();
        key.setKeyType(LeadKeyRef.EMAIL);
        key.setKeyValue("lead@company.com");

        LeadKey key2 = new LeadKey();
        key2.setKeyType(LeadKeyRef.EMAIL);
        key2.setKeyValue("anotherlead@company.com");

        leadKeyList.getLeadKeies().add(key);
        leadKeyList.getLeadKeies().add(key2);

        JAXBElement<ArrayOfLeadKey> arrayOfLeadKey = objectFactory
                .createParamsRequestCampaignLeadList(leadKeyList);
        request.setLeadList(arrayOfLeadKey);

        SuccessRequestCampaign result = port.requestCampaign(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessRequestCampaign.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:SyncLead.java

public static void main(String[] args) {
    System.out.println("Executing syncLead");
    try {// w  w  w  .ja  v  a2 s. c  om
        URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL");
        String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
        String marketoSecretKey = "27272727aa";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsSyncLead request = new ParamsSyncLead();
        LeadRecord key = new LeadRecord();

        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<String> email = objectFactory.createLeadRecordEmail("george@jungle.com");
        key.setEmail(email);
        request.setLeadRecord(key);

        Attribute attr1 = new Attribute();
        attr1.setAttrName("FirstName");
        attr1.setAttrValue("George2");

        Attribute attr2 = new Attribute();
        attr2.setAttrName("LastName");
        attr2.setAttrValue("of the Jungle");

        ArrayOfAttribute aoa = new ArrayOfAttribute();
        aoa.getAttributes().add(attr1);
        aoa.getAttributes().add(attr2);

        QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
        JAXBElement<ArrayOfAttribute> attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa);
        key.setLeadAttributeList(attrList);

        MktowsContextHeader headerContext = new MktowsContextHeader();
        headerContext.setTargetWorkspace("default");

        SuccessSyncLead result = port.syncLead(request, header, headerContext);

        JAXBContext context = JAXBContext.newInstance(SuccessSyncLead.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:SyncCustomObjects.java

public static void main(String[] args) {
    System.out.println("Executing Sync Custom Objects");
    try {/*from   w  ww  .j av a2  s. c o m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsSyncCustomObjects request = new ParamsSyncCustomObjects();
        request.setObjTypeName("RoadShow");
        JAXBElement<SyncOperationEnum> operation = new ObjectFactory()
                .createParamsSyncCustomObjectsOperation(SyncOperationEnum.UPSERT);
        request.setOperation(operation);

        ArrayOfCustomObj customObjects = new ArrayOfCustomObj();

        CustomObj customObj = new CustomObj();

        ArrayOfAttribute arrayOfKeyAttributes = new ArrayOfAttribute();
        Attribute attr = new Attribute();
        attr.setAttrName("MKTOID");
        attr.setAttrValue("1090177");

        Attribute attr2 = new Attribute();
        attr2.setAttrName("rid");
        attr2.setAttrValue("rid1");

        arrayOfKeyAttributes.getAttributes().add(attr);
        arrayOfKeyAttributes.getAttributes().add(attr2);

        JAXBElement<ArrayOfAttribute> keyAttributes = new ObjectFactory()
                .createCustomObjCustomObjKeyList(arrayOfKeyAttributes);
        customObj.setCustomObjKeyList(keyAttributes);
        ArrayOfAttribute arrayOfValueAttributes = new ArrayOfAttribute();

        Attribute city = new Attribute();
        city.setAttrName("city");
        city.setAttrValue("SanMateo");

        Attribute zip = new Attribute();
        zip.setAttrName("zip");
        zip.setAttrValue("94404");

        Attribute state = new Attribute();
        state.setAttrName("state");
        state.setAttrValue("California");

        arrayOfValueAttributes.getAttributes().add(city);
        arrayOfValueAttributes.getAttributes().add(state);
        arrayOfValueAttributes.getAttributes().add(zip);

        JAXBElement<ArrayOfAttribute> valueAttributes = new ObjectFactory()
                .createCustomObjCustomObjAttributeList(arrayOfValueAttributes);
        customObj.setCustomObjAttributeList(valueAttributes);

        customObjects.getCustomObjs().add(customObj);

        SuccessSyncCustomObjects result = port.syncCustomObjects(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessSyncCustomObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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

From source file:SyncMultipleLeads.java

public static void main(String[] args) {
    System.out.println("Executing syncMultipleLeads");
    try {//from w  w w  .j  ava  2  s .c  o  m
        URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL");
        String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
        String marketoSecretKey = "27272727aa";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsSyncMultipleLeads request = new ParamsSyncMultipleLeads();

        ObjectFactory objectFactory = new ObjectFactory();

        JAXBElement<Boolean> dedup = objectFactory.createParamsSyncMultipleLeadsDedupEnabled(true);
        request.setDedupEnabled(dedup);

        ArrayOfLeadRecord arrayOfLeadRecords = new ArrayOfLeadRecord();

        // Create First Lead Record
        LeadRecord rec1 = new LeadRecord();

        JAXBElement<String> email = objectFactory.createLeadRecordEmail("t@t.com");
        rec1.setEmail(email);

        Attribute attr1 = new Attribute();
        attr1.setAttrName("FirstName");
        attr1.setAttrValue("George");

        Attribute attr2 = new Attribute();
        attr2.setAttrName("LastName");
        attr2.setAttrValue("of the Jungle");

        ArrayOfAttribute aoa = new ArrayOfAttribute();
        aoa.getAttributes().add(attr1);
        aoa.getAttributes().add(attr2);

        QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
        JAXBElement<ArrayOfAttribute> attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa);

        rec1.setLeadAttributeList(attrList);
        arrayOfLeadRecords.getLeadRecords().add(rec1);

        // Create Second Lead Record
        LeadRecord rec2 = new LeadRecord();

        JAXBElement<String> email2 = objectFactory.createLeadRecordEmail("myemail@test.com");
        rec2.setEmail(email2);

        Attribute attr11 = new Attribute();
        attr11.setAttrName("FirstName");
        attr11.setAttrValue("Nancy");

        Attribute attr21 = new Attribute();
        attr21.setAttrName("LastName");
        attr21.setAttrValue("Lady");

        ArrayOfAttribute aoa2 = new ArrayOfAttribute();
        aoa2.getAttributes().add(attr11);
        aoa2.getAttributes().add(attr21);

        qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
        JAXBElement<ArrayOfAttribute> attrList2 = new JAXBElement(qname, ArrayOfAttribute.class, aoa2);

        rec2.setLeadAttributeList(attrList);
        arrayOfLeadRecords.getLeadRecords().add(rec2);

        request.setLeadRecordList(arrayOfLeadRecords);

        SuccessSyncMultipleLeads result = port.syncMultipleLeads(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessSyncMultipleLeads.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

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