private String combineData() { String content = ""; XMLBuilder builder = null; int index = 0; String[] tags; boolean isEntry = contentArray.size() != 2; if (isEntry) { tags = new String[] { "date-created", "time-created", "latitude", "longitude", "first-name", "middle-name", "last-name", "birthday", "age", "gender", "address", "slide-number", "region", "case", "species", "drugs-given", "exam-result", "remarks" }; } else { tags = new String[] {"user", "pass"}; } try { if (isEntry) builder = XMLBuilder.create("entry"); else builder = XMLBuilder.create("credentials"); Log.d("MakeTextFile", String.valueOf(contentArray.size())); for (String data : contentArray) { builder.element(tags[index++]).text(data); Log.v("WRITE", "CONTENT: " + data); } Properties outputProperties = new Properties(); outputProperties.put(javax.xml.transform.OutputKeys.METHOD, "xml"); outputProperties.put(javax.xml.transform.OutputKeys.INDENT, "yes"); outputProperties.put("{http://xml.apache.org/xslt}indent-amount", "2"); outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); content = builder.asString(outputProperties); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return content; }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { checkArgument( checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!"); Integer memoryInMB = Integer.class.cast(payload); XMLBuilder cpuItem; try { cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS); cpuItem.e("rasd:AllocationUnits").t("byte * 2^20"); cpuItem.e("rasd:Description").t("Memory Size"); cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory"); cpuItem.e("rasd:InstanceID").t("5"); cpuItem.e("rasd:Reservation").t("0"); cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value()); cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString()); cpuItem.e("rasd:Weight").t("0"); Properties outputProperties = new Properties(); outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); request = super.bindToRequest(request, cpuItem.asString(outputProperties)); } catch (Exception e) { Throwables.propagate(e); } return request; }
@Test public void forwardedWithDelayTest() throws Exception { XmlPullParser parser; String control; Forwarded fwd; // @formatter:off control = XMLBuilder.create("forwarded") .a("xmlns", "urn:xmpp:forwarded:0") .e("message") .a("from", "*****@*****.**") .up() .e("delay") .ns(DelayInformation.NAMESPACE) .a("stamp", "2010-07-10T23:08:25Z") .asString(outputProperties); // @formatter:on parser = PacketParserUtils.getParserFor(control); fwd = (Forwarded) new ForwardedProvider().parse(parser); // assert there is delay information in packet DelayInformation delay = fwd.getDelayInformation(); assertNotNull(delay); // check message assertEquals("*****@*****.**", fwd.getForwardedPacket().getFrom()); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); assertEquals("forwarded", parser.getName()); }
@Test public void forwardedTest() throws Exception { XmlPullParser parser; String control; Forwarded fwd; control = XMLBuilder.create("forwarded") .a("xmlns", "urn:xmpp:forwarded:0") .e("message") .a("from", "*****@*****.**") .asString(outputProperties); parser = PacketParserUtils.getParserFor(control); fwd = (Forwarded) new ForwardedProvider().parse(parser); // no delay in packet assertEquals(null, fwd.getDelayInformation()); // check message assertEquals("*****@*****.**", fwd.getForwardedPacket().getFrom()); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); assertEquals("forwarded", parser.getName()); }
public XMLBuilder toXMLBuilder() throws ServiceException, ParserConfigurationException, FactoryConfigurationError, TransformerException { XMLBuilder builder = XMLBuilder.create("DeleteBucket") .attr("xmlns", Constants.XML_NAMESPACE) .elem("Bucket") .text(getName()) .up(); return builder; }
@Test(expected = Exception.class) public void forwardedEmptyTest() throws Exception { XmlPullParser parser; String control; control = XMLBuilder.create("forwarded") .a("xmlns", "urn:xmpp:forwarded:0") .asString(outputProperties); parser = PacketParserUtils.getParserFor(control); new ForwardedProvider().parse(parser); }
// TODO: finish me! @Test(enabled = false) public void testCreateNodeUsingVCloud1_0ApiAgainstVCloudDirector1_5WhenVAppTemplateHasNetworkNamedNone() throws Exception { String group = "group"; String name = "group-abcd"; String instantiateXML = XMLBuilder.create("InstantiateVAppTemplateParams") .a("xmlns", ns) .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1") .a("deploy", "false") .a("name", name) .a("powerOn", "false") .e("Description") .up() .e("InstantiationParams") .e("NetworkConfigSection") .e("ovf:Info") .t("Configuration parameters for logical networks") .up() .e("NetworkConfig") .a("networkName", "orgNet-jclouds-External") // NOTE not "None" .e("Configuration") .e("ParentNetwork") .a("href", ENDPOINT + "/v1.0/network/" + networkId) .up() .e("FenceMode") .t("bridged") .up() .up() .up() .up() .up() .e("Source") .a("href", ENDPOINT + "/v1.0/vAppTemplate/" + templateId) .up() .e("AllEULAsAccepted") .t("true") .up() .asString(outputProperties); HttpRequest version1_0InstantiateWithNetworkNamedSameAsOrgNetwork = HttpRequest.builder() .method("POST") .endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate") .addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml") .addHeader("x-vcloud-authorization", sessionToken) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken) .payload( payloadFromStringWithContentType( instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")) .build(); ComputeService compute = requestsSendResponses( ImmutableMap.<HttpRequest, HttpResponse>builder() .put(versionsRequest, versionsResponseFromVCD1_5) .put( version1_0LoginRequest, successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg) .put( version1_0GetOrgRequest, successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork) .put( version1_0GetCatalogRequest, successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate) .put( version1_0GetCatalogItemRequest, successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate) .put( version1_0GetVDCRequest, successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork) .put( version1_0GetVAppTemplateRequest, successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent) .put( version1_0GetOVFForVAppTemplateRequest, successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM) .put( version1_0InstantiateWithNetworkNamedSameAsOrgNetwork, successfulVersion1_0InstantiatedVApp) .build()); InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn starter = compute .getContext() .utils() .injector() .getInstance( InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class); NodeAndInitialCredentials<VApp> appAndCreds = starter.createNodeWithGroupEncodedIntoName(group, name, compute.templateBuilder().build()); assertEquals(appAndCreds.getNode().getName(), name); assertEquals( appAndCreds.getCredentials(), LoginCredentials.builder().user("root").password("fromVApp").build()); }
public void testInstantiateVAppFromTemplateWhenUsingOverriddenNetworkAndFenceMode() throws Exception { String name = "group-abcd"; FenceMode fenceMode = FenceMode.NAT_ROUTED; URI parentNetwork = URI.create(ENDPOINT + "/v1.0/network/" + "foooooooo"); String instantiateXML = XMLBuilder.create("InstantiateVAppTemplateParams") .a("xmlns", ns) .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1") .a("deploy", "false") .a("name", name) .a("powerOn", "false") .e("Description") .up() .e("InstantiationParams") .e("NetworkConfigSection") .e("ovf:Info") .t("Configuration parameters for logical networks") .up() .e("NetworkConfig") .a("networkName", "jclouds") // NOTE not "None" .e("Configuration") .e("ParentNetwork") .a("href", parentNetwork.toASCIIString()) .up() .e("FenceMode") .t(fenceMode.toString()) .up() .up() .up() .up() .up() .e("Source") .a("href", ENDPOINT + "/v1.0/vAppTemplate/" + templateId) .up() .e("AllEULAsAccepted") .t("true") .up() .asString(outputProperties); HttpRequest version1_0InstantiateWithCustomizedNetwork = HttpRequest.builder() .method("POST") .endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate") .addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml") .addHeader("x-vcloud-authorization", sessionToken) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken) .payload( payloadFromStringWithContentType( instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")) .build(); ComputeService compute = requestsSendResponses( ImmutableMap.<HttpRequest, HttpResponse>builder() .put(versionsRequest, versionsResponseFromVCD1_5) .put( version1_0LoginRequest, successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg) .put( version1_0GetOrgRequest, successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork) .put( version1_0GetCatalogRequest, successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate) .put( version1_0GetCatalogItemRequest, successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate) .put( version1_0GetVDCRequest, successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork) .put( version1_0GetVAppTemplateRequest, successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent) .put( version1_0GetOVFForVAppTemplateRequest, successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM) .put( version1_0InstantiateWithCustomizedNetwork, successfulVersion1_0InstantiatedVApp) .build()); InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn starter = compute .getContext() .utils() .injector() .getInstance( InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class); Template template = compute.templateBuilder().build(); template .getOptions() .as(VCloudTemplateOptions.class) .parentNetwork(parentNetwork) .fenceMode(fenceMode); starter.instantiateVAppFromTemplate(name, template); }