List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:vitro.vgw.communication.idas.IdasProxyImpl.java
private Object sendRequest(Object request) throws VitroGatewayException { Object result = null;/* w ww . j a va 2 s. c om*/ InputStream instream = null; try { HttpPost httpPost = new HttpPost(endPoint); JAXBContext jaxbContext = Utils.getJAXBContext(); Marshaller mar = jaxbContext.createMarshaller(); mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mar.marshal(request, baos); String requestXML = baos.toString(HTTP.UTF_8); StringEntity entityPar = new StringEntity(requestXML, "application/xml", HTTP.UTF_8); httpPost.setEntity(entityPar); HttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { instream = entity.getContent(); Unmarshaller unmarshaller = Utils.getJAXBContext().createUnmarshaller(); Object idasResponse = unmarshaller.unmarshal(instream); if (idasResponse instanceof ExceptionReport) { throw Utils.parseException((ExceptionReport) idasResponse); } result = idasResponse; } else { throw new VitroGatewayException("Server response does not contain any body"); } } catch (VitroGatewayException e) { throw e; } catch (Exception e) { throw new VitroGatewayException(e); } finally { if (instream != null) { try { instream.close(); } catch (IOException e) { logger.error("Error while closing server response stream", e); } } } return result; }
From source file:com.t2tierp.controller.nfe.CancelaNfe.java
private String xmlCancelamento(br.inf.portalfiscal.nfe.retevento.TRetEnvEvento retorno, String versaoDados, String codigoUf, String ambiente, String chaveAcesso, String numeroProtocolo, String justificativa, String cnpj, String dataHoraEvento) throws Exception { TProcEvento xml = new TProcEvento(); xml.setVersao(versaoDados);/* w ww.ja v a 2s .c om*/ TEvento evento = new TEvento(); xml.setEvento(evento); TEvento.InfEvento infEvento = new TEvento.InfEvento(); evento.setInfEvento(infEvento); evento.setVersao(versaoDados); TEvento.InfEvento.DetEvento detEvento = new TEvento.InfEvento.DetEvento(); infEvento.setDetEvento(detEvento); infEvento.setCNPJ(cnpj); infEvento.setCOrgao(codigoUf); infEvento.setChNFe(chaveAcesso); infEvento.setDhEvento(dataHoraEvento); infEvento.setId("ID" + "110111" + chaveAcesso + "01"); infEvento.setNSeqEvento("1"); infEvento.setTpAmb(ambiente); infEvento.setTpEvento("110111"); infEvento.setVerEvento(versaoDados); detEvento.setDescEvento("Cancelamento"); detEvento.setNProt(numeroProtocolo); detEvento.setVersao(versaoDados); detEvento.setXJust(justificativa); br.inf.portalfiscal.nfe.procevento.TRetEvento retEvento = new br.inf.portalfiscal.nfe.procevento.TRetEvento(); xml.setRetEvento(retEvento); br.inf.portalfiscal.nfe.procevento.TRetEvento.InfEvento retInfEvento = new br.inf.portalfiscal.nfe.procevento.TRetEvento.InfEvento(); retEvento.setInfEvento(retInfEvento); retEvento.setVersao(retorno.getVersao()); retInfEvento.setCPFDest(retorno.getRetEvento().get(0).getInfEvento().getCPFDest()); retInfEvento.setCNPJDest(retorno.getRetEvento().get(0).getInfEvento().getCNPJDest()); retInfEvento.setCOrgao(retorno.getRetEvento().get(0).getInfEvento().getCOrgao()); retInfEvento.setCStat(retorno.getRetEvento().get(0).getInfEvento().getCStat()); retInfEvento.setChNFe(retorno.getRetEvento().get(0).getInfEvento().getChNFe()); retInfEvento.setDhRegEvento(retorno.getRetEvento().get(0).getInfEvento().getDhRegEvento()); retInfEvento.setEmailDest(retorno.getRetEvento().get(0).getInfEvento().getEmailDest()); retInfEvento.setId(retorno.getRetEvento().get(0).getInfEvento().getId()); retInfEvento.setNProt(retorno.getRetEvento().get(0).getInfEvento().getNProt()); retInfEvento.setNSeqEvento(retorno.getRetEvento().get(0).getInfEvento().getNSeqEvento()); retInfEvento.setTpAmb(retorno.getRetEvento().get(0).getInfEvento().getTpAmb()); retInfEvento.setTpEvento(retorno.getRetEvento().get(0).getInfEvento().getTpEvento()); retInfEvento.setVerAplic(retorno.getRetEvento().get(0).getInfEvento().getVerAplic()); retInfEvento.setXEvento(retorno.getRetEvento().get(0).getInfEvento().getXEvento()); retInfEvento.setXMotivo(retorno.getRetEvento().get(0).getInfEvento().getXMotivo()); JAXBContext jc = JAXBContext.newInstance("br.inf.portalfiscal.nfe.procevento"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); JAXBElement<TProcEvento> element = new br.inf.portalfiscal.nfe.procevento.ObjectFactory() .createProcEventoNFe(xml); StringWriter writer = new StringWriter(); marshaller.marshal(element, writer); return writer.toString(); }
From source file:fr.fastconnect.factory.tibco.bw.maven.compile.ArchiveBuilder.java
public void save(File f) { try {//from ww w . jav a 2 s . c om JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(this.repository, f); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:eu.crisis_economics.abm.dashboard.cluster.script.BashScheduler.java
/** {@inheritDoc} * @throws SchedulerException /*from www . j a va 2 s.c om*/ */ @Override public String runParameterSweep(final Model paramSweepConfig, final String timeLimit, final File workDir) throws SchedulerException { File file = null; try { // file = File.createTempFile("paramsweep-", ".xml"); file = new File(workDir, "paramsweep-config.xml"); Marshaller marshaller = JAXBContext.newInstance(Model.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(paramSweepConfig, file); // } catch (IOException e) { // throw new SchedulerException("Could not create temporary parameter-sweep configuration xml.", e); } catch (JAXBException e) { throw new SchedulerException( "Could not write temporary parameter-sweep configuration xml: " + file.toString(), e); } CommandLine cmd = new CommandLine(cmdFile); Map<String, Object> substitutions = new HashMap<String, Object>(); substitutions.put(CMD_SUBSTITUTION_NAME_FILE, file); cmd.setSubstitutionMap(substitutions); if (timeLimit != null && !timeLimit.isEmpty()) { cmd.addArgument("-t", false); cmd.addArgument(timeLimit, false); } // add server port argument cmd.addArgument("-p", false); cmd.addArgument(String.valueOf(serverPort), false); cmd.addArgument("${" + CMD_SUBSTITUTION_NAME_FILE + "}", false); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workDir); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(byteArrayOutputStream); executor.setStreamHandler(streamHandler); try { executor.execute(cmd); } catch (ExecuteException e) { throw new SchedulerException( paramSweepCmd + " exited with " + e.getExitValue() + ". Output:\n" + byteArrayOutputStream, e); } catch (IOException e) { throw new SchedulerException( "Execution of " + paramSweepCmd + " failed. Output:\n" + byteArrayOutputStream, e); } // the standard output of the script is the job id final String jobId = byteArrayOutputStream.toString(); return jobId; }
From source file:it.cnr.icar.eric.server.event.EventManager.java
private void onEventInternal(ServerRequestContext context, AuditableEventType ebAuditableEventType) { try {//from w w w .j a v a2s . c o m javax.xml.bind.Marshaller marshaller = BindingUtility.getInstance().getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //marshaller.marshal(ae, System.err); //Get the HashMap where keys are the Subscriptions that match this event //and values are the matchedObjects for that Subscription. HashMap<SubscriptionType, List<IdentifiableType>> subscriptionsMap = subscriptionMatcher .getMatchedSubscriptionsMap(context, ebAuditableEventType); //Process each matching Subscription Iterator<SubscriptionType> subscriptionsIter = subscriptionsMap.keySet().iterator(); while (subscriptionsIter.hasNext()) { SubscriptionType subscription = subscriptionsIter.next(); processSubscription(context, subscription, (subscriptionsMap.get(subscription)), ebAuditableEventType); } } catch (Exception e) { try { context.rollback(); } catch (RegistryException e1) { log.error(e1, e1); } log.error(ServerResourceBundle.getInstance().getString("message.ExceptionCaughtOnEvent"), e); } try { context.commit(); } catch (RegistryException e) { log.error(e, e); } }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String getBedAvailablityHAVE(String hospitalname) { String hospitalstatushave;/* ww w.jav a2s .c om*/ BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname); HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats); try { JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(hospitalStatus, sw); hospitalstatushave = sw.toString(); } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR; } return hospitalstatushave; }
From source file:it.cnr.icar.eric.client.xml.registry.infomodel.IdentifiableImpl.java
public String toXML() throws JAXRException { try {//from w w w . j ava2 s . c om StringWriter sw = new StringWriter(); Marshaller marshaller = BindingUtility.getInstance().getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); JAXBElement<IdentifiableType> ebIdentifiable = bu.rimFac .createIdentifiable((IdentifiableType) toBindingObject()); marshaller.marshal(ebIdentifiable, sw); return sw.toString(); } catch (javax.xml.bind.JAXBException e) { throw new JAXRException(e); } }
From source file:mx.bigdata.sat.cfd.CFDv22.java
public void guardar(OutputStream out) throws Exception { Marshaller m = context.createMarshaller(); m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes)); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.sat.gob.mx/cfd/2 " + "http://www.sat.gob.mx/sitio_internet/cfd/2/cfdv22.xsd"); byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8"); out.write(xmlHeaderBytes);//from ww w .ja va2 s .co m m.marshal(document, out); }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String createBedAvailabilityDE() throws DatatypeConfigurationException { String DEmessageenvelope = ""; String DEmessage = ""; EDXLDistribution ed = EDXLlib.createEDXLEnvelope(); try {//from w ww. j a v a2 s. com JAXBContext jaxbContext = JAXBContext.newInstance(EDXLDistribution.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(ed, sw); DEmessageenvelope = sw.toString(); //could not unescape characters no matter what! //encapsulate the edxl have message into DE by avoiding jaxb //DEmessage = EDXLlib.DEEncapsulation(DEmessageenvelope, edxlhave); DEmessage = DEmessageenvelope; } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR; } return DEmessage; }
From source file:com.floreantpos.bo.actions.DataExportAction.java
@Override public void actionPerformed(ActionEvent e) { Session session = null;//from ww w.jav a 2s . c o m Transaction transaction = null; FileWriter fileWriter = null; GenericDAO dao = new GenericDAO(); try { JFileChooser fileChooser = getFileChooser(); int option = fileChooser.showSaveDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow()); if (option != JFileChooser.APPROVE_OPTION) { return; } File file = fileChooser.getSelectedFile(); if (file.exists()) { option = JOptionPane.showConfirmDialog(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataExportAction.1") + file.getName() + "?", //$NON-NLS-1$//$NON-NLS-2$ Messages.getString("DataExportAction.3"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION); if (option != JOptionPane.YES_OPTION) { return; } } // fixMenuItemModifierGroups(); JAXBContext jaxbContext = JAXBContext.newInstance(Elements.class); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); StringWriter writer = new StringWriter(); session = dao.createNewSession(); transaction = session.beginTransaction(); Elements elements = new Elements(); // * 2. USERS // * 3. TAX // * 4. MENU_CATEGORY // * 5. MENU_GROUP // * 6. MENU_MODIFIER // * 7. MENU_MODIFIER_GROUP // * 8. MENU_ITEM // * 9. MENU_ITEM_SHIFT // * 10. RESTAURANT // * 11. USER_TYPE // * 12. USER_PERMISSION // * 13. SHIFT elements.setTaxes(TaxDAO.getInstance().findAll(session)); elements.setMenuCategories(MenuCategoryDAO.getInstance().findAll(session)); elements.setMenuGroups(MenuGroupDAO.getInstance().findAll(session)); elements.setMenuModifiers(MenuModifierDAO.getInstance().findAll(session)); elements.setMenuModifierGroups(MenuModifierGroupDAO.getInstance().findAll(session)); elements.setMenuItems(MenuItemDAO.getInstance().findAll(session)); elements.setMenuItemModifierGroups(MenuItemModifierGroupDAO.getInstance().findAll(session)); // elements.setUsers(UserDAO.getInstance().findAll(session)); // // elements.setMenuItemShifts(MenuItemShiftDAO.getInstance().findAll(session)); // elements.setRestaurants(RestaurantDAO.getInstance().findAll(session)); // elements.setUserTypes(UserTypeDAO.getInstance().findAll(session)); // elements.setUserPermissions(UserPermissionDAO.getInstance().findAll(session)); // elements.setShifts(ShiftDAO.getInstance().findAll(session)); m.marshal(elements, writer); transaction.commit(); fileWriter = new FileWriter(file); fileWriter.write(writer.toString()); fileWriter.close(); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataExportAction.4")); //$NON-NLS-1$ } catch (Exception e1) { transaction.rollback(); PosLog.error(getClass(), e1); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage()); } finally { IOUtils.closeQuietly(fileWriter); dao.closeSession(session); } }