List of usage examples for javax.xml.stream XMLStreamException toString
public String toString()
From source file:com.cloud.bridge.service.controller.s3.S3ObjectAction.java
private void executeGetObjectAcl(HttpServletRequest request, HttpServletResponse response) throws IOException { String bucketName = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY); String key = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY); S3GetObjectAccessControlPolicyRequest engineRequest = new S3GetObjectAccessControlPolicyRequest(); engineRequest.setBucketName(bucketName); engineRequest.setKey(key);//from w w w. ja v a 2 s. c o m S3AccessControlPolicy engineResponse = ServiceProvider.getInstance().getS3Engine() .handleRequest(engineRequest); // -> serialize using the apache's Axiom classes GetObjectAccessControlPolicyResponse onePolicy = S3SoapServiceImpl .toGetObjectAccessControlPolicyResponse(engineResponse); try { OutputStream os = response.getOutputStream(); response.setStatus(200); response.setContentType("text/xml; charset=UTF-8"); XMLStreamWriter xmlWriter = xmlOutFactory.createXMLStreamWriter(os); String documentStart = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); os.write(documentStart.getBytes()); MTOMAwareXMLSerializer MTOMWriter = new MTOMAwareXMLSerializer(xmlWriter); onePolicy.serialize(new QName("http://s3.amazonaws.com/doc/2006-03-01/", "GetObjectAccessControlPolicyResponse", "ns1"), factory, MTOMWriter); xmlWriter.flush(); xmlWriter.close(); os.close(); } catch (XMLStreamException e) { throw new IOException(e.toString()); } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serialize(ADBBean[] beanArray, QName qname, XMLStreamWriter writer) { for (ADBBean bean : beanArray) { try {/* w w w . j a va 2s . co m*/ bean.serialize(qname, writer); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeExchanges(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {//from w ww . ja va 2 s . c o m writer.writeStartElement(XML_NAMESPACE_URI, EXCHANGES_LOCALNAME); writer.writeCharacters(NEWLINE); serialize(eodDataProvider.getExchanges(), EXCHANGE_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeSymbols(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {/*from w w w.ja v a 2 s. c o m*/ writer.writeStartElement(XML_NAMESPACE_URI, SYMBOLS_LOCALNAME); writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE); writer.writeCharacters(NEWLINE); serialize(eodDataProvider.getSymbols(TEST_EXCHANGE), SYMBOL_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
private static void serializeQuotes(EodDataProvider eodDataProvider, XMLStreamWriter writer) { try {/*from w w w . jav a2s . c o m*/ writer.writeStartElement(XML_NAMESPACE_URI, QUOTES_LOCALNAME); writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE); writer.writeAttribute(XML_NAMESPACE_URI, TESTSYMBOL_ATTRNAME, TEST_SYMBOL); writer.writeCharacters(NEWLINE); Calendar startCalendar = Calendar.getInstance(); startCalendar.add(Calendar.YEAR, HISTORY_YEAR_OFFSET); // startCalendar.add(Calendar.MONTH, HISTORY_MONTH_OFFSET); Calendar endCalendar = Calendar.getInstance(); serialize(eodDataProvider.getQuotes(TEST_EXCHANGE, TEST_SYMBOL, startCalendar, endCalendar, DEFAULT_FREQUENCY), QUOTE_QNAME, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); } catch (XMLStreamException xse) { logger.error(xse.toString()); logger.error(xse); } catch (EodDataProviderException edpe) { logger.error(edpe.toString()); logger.error(edpe); } finally { if (eodDataProvider != null) { // eodDataProvider.close(); } } }
From source file:org.wso2.carbon.governance.registry.extensions.aspects.ChecklistLifeCycle.java
public void associate(Resource resource, Registry registry) throws RegistryException { try {/* w w w . ja va2 s .c o m*/ String xmlContent = ""; if (isConfigurationFromResource) { /* expected format of the content in the resource <lifecycle> <state name="Created"> <checkitem>Testing option 1</checkitem> <checkitem>Testing option 2</checkitem> <checkitem>Testing option 3</checkitem> <checkitem>Testing option 4</checkitem> </state> <state name="Tested"> <checkitem>Deploying option 1</checkitem> <checkitem>Deploying option 2</checkitem> <checkitem>Deploying option 3</checkitem> <checkitem>Deploying option 4</checkitem> <checkitem>Deploying option 5</checkitem> </state> <state name="Deployed"> <checkitem>Deprecating option 1</checkitem> <checkitem>Deprecating option 2</checkitem> <checkitem>Deprecating option 3</checkitem> </state> <state name="Deprecated"> </state> </lifecycle> */ Resource configurationResource = registry.get(configurationResourcePath); xmlContent = RegistryUtils.decodeBytes((byte[]) configurationResource.getContent()); configurationElement = AXIOMUtil.stringToOM(xmlContent); } else { /* expected format in registry.xml *** opening aspect tag *** <configuration type="literal"> <lifecycle> <state name="Created"> <checkitem>Testing option 1</checkitem> <checkitem>Testing option 2</checkitem> <checkitem>Testing option 3</checkitem> <checkitem>Testing option 4</checkitem> </state> <state name="Tested"> <checkitem>Deploying option 1</checkitem> <checkitem>Deploying option 2</checkitem> <checkitem>Deploying option 3</checkitem> <checkitem>Deploying option 4</checkitem> <checkitem>Deploying option 5</checkitem> </state> <state name="Deployed"> <checkitem>Deprecating option 1</checkitem> <checkitem>Deprecating option 2</checkitem> <checkitem>Deprecating option 3</checkitem> </state> <state name="Deprecated"> </state> </lifecycle> </configuration> *** closing aspect tag *** */ // configuration element is populated inside the constructor } Iterator stateElements = configurationElement.getChildElements(); int propertyOrder = 0; boolean addStates = (states.size() == 0); while (stateElements.hasNext()) { OMElement stateEl = (OMElement) stateElements.next(); String name = stateEl.getAttributeValue(new QName("name")); if (name == null) { throw new IllegalArgumentException("Must have a name attribute for each state"); } if (addStates) { states.add(name); } Iterator checkListIterator = stateEl.getChildElements(); int checklistItemOrder = 0; while (checkListIterator.hasNext()) { OMElement itemEl = (OMElement) checkListIterator.next(); if (itemEl.getQName().equals(new QName("checkitem"))) { List<String> items = new ArrayList<String>(); String itemName = itemEl.getText(); if (itemName == null) throw new RegistryException("Checklist items should have a name!"); items.add("status:" + name); items.add("name:" + itemName); items.add("value:false"); if (itemEl.getAttribute(new QName("order")) != null) { items.add("order:" + itemEl.getAttributeValue(new QName("order"))); } else { items.add("order:" + checklistItemOrder); } String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.option" + propertyOrder + ".item"; resource.setProperty(resourcePropertyNameForItem, items); checklistItemOrder++; propertyOrder++; } else if (itemEl.getQName().equals(new QName("js"))) { Iterator scriptElementIterator = itemEl.getChildElements(); while (scriptElementIterator.hasNext()) { OMElement scriptItemEl = (OMElement) scriptElementIterator.next(); if (scriptItemEl.getQName().equals(new QName("console"))) { StringBuffer lifecycleScript = new StringBuffer(); String lifecycleScriptCommand = ""; Iterator consoleScriptElementIterator = scriptItemEl.getChildElements(); while (consoleScriptElementIterator.hasNext()) { OMElement consoleScriptItemEl = (OMElement) consoleScriptElementIterator.next(); if (consoleScriptItemEl.getQName().equals(new QName("script"))) { lifecycleScript.append(consoleScriptItemEl.toString()).append("\n"); } } if (scriptItemEl.getAttribute(new QName("demoteFunction")) != null) { lifecycleScriptCommand = scriptItemEl .getAttributeValue(new QName("demoteFunction")); List<String> items = new ArrayList<String>(); items.add(lifecycleScript.toString()); items.add(lifecycleScriptCommand); String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.js.script.console." + name + "." + DEMOTE; resource.setProperty(resourcePropertyNameForItem, items); } if (scriptItemEl.getAttribute(new QName("promoteFunction")) != null) { lifecycleScriptCommand = scriptItemEl .getAttributeValue(new QName("promoteFunction")); List<String> items = new ArrayList<String>(); items.add(lifecycleScript.toString()); items.add(lifecycleScriptCommand); String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.js.script.console." + name + "." + PROMOTE; resource.setProperty(resourcePropertyNameForItem, items); } } else if (scriptItemEl.getQName().equals(new QName("server"))) { String lifecycleScript = ""; String lifecycleScriptCommand = ""; Iterator serverScriptElementIterator = scriptItemEl.getChildElements(); if (serverScriptElementIterator.hasNext()) { OMElement serverScriptItemEl = (OMElement) serverScriptElementIterator.next(); if (serverScriptItemEl.getQName().equals(new QName("script"))) { lifecycleScript += serverScriptItemEl.toString(); lifecycleScript = lifecycleScript.trim(); } } if (scriptItemEl.getAttribute(new QName("demoteFunction")) != null) { lifecycleScriptCommand = scriptItemEl .getAttributeValue(new QName("demoteFunction")); List<String> items = new ArrayList<String>(); items.add(lifecycleScript); items.add(lifecycleScriptCommand); String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.js.script.server." + name + "." + DEMOTE; resource.setProperty(resourcePropertyNameForItem, items); } if (scriptItemEl.getAttribute(new QName("promoteFunction")) != null) { lifecycleScriptCommand = scriptItemEl .getAttributeValue(new QName("promoteFunction")); List<String> items = new ArrayList<String>(); items.add(lifecycleScript); items.add(lifecycleScriptCommand); String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.js.script.server." + name + "." + PROMOTE; resource.setProperty(resourcePropertyNameForItem, items); } } } } } } } catch (XMLStreamException e) { throw new RegistryException("Resource does not contain valid XML configuration: " + e.toString()); } resource.setProperty(stateProperty, states.get(0)); resource.setProperty(lifecycleProperty, aspectName); }