private void increaseSearchIndexStartTimeDelay() throws Exception { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; OMElement documentElement = getRegistryXmlOmElement(); try { AXIOMXPath xpathExpression = new AXIOMXPath("/wso2registry/indexingConfiguration/startingDelayInSeconds"); OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement); indexConfigNode.setText("2"); AXIOMXPath xpathExpression1 = new AXIOMXPath("/wso2registry/indexingConfiguration/indexingFrequencyInSeconds"); OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement); indexConfigNode1.setText("1"); fileOutputStream = new FileOutputStream(getRegistryXMLPath()); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); documentElement.serialize(writer); documentElement.build(); Thread.sleep(2000); } catch (Exception e) { log.error("registry.xml edit fails" + e.getMessage()); throw new Exception("registry.xml edit fails" + e.getMessage()); } finally { assert fileOutputStream != null; fileOutputStream.close(); assert writer != null; writer.flush(); } }
/** * Set values in OmElement * * @param template Jenkins job configuration template * @param selector Selector of the template * @param value related value from the project * @throws AppFactoryException */ protected void setValueUsingXpath(OMElement template, String selector, String value) throws AppFactoryException { try { AXIOMXPath axiomxPath = new AXIOMXPath(selector); Object selectedObject = axiomxPath.selectSingleNode(template); if (selectedObject != null && selectedObject instanceof OMElement) { OMElement svnRepoPathElement = (OMElement) selectedObject; svnRepoPathElement.setText(value); } else { log.warn("Unable to find xml element matching selector : " + selector); } } catch (Exception e) { String msg = "Error while setting values using Xpath selector:" + selector; log.error(msg, e); throw new AppFactoryException(msg, e); } }
private void sendEvent(Object obj) { if (obj instanceof OMElement) { OMElement eventOMElement = (OMElement) obj; if (eventBuilderConfiguration.isTraceEnabled()) { trace.info("[Event-Builder] Received event as OMElement.\n" + eventOMElement.toString()); } OMNamespace omNamespace = null; if (this.xPathDefinition == null || this.xPathDefinition.isEmpty()) { omNamespace = eventOMElement.getNamespace(); } List<Object> objList = new ArrayList<Object>(); for (XPathData xpathData : attributeXpathList) { AXIOMXPath xpath = xpathData.getXpath(); OMElement omElementResult = null; String type = xpathData.getType(); try { if (omNamespace != null) { xpath.addNamespaces(eventOMElement); } omElementResult = (OMElement) xpath.selectSingleNode(eventOMElement); Class<?> beanClass = Class.forName(type); Object returnedObj = null; if (omElementResult != null) { returnedObj = BeanUtil.deserialize( beanClass, omElementResult, reflectionBasedObjectSupplier, null); } else if (xpathData.getDefaultValue() != null) { if (!beanClass.equals(String.class)) { Class<?> stringClass = String.class; Method valueOfMethod = beanClass.getMethod("valueOf", stringClass); returnedObj = valueOfMethod.invoke(null, xpathData.getDefaultValue()); } else { returnedObj = xpathData.getDefaultValue(); } log.warn("Unable to parse XPath to retrieve required attribute. Sending defaults."); } else { log.warn( "Unable to parse XPath to retrieve required attribute. Skipping to next attribute."); } objList.add(returnedObj); } catch (JaxenException e) { throw new EventBuilderConfigurationException("Error parsing xpath for " + xpath, e); } catch (ClassNotFoundException e) { throw new EventBuilderConfigurationException( "Cannot find specified class for type " + type); } catch (AxisFault axisFault) { throw new EventBuilderConfigurationException( "Error deserializing OMElement " + omElementResult, axisFault); } catch (NoSuchMethodException e) { throw new EventBuilderConfigurationException( "Error trying to convert default value to specified target type.", e); } catch (InvocationTargetException e) { throw new EventBuilderConfigurationException( "Error trying to convert default value to specified target type.", e); } catch (IllegalAccessException e) { throw new EventBuilderConfigurationException( "Error trying to convert default value to specified target type.", e); } } Object[] objArray = objList.toArray(new Object[objList.size()]); if (!this.basicEventListeners.isEmpty()) { if (eventBuilderConfiguration.isTraceEnabled()) { trace.info( "[Event-Builder] Sending event object array " + Arrays.toString(objArray) + " to all registered basic event listeners"); } for (BasicEventListener basicEventListener : basicEventListeners) { basicEventListener.onEvent(objArray); } } if (!this.wso2EventListeners.isEmpty()) { Event event = new Event( exportedStreamDefinition.getStreamId(), System.currentTimeMillis(), null, null, objArray); if (eventBuilderConfiguration.isTraceEnabled()) { trace.info( "[Event-Builder] Sending event " + event.toString() + " to all registered wso2 event listeners"); } for (Wso2EventListener wso2EventListener : wso2EventListeners) { wso2EventListener.onEvent(event); } } } }