Example usage for javax.xml.bind JAXBContext newInstance

List of usage examples for javax.xml.bind JAXBContext newInstance

Introduction

In this page you can find the example usage for javax.xml.bind JAXBContext newInstance.

Prototype

public static JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException 

Source Link

Document

Create a new instance of a JAXBContext class.

Usage

From source file:GetLeadActivity.java

public static void main(String[] args) {
    System.out.println("Executing Get Lead Activity");
    try {//from w  ww  .  ja v a 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:com.moss.error_reporting.server.ErrorReportServer.java

public static void main(String[] args) throws Exception {

    File log4jConfigFile = new File("log4j.xml");

    if (log4jConfigFile.exists()) {
        DOMConfigurator.configureAndWatch(log4jConfigFile.getAbsolutePath(), 1000);
        System.out.println("Configuring with log file " + log4jConfigFile.getAbsolutePath());
    } else {/*from   ww w  .  j  a v  a  2s  .c o  m*/
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);
    }

    ServerConfiguration config;

    JAXBContext context = JAXBContext.newInstance(ServerConfiguration.class);
    JAXBHelper helper = new JAXBHelper(context);

    File configFile = new File("error-report-server.xml");
    if (!configFile.exists())
        configFile = new File(new File(System.getProperty("user.dir")), ".error-report-server.xml");
    if (!configFile.exists())
        configFile = new File("/etc/error-report-server.xml");

    if (!configFile.exists()) {

        config = new ServerConfiguration();
        helper.writeToFile(helper.writeToXmlString(config), configFile);
        System.out.println("Created default config file at " + configFile.getAbsolutePath());

    } else {
        System.out.println("Reading config file at " + configFile.getAbsolutePath());
        config = helper.readFromFile(configFile);
    }
    new ErrorReportServer(config);
}

From source file:RequestCampaign.java

public static void main(String[] args) {
    System.out.println("Executing Request Campaign");
    try {/*  w w  w.  j  a  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
        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:org.jasig.portlet.maps.tools.MapDataTransformer.java

/**
 * @param args//from   w  w w  .ja  v  a 2s. c  o m
 */
public static void main(String[] args) {

    // translate the KML file to the map portlet's native data format
    File kml = new File("map-data.xml");
    File xslt = new File("google-earth.xsl");

    try {
        TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer(new StreamSource(xslt));
        trans.transform(new StreamSource(kml), new StreamResult(System.out));
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }

    // deserialize the map data from XML
    MapData data = null;
    try {
        JAXBContext jc = JAXBContext.newInstance(MapData.class);
        Unmarshaller u = jc.createUnmarshaller();
        data = (MapData) u.unmarshal(new FileInputStream(new File("map-data-transformed.xml")));
    } catch (JAXBException e1) {
        e1.printStackTrace();
        return;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }

    // ensure each location has a unique, non-null abbreviation
    setAbbreviations(data);

    // update each location with an address
    //        setAddresses(data);

    // sort locations by name
    Collections.sort(data.getLocations(), new ByNameLocationComparator());

    // serialize new map data out to a file into JSON format
    try {
        mapper.defaultPrettyPrintingWriter().writeValue(new File("map.json"), data);
    } catch (JsonGenerationException e) {
        System.out.println("Error generating JSON data for map");
        e.printStackTrace();
    } catch (JsonMappingException e) {
        System.out.println("Error generating JSON data for map");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Error writing JSON data to map file");
        e.printStackTrace();
    }

}

From source file:MergeLeads.java

public static void main(String[] args) {
    System.out.println("Executing Merge Lead");
    try {/*from  w ww.  j ava  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
        ParamsMergeLeads request = new ParamsMergeLeads();

        ArrayOfAttribute winningLeadArray = new ArrayOfAttribute();

        Attribute winner = new Attribute();
        winner.setAttrName("IDNUM");
        winner.setAttrValue("2");
        winningLeadArray.getAttributes().add(winner);
        request.setWinningLeadKeyList(winningLeadArray);

        ArrayOfAttribute losingLeadArray = new ArrayOfAttribute();

        Attribute loser = new Attribute();
        loser.setAttrName("IDNUM");
        loser.setAttrValue("15");
        losingLeadArray.getAttributes().add(loser);

        ArrayOfAttribute losingLeadArray2 = new ArrayOfAttribute();
        Attribute loser2 = new Attribute();
        loser2.setAttrName("IDNUM");
        loser2.setAttrValue("16");
        losingLeadArray2.getAttributes().add(loser2);

        ArrayOfKeyList losingKeyList = new ArrayOfKeyList();
        losingKeyList.getKeyLists().add(losingLeadArray);
        losingKeyList.getKeyLists().add(losingLeadArray2);
        request.setLosingLeadKeyLists(losingKeyList);

        SuccessMergeLeads result = port.mergeLeads(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessMergeLeads.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 {//from  w ww .j  av a2s  .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
        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:ScheduleCampaign.java

public static void main(String[] args) {
    System.out.println("Executing Schedule Campaign");
    try {//from   w  ww . j  a  va2s .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
        ParamsScheduleCampaign request = new ParamsScheduleCampaign();

        request.setProgramName("Trav-Demo-Program");
        request.setCampaignName("Batch Campaign Example");

        // Create setCampaignRunAt timestamp
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(new Date().getTime());

        DatatypeFactory factory = DatatypeFactory.newInstance();
        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<XMLGregorianCalendar> setCampaignRunAtValue = objectFactory
                .createParamsScheduleCampaignCampaignRunAt(factory.newXMLGregorianCalendar(gc));
        request.setCampaignRunAt(setCampaignRunAtValue);

        request.setCloneToProgramName("TestProgramCloneFromSOAP");

        ArrayOfAttrib aoa = new ArrayOfAttrib();

        Attrib attrib = new Attrib();
        attrib.setName("{{my.message}}");
        attrib.setValue("Updated message");

        aoa.getAttribs().add(attrib);

        JAXBElement<ArrayOfAttrib> arrayOfAttrib = objectFactory
                .createParamsScheduleCampaignProgramTokenList(aoa);
        request.setProgramTokenList(arrayOfAttrib);

        SuccessScheduleCampaign result = port.scheduleCampaign(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessScheduleCampaign.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:GetLeadChanges.java

public static void main(String[] args) {
    System.out.println("Executing Get Lead Changes");
    try {/*  w  w w . ja v a2s .  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
        ParamsGetLeadChanges request = new ParamsGetLeadChanges();

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

        ArrayOfString activities = new ArrayOfString();
        activities.getStringItems().add("Visit Webpage");
        activities.getStringItems().add("Click Link");

        JAXBElement<ArrayOfString> activityFilter = objectFactory
                .createParamsGetLeadChangesActivityNameFilter(activities);
        request.setActivityNameFilter(activityFilter);

        // Create oldestCreateAt timestamp from 5 days ago
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(new Date().getTime());
        gc.add(GregorianCalendar.DAY_OF_YEAR, -5);

        DatatypeFactory factory = DatatypeFactory.newInstance();
        JAXBElement<XMLGregorianCalendar> oldestCreateAtValue = objectFactory
                .createStreamPositionOldestCreatedAt(factory.newXMLGregorianCalendar(gc));

        StreamPosition sp = new StreamPosition();
        sp.setOldestCreatedAt(oldestCreateAtValue);
        request.setStartPosition(sp);

        SuccessGetLeadChanges result = port.getLeadChanges(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetLeadChanges.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 {/*  www . ja va 2 s .com*/
        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 .  java2 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();
    }
}