List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java
/** * Initialize JAXB transformers/* w w w .ja v a 2 s .c o m*/ * * @throws JAXBException */ private void initJAXB() throws JAXBException { if (marshaller != null) { return; } JAXBContext jaxbContext = getPspipJaxb(); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = jaxbContext.createUnmarshaller(); }
From source file:alter.vitro.vgw.service.VitroGatewayService.java
public void registerOnDemand(int modeFlag) throws Exception { if (!getUseIdas()) // send through pipe to the amethyst activeMQ {//from w w w . j a va2s . c o m registerSOSpipe.run(); } //Scan controlled WSI and associated resources CGateway myGateway = new CGateway(); myGateway.setId(getAssignedGatewayUniqueIdFromReg()); myGateway.setName(""); myGateway.setDescription(""); // The code for acquiring GW description is in the createWSIDescr() method CGatewayWithSmartDevices gwWithNodeDescriptorList = myDCon.createWSIDescr(myGateway); logger.debug("nodeDescriptorList = {}", gwWithNodeDescriptorList.getSmartDevVec()); List<CSmartDevice> alterNodeDescriptorsList = gwWithNodeDescriptorList.getSmartDevVec(); ResourceAvailabilityService.getInstance().updateCachedNodeList(alterNodeDescriptorsList, ResourceAvailabilityService.SUBSEQUENT_DISCOVERY); // PREPARE TO SEND THE MESSAGE! JAXBContext jaxbContext = Utils.getJAXBContext(); Marshaller mar = jaxbContext.createMarshaller(); mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // new new for (CSmartDevice alterNodeDescriptor : alterNodeDescriptorsList) { RegisterSensor registerSensor = sensorMLMessageAdapter.getRegisterSensorMessage(alterNodeDescriptor, gwWithNodeDescriptorList.getGateway()); if (!getUseIdas()) // send through pipe to the amethyst activeMQ { ByteArrayOutputStream baos = new ByteArrayOutputStream(); mar.marshal(registerSensor, baos); String requestXML = baos.toString(HTTP.UTF_8); registerSOSpipe.sendText(requestXML); } else { RegisterSensorResponse registerSensorResponse = idas.registerSensor(registerSensor); String assignedSensorId = registerSensorResponse.getAssignedSensorId(); // DEBUG System.out.println("Registered Sensor with id: " + assignedSensorId); //Register assigned sensor id to associate subsequent observation to the correct node //TODO: understand if persistence is needed idasNodeMapping.put(alterNodeDescriptor.getId(), assignedSensorId); } } // end of --> new new /* //Register available resources on the external middleware (here the end user / VSP app) List<RegisterSensor> registerSensorList = sensorMLMessageAdapter.getRegisterSensorMessage(gwWithNodeDescriptorList); // PREPARE TO SEND THE MESSAGE! JAXBContext jaxbContext = Utils.getJAXBContext(); Marshaller mar = jaxbContext.createMarshaller(); mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); for (RegisterSensor registerSensor : registerSensorList) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); mar.marshal(registerSensor, baos); String requestXML = baos.toString(HTTP.UTF_8); if(!getUseIdas()) // send through pipe to the amethyst activeMQ { registerSOSpipe.sendText(requestXML); } else { IdasProxy IdasPrx = new IdasProxyImpl(getDVNSUrl()); this.setIdas(IdasPrx); RegisterSensorResponse registerSensorResponse = idas.registerSensor(registerSensor); String assignedSensorId = registerSensorResponse.getAssignedSensorId(); // DEBUG System.out.println("Registered Sensor with id: " + assignedSensorId); idasNodeMapping.put(, assignedSensorId); } } */ // This closes the pipe for sending registering messages if (!getUseIdas()) // send through pipe to the amethyst activeMQ { registerSOSpipe.stop(); } // SEND TO VSP a confirmation message of nodes/enabled disabled // IF VSP was already running and had a cache for this VGW, that this message will be ignored // But If VSP was restarted while the VGW was running, then this message will be used to update the VSP!!! // send ONLY if you have previously received some request from the VSP // which means ONLY if this is NOT the registerOnDemand call in the init(). Otherwise the VGW spoils the cache in the VSP with all nodes set as enabled if (modeFlag == POST_INIT_FLAG && isGwWasInitiated()) { String msgCurrentEnabledStatusFromCache = ResourceAvailabilityService.getInstance() .createSynchConfirmationForVSPFromCurrentStatus_VGWInitiated(); if (msgCurrentEnabledStatusFromCache != null && !msgCurrentEnabledStatusFromCache.isEmpty()) { StringBuilder toAddHeaderBld = new StringBuilder(); // based on a UserNodeResponse structure we should have a queryId (which here is the messageType again, as src which should be the VSPCore, and a body) toAddHeaderBld.append(UserNodeResponse.COMMAND_TYPE_ENABLENODES_RESP); toAddHeaderBld.append(UserNodeResponse.headerSpliter); toAddHeaderBld .append(VitroGatewayService.getVitroGatewayService().getAssignedGatewayUniqueIdFromReg()); toAddHeaderBld.append(UserNodeResponse.headerSpliter); toAddHeaderBld.append(msgCurrentEnabledStatusFromCache); msgCurrentEnabledStatusFromCache = toAddHeaderBld.toString(); SimpleQueryHandler.getInstance().sendResponse(msgCurrentEnabledStatusFromCache); } } }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Export document from openkm repository to filesystem. *///from w w w .j a v a 2 s . com public static ImpExpStats exportDocument(String token, String docPath, String destPath, String metadata, boolean history, Writer out, InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException, AccessDeniedException, ParseException, NoSuchGroupException { DocumentModule dm = ModuleManager.getDocumentModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Document docChild = dm.getProperties(token, docPath); Gson gson = new Gson(); ImpExpStats stats = new ImpExpStats(); // Version history if (history) { // Create dummy document file new File(destPath).createNewFile(); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); FileOutputStream fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } for (Version ver : dm.getVersionHistory(token, docChild.getPath())) { String versionPath = destPath + "#v" + ver.getName() + "#"; FileOutputStream vos = new FileOutputStream(versionPath); InputStream vis = dm.getContentByVersion(token, docChild.getPath(), ver.getName()); IOUtils.copy(vis, vos); IOUtils.closeQuietly(vis); IOUtils.closeQuietly(vos); FileLogger.info(BASE_NAME, "Created document ''{0}'' version ''{1}''", docChild.getPath(), ver.getName()); // Metadata if (metadata.equals("JSON")) { VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); String json = gson.toJson(vmd); vos = new FileOutputStream(versionPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, vos); IOUtils.closeQuietly(vos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(VersionMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(vmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } } else { FileOutputStream fos = new FileOutputStream(destPath); InputStream is = dm.getContent(token, docChild.getPath(), false); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); FileLogger.info(BASE_NAME, "Created document ''{0}''", docChild.getPath()); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } if (out != null) { out.write(deco.print(docChild.getPath(), docChild.getActualVersion().getSize(), null)); out.flush(); } // Stats stats.setSize(stats.getSize() + docChild.getActualVersion().getSize()); stats.setDocuments(stats.getDocuments() + 1); return stats; }
From source file:com.sun.tools.xjc.addon.xew.XmlElementWrapperPluginTest.java
/** * Standard test for XSD examples.//w ww . ja va 2s . c o m * * @param testName * the prototype of XSD file name / package name * @param extraXewOptions * to be passed to plugin * @param generateEpisode * generate episode file and check the list of classes included into it * @param classesToCheck * expected classes/files in target directory; these files content is checked if it is present in * resources directory; {@code ObjectFactory.java} is automatically included */ static void assertXsd(String testName, String[] extraXewOptions, boolean generateEpisode, String... classesToCheck) throws Exception { String resourceXsd = testName + ".xsd"; String packageName = testName.replace('-', '_'); // Force plugin to reinitialize the logger: System.clearProperty(XmlElementWrapperPlugin.COMMONS_LOGGING_LOG_LEVEL_PROPERTY_KEY); URL xsdUrl = XmlElementWrapperPluginTest.class.getResource(resourceXsd); File targetDir = new File(GENERATED_SOURCES_PREFIX); targetDir.mkdirs(); PrintStream loggingPrintStream = new PrintStream( new LoggingOutputStream(logger, LoggingOutputStream.LogLevel.INFO, "[XJC] ")); String[] opts = ArrayUtils.addAll(extraXewOptions, "-no-header", "-extension", "-Xxew", "-d", targetDir.getPath(), xsdUrl.getFile()); String episodeFile = new File(targetDir, "episode.xml").getPath(); // Episode plugin should be triggered after Xew, see https://github.com/dmak/jaxb-xew-plugin/issues/6 if (generateEpisode) { opts = ArrayUtils.addAll(opts, "-episode", episodeFile); } assertTrue("XJC compilation failed. Checked console for more info.", Driver.run(opts, loggingPrintStream, loggingPrintStream) == 0); if (generateEpisode) { // FIXME: Episode file actually contains only value objects Set<String> classReferences = getClassReferencesFromEpisodeFile(episodeFile); if (Arrays.asList(classesToCheck).contains("package-info")) { classReferences.add(packageName + ".package-info"); } assertEquals("Wrong number of classes in episode file", classesToCheck.length, classReferences.size()); for (String className : classesToCheck) { assertTrue(className + " class is missing in episode file;", classReferences.contains(packageName + "." + className)); } } targetDir = new File(targetDir, packageName); Collection<String> generatedJavaSources = new HashSet<String>(); // *.properties files are ignored: for (File targetFile : FileUtils.listFiles(targetDir, new String[] { "java" }, true)) { // This is effectively the path of targetFile relative to targetDir: generatedJavaSources .add(targetFile.getPath().substring(targetDir.getPath().length() + 1).replace('\\', '/')); } // This class is added and checked by default: classesToCheck = ArrayUtils.add(classesToCheck, "ObjectFactory"); assertEquals("Wrong number of generated classes " + generatedJavaSources + ";", classesToCheck.length, generatedJavaSources.size()); for (String className : classesToCheck) { className = className.replace('.', '/') + ".java"; assertTrue(className + " is missing in target directory", generatedJavaSources.contains(className)); } // Check the contents for those files which exist in resources: for (String className : classesToCheck) { className = className.replace('.', '/') + ".java"; File sourceFile = new File(PREGENERATED_SOURCES_PREFIX + packageName, className); if (sourceFile.exists()) { // To avoid CR/LF conflicts: assertEquals("For " + className, FileUtils.readFileToString(sourceFile).replace("\r", ""), FileUtils.readFileToString(new File(targetDir, className)).replace("\r", "")); } } JAXBContext jaxbContext = compileAndLoad(packageName, targetDir, generatedJavaSources); URL xmlTestFile = XmlElementWrapperPluginTest.class.getResource(testName + ".xml"); if (xmlTestFile != null) { StringWriter writer = new StringWriter(); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(schemaFactory.newSchema(xsdUrl)); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Object bean = unmarshaller.unmarshal(xmlTestFile); marshaller.marshal(bean, writer); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); Diff xmlDiff = new Diff(IOUtils.toString(xmlTestFile), writer.toString()); assertXMLEqual("Generated XML is wrong: " + writer.toString(), xmlDiff, true); } }
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public Marshaller getMarshaller(Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE); return m;/*from w w w .ja v a 2 s .c o m*/ }
From source file:com.github.webapp_minifier.WebappMinifierMojo.java
/** * @see org.apache.maven.plugin.AbstractMojo#execute() *///from ww w. ja v a2 s . c o m @Override public void execute() throws MojoExecutionException { // Copy the source directory to the target directory. try { getLog().debug("Copying " + this.sourceDirectory + " to " + this.minifiedDirectory); if (this.minifiedDirectory.exists()) { FileUtils.deleteDirectory(this.minifiedDirectory); } FileUtils.copyDirectoryStructure(this.sourceDirectory, this.minifiedDirectory); } catch (final IOException e) { throw new MojoExecutionException("Failed to copy the source directory", e); } if (!this.skipMinify) { // Process each of the requested files. final DefaultTagHandler tagHandler = new DefaultTagHandler(getLog(), this); final TagReplacer tagReplacer = TagReplacerFactory.getReplacer(this.parser, getLog(), this.encoding); for (final String fileName : getFilesToProcess()) { final File htmlFile = new File(this.minifiedDirectory, fileName); final File minifiedHtmlFile = new File(this.minifiedDirectory, fileName + ".min"); final File htmlFileBackup = new File(this.minifiedDirectory, fileName + ".bak"); InputStream inputStream = null; OutputStream outputStream = null; try { getLog().info("Processing " + htmlFile.getCanonicalFile()); final String baseUri = CommonUtils.getBaseUri(htmlFile, this.minifiedDirectory); inputStream = new BufferedInputStream(new FileInputStream(htmlFile)); outputStream = new BufferedOutputStream(new FileOutputStream(minifiedHtmlFile)); tagHandler.start(htmlFile); tagReplacer.process(inputStream, tagHandler, baseUri, outputStream); } catch (final IOException e) { throw new MojoExecutionException("Failed to process " + htmlFile, e); } finally { IOUtil.close(inputStream); IOUtil.close(outputStream); } if (!htmlFile.renameTo(htmlFileBackup)) { throw new MojoExecutionException( "Failed to rename " + htmlFile.getName() + " to " + htmlFileBackup.getName()); } if (!minifiedHtmlFile.renameTo(htmlFile)) { throw new MojoExecutionException( "Failed to rename " + minifiedHtmlFile.getName() + " to " + htmlFile.getName()); } } // Write out the summary file. final File summaryFile = new File(this.minifiedDirectory, "webapp-minifier-summary.xml"); try { final JAXBContext context = JAXBContext.newInstance(MinificationSummary.class); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, getEncoding()); marshaller.marshal(tagHandler.getReport(), summaryFile); tagHandler.getReport(); } catch (final JAXBException e) { throw new MojoExecutionException("Failed to marshal the plugin's summary to XML", e); } // Attempt to configure the maven-war-plugin. if (this.project != null) { this.project.getProperties().setProperty("war.warName", "my-name.war"); for (final Object object : this.project.getBuildPlugins()) { final Plugin plugin = (Plugin) object; if (StringUtils.equals("org.apache.maven.plugins", plugin.getGroupId()) && StringUtils.equals("maven-war-plugin", plugin.getArtifactId())) { getLog().info("Examining plugin " + plugin.getArtifactId()); final Object configuration = plugin.getConfiguration(); getLog().info("Fetched configuration " + configuration.getClass() + ": " + configuration); final Xpp3Dom document = (Xpp3Dom) configuration; final Xpp3Dom[] children = document.getChildren("warSourceDirectory"); getLog().info("Fetched children " + children.length); for (final Xpp3Dom child : children) { getLog().info("Child: " + child); getLog().info("Child Value: " + child.getValue()); child.setValue(child.getValue() + "_oops"); getLog().info("Child Value: " + child.getValue()); } } } } } }
From source file:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java
/** Write the result set as a RegistryObjectList */ private void writeRegistryObjectList(List<? extends IdentifiableType> ebRegistryObjectTypeList) throws IOException, RegistryException { ServletOutputStream sout = null;//ww w . j a va 2 s. com try { sout = response.getOutputStream(); @SuppressWarnings("unchecked") RegistryObjectListType ebRegistryObjectListType = bu .getRegistryObjectListType((List<RegistryObjectType>) ebRegistryObjectTypeList); // javax.xml.bind.Marshaller marshaller = bu.rimFac.createMarshaller(); javax.xml.bind.Marshaller marshaller = bu.getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(ebRegistryObjectListType, sout); } catch (JAXBException e) { throw new RegistryException(e); } finally { if (sout != null) { sout.close(); } } }
From source file:labr_client.xml.ObjToXML.java
public static String marshallRequest(LabrRequest request) { String xml = ""; String date = String.format("%1$tY%1$tm%1$td", new Date()); String time = String.format("%1$tH%1$tM%1$tS", new Date()); try {//from w w w. j a va 2 s. c o m JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); File labrRequest = new File("data/tmp/" + date + time + ".xml"); m.marshal(request, labrRequest); xml = FileUtils.readFileToString(labrRequest); } catch (JAXBException | IOException ex) { Logger.getLogger(ObjToXML.class.getName()).log(Level.SEVERE, null, ex); } return xml; }
From source file:at.ac.tuwien.dsg.comot.orchestrator.interraction.rsybl.rSYBLInterraction.java
public void sendUpdatedConfigToRSYBL(CloudService serviceTemplate, CompositionRulesConfiguration compositionRulesConfiguration, String effectsJSON) { HttpHost endpoint = new HttpHost(rSYBL_BASE_IP, rSYBL_BASE_PORT); {/*www.j a va 2s .com*/ DefaultHttpClient httpClient = new DefaultHttpClient(); try { JAXBContext jAXBContext = JAXBContext.newInstance(CompositionRulesConfiguration.class); Marshaller marshaller = jAXBContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); log.info("Sending updated composition rules"); marshaller.marshal(compositionRulesConfiguration, sw); log.info(sw.toString()); URI putDeploymentStructureURL = UriBuilder .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/compositionRules").build(); HttpPost putDeployment = new HttpPost(putDeploymentStructureURL); StringEntity entity = new StringEntity(sw.getBuffer().toString()); entity.setContentType("application/xml"); entity.setChunked(true); putDeployment.setEntity(entity); log.info("Executing request " + putDeployment.getRequestLine()); HttpResponse response = httpClient.execute(endpoint, putDeployment); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (response.getStatusLine().getStatusCode() == 200) { } if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); } } catch (Exception e) { log.error(e.getMessage(), e); } } { DefaultHttpClient httpClient = new DefaultHttpClient(); try { URI putDeploymentStructureURL = UriBuilder .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/elasticityCapabilitiesEffects") .build(); HttpPost putDeployment = new HttpPost(putDeploymentStructureURL); StringEntity entity = new StringEntity(effectsJSON); entity.setContentType("application/json"); entity.setChunked(true); putDeployment.setEntity(entity); log.info("Send updated Effects"); log.info(effectsJSON); HttpResponse response = httpClient.execute(endpoint, putDeployment); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (response.getStatusLine().getStatusCode() == 200) { } if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); } } catch (Exception e) { log.error(e.getMessage(), e); } } { DefaultHttpClient httpClient = new DefaultHttpClient(); try { JAXBContext jAXBContext = JAXBContext.newInstance(CloudServiceXML.class); CloudServiceXML cloudServiceXML = toRSYBLRepresentation(serviceTemplate); Marshaller marshaller = jAXBContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); log.info("Sending updated service description to rSYBL"); marshaller.marshal(cloudServiceXML, sw); log.info(sw.toString()); URI putDeploymentStructureURL = UriBuilder .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/elasticityRequirements") .build(); HttpPost putDeployment = new HttpPost(putDeploymentStructureURL); StringEntity entity = new StringEntity(sw.getBuffer().toString()); entity.setContentType("application/xml"); entity.setChunked(true); putDeployment.setEntity(entity); log.info("Executing request " + putDeployment.getRequestLine()); HttpResponse response = httpClient.execute(endpoint, putDeployment); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (response.getStatusLine().getStatusCode() == 200) { } if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); } } catch (Exception e) { log.error(e.getMessage(), e); } } }
From source file:at.gv.egovernment.moa.id.protocols.stork2.MandateRetrievalRequest.java
private PersonalAttribute marshallComplexAttribute(PersonalAttribute currentAttribute, Object obj) { // TODO refactor StringWriter stringWriter = new StringWriter(); try {/*www. jav a 2 s. c o m*/ if (obj instanceof MandateContentType) { final Marshaller marshaller = JAXBContext.newInstance(MandateContentType.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(new JAXBElement<MandateContentType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateContentType.class, null, (MandateContentType) obj), stringWriter); } else if (obj instanceof MandateType) { final Marshaller marshaller = JAXBContext.newInstance(MandateType.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(new JAXBElement<MandateType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateType.class, null, (MandateType) obj), stringWriter); } else if (obj instanceof RepresentationPersonType) { final Marshaller marshaller = JAXBContext.newInstance(RepresentationPersonType.class) .createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal( new JAXBElement<RepresentationPersonType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), RepresentationPersonType.class, null, (RepresentationPersonType) obj), stringWriter); } } catch (Exception ex) { Logger.error("Could not marshall atrribute: " + currentAttribute.getName() + ", " + ex.getMessage()); return new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), new ArrayList<String>(), AttributeStatusType.NOT_AVAILABLE.value()); } ArrayList<String> value = new ArrayList<String>(); value.add(stringWriter.toString()); PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, AttributeStatusType.AVAILABLE.value()); return personalAttribute; }