public static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean) { OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement handler = factory.createOMElement("handler", null); handler.addAttribute(factory.createOMAttribute("class", null, bean.getHandlerClass())); if (bean.getTenant() != null) { handler.addAttribute(factory.createOMAttribute("tenant", null, bean.getTenant())); } StringBuilder sb = new StringBuilder(); for (String method : bean.getMethods()) { if (method != null && method.length() > 0) { sb.append(method).append(","); } } // Remove last "," if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); handler.addAttribute(factory.createOMAttribute("methods", null, sb.toString())); } for (String property : bean.getPropertyList()) { OMElement temp = factory.createOMElement("property", null); temp.addAttribute(factory.createOMAttribute("name", null, property)); OMElement xmlProperty = bean.getXmlProperties().get(property); if (xmlProperty != null) { // The serialization happens by adding the whole XML property value to the // bean. // Therefore if it is a XML property, we take that whole element. handler.addChild(xmlProperty); } else { String nonXMLProperty = bean.getNonXmlProperties().get(property); if (nonXMLProperty != null) { temp.setText(nonXMLProperty); handler.addChild(temp); } } } OMElement filter = factory.createOMElement("filter", null); filter.addAttribute( factory.createOMAttribute("class", null, bean.getFilter().getFilterClass())); for (String property : bean.getFilter().getPropertyList()) { OMElement temp = factory.createOMElement("property", null); temp.addAttribute(factory.createOMAttribute("name", null, property)); OMElement xmlProperty = bean.getFilter().getXmlProperties().get(property); if (xmlProperty != null) { temp.addAttribute(factory.createOMAttribute("type", null, "xml")); temp.addChild(xmlProperty); filter.addChild(temp); } else { String nonXMLProperty = bean.getFilter().getNonXmlProperties().get(property); if (nonXMLProperty != null) { temp.setText(nonXMLProperty); filter.addChild(temp); } } } handler.addChild(filter); return handler; }
public OMElement serialize(OMFactory fac) { if (log.isDebugEnabled() || log.isTraceEnabled()) { log.debug("Serialize command"); } /* * org.apache.axiom.om.OMNamespace nullNS = fac.createOMNamespace( * XMLConfigConstants.NULL_NAMESPACE, ""); */ ValueSerializer valueSerializer = new ValueSerializer(); OMElement root = AuditMediatorUtils.createTag(fac, this.type); for (Iterator iterator = params.iterator(); iterator.hasNext(); ) { Param param = (Param) iterator.next(); OMElement paramTag = AuditMediatorUtils.createTag(fac, AuditMediatorUtils.PARAM_TAG_NAME); root.addChild(paramTag); paramTag.addAttribute( fac.createOMAttribute( AuditMediatorUtils.NAME_ATT_NAME, AuditMediatorUtils.nullNS, param.getName())); valueSerializer.serializeValue(param.getValue(), AuditMediatorUtils.VALUE_ATT_NAME, paramTag); } return root; }
private static void addPropertyElements( OMFactory factory, OMElement parent, String className, String description, Map<String, String> properties) { if (className != null) { parent.addAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_CLASS, className, null); } if (description != null) { parent.addAttribute(UserCoreConstants.RealmConfig.CLASS_DESCRIPTION, description, null); } Iterator<Map.Entry<String, String>> ite = properties.entrySet().iterator(); while (ite.hasNext()) { Map.Entry<String, String> entry = ite.next(); String name = entry.getKey(); String value = entry.getValue(); OMElement propElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY)); OMAttribute propAttr = factory.createOMAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, name); propElem.addAttribute(propAttr); propElem.setText(value); parent.addChild(propElem); } }
/** * Serialize the Value object to an OMElement representing the entry * * @param key Value to serialize * @param elem OMElement * @return OMElement */ public OMElement serializeValue(Value key, String name, OMElement elem) { if (key != null) { if (key.getExpression() == null) { // static key elem.addAttribute(fac.createOMAttribute(name, nullNS, key.getKeyValue())); } else { String startChar = "{", endChar = "}"; // if this is an expr type key we add an additional opening and closing brace if (key.hasExprTypeKey()) { startChar = startChar + "{"; endChar = endChar + "}"; } // dynamic key SynapsePathSerializer.serializePath( key.getExpression(), startChar + key.getExpression().toString() + endChar, elem, name); } } return elem; }
private static OMElement getEchoOMBlock(String text, String sequenceKey) { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace applicationNamespace = fac.createOMNamespace(applicationNamespaceName, "ns1"); OMElement echoStringElement = fac.createOMElement(echoString, applicationNamespace); OMElement textElem = fac.createOMElement(Text, applicationNamespace); OMElement sequenceElem = fac.createOMElement(Sequence, applicationNamespace); textElem.setText(text); sequenceElem.setText(sequenceKey); echoStringElement.addChild(textElem); echoStringElement.addChild(sequenceElem); OMNamespace namespace = fac.createOMNamespace(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, "env"); OMAttribute attr = fac.createOMAttribute( "encodingStyle", namespace, "http://schemas.xmlsoap.org/soap/encoding/"); echoStringElement.addAttribute(attr); return echoStringElement; }
public static NfeCabecMsg parse(final javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception { final NfeCabecMsg object = new NfeCabecMsg(); java.lang.String nillableValue = null; try { while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type") != null) { final java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type"); if (fullTypeName != null) { java.lang.String nsPrefix = null; if (fullTypeName.contains(":")) { nsPrefix = fullTypeName.substring(0, fullTypeName.indexOf(":")); } nsPrefix = nsPrefix == null ? "" : nsPrefix; final java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":") + 1); if (!"nfeCabecMsg".equals(type)) { // find namespace for the prefix final java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix); return (NfeCabecMsg) ExtensionMapper.getTypeObject(nsUri, type, reader); } } } // Note all attributes that were handled. Used to differ normal attributes // from anyAttributes. final java.util.Vector<String> handledAttributes = new java.util.Vector<>(); // now run through all any or extra attributes // which were not reflected until now for (int i = 0; i < reader.getAttributeCount(); i++) { if (!handledAttributes.contains(reader.getAttributeLocalName(i))) { // this is an anyAttribute and we create // an OMAttribute for this final org.apache.axiom.om.OMFactory factory = org.apache.axiom.om.OMAbstractFactory.getOMFactory(); final org.apache.axiom.om.OMAttribute attr = factory.createOMAttribute( reader.getAttributeLocalName(i), factory.createOMNamespace( reader.getAttributeNamespace(i), reader.getAttributePrefix(i)), reader.getAttributeValue(i)); // and add it to the extra attributes object.addExtraAttributes(attr); } } reader.next(); while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } if (reader.isStartElement() && new javax.xml.namespace.QName( "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2", "versaoDados") .equals(reader.getName())) { nillableValue = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "nil"); if ("true".equals(nillableValue) || "1".equals(nillableValue)) { throw new org.apache.axis2.databinding.ADBException( "The element: " + "versaoDados" + " cannot be null"); } final java.lang.String content = reader.getElementText(); object.setVersaoDados( org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content)); reader.next(); } // End of if for expected property start element else { } while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } if (reader.isStartElement() && new javax.xml.namespace.QName( "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2", "cUF") .equals(reader.getName())) { nillableValue = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "nil"); if ("true".equals(nillableValue) || "1".equals(nillableValue)) { throw new org.apache.axis2.databinding.ADBException( "The element: " + "cUF" + " cannot be null"); } final java.lang.String content = reader.getElementText(); object.setCUF( org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content)); reader.next(); } // End of if for expected property start element else { } while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } if (reader.isStartElement()) { // A start element we are not expecting indicates a trailing invalid property throw new org.apache.axis2.databinding.ADBException( "Unexpected subelement " + reader.getName()); } } catch (final javax.xml.stream.XMLStreamException e) { throw new java.lang.Exception(e); } return object; }
// TODO get a factory or a stream writer - add more props public static OMElement serialize(RealmConfiguration realmConfig) { OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement rootElement = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_MANAGER)); OMElement realmElement = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_REALM)); String realmName = realmConfig.getRealmClassName(); OMAttribute propAttr = factory.createOMAttribute( UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, realmName); realmElement.addAttribute(propAttr); rootElement.addChild(realmElement); OMElement mainConfig = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_CONFIGURATION)); realmElement.addChild(mainConfig); OMElement addAdmin = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADD_ADMIN)); OMElement adminUser = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADMIN_USER)); OMElement adminUserNameElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_NAME)); adminUserNameElem.setText(realmConfig.getAdminUserName()); OMElement adminPasswordElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PASSWORD)); addAdmin.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAddAdmin())); adminPasswordElem.setText(realmConfig.getAdminPassword()); adminUser.addChild(adminUserNameElem); adminUser.addChild(adminPasswordElem); mainConfig.addChild(addAdmin); mainConfig.addChild(adminUser); OMElement adminRoleNameElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADMIN_ROLE)); adminRoleNameElem.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAdminRoleName())); mainConfig.addChild(adminRoleNameElem); OMElement systemUserNameElem = factory.createOMElement( new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_SYSTEM_USER_NAME)); mainConfig.addChild(systemUserNameElem); // adding the anonymous user OMElement anonymousUserEle = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ANONYMOUS_USER)); OMElement anonymousUserNameElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_NAME)); OMElement anonymousPasswordElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PASSWORD)); anonymousUserEle.addChild(anonymousUserNameElem); anonymousUserEle.addChild(anonymousPasswordElem); mainConfig.addChild(anonymousUserEle); // adding the everyone role OMElement everyoneRoleNameElem = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_EVERYONE_ROLE)); everyoneRoleNameElem.setText( UserCoreUtil.removeDomainFromName(realmConfig.getEveryOneRoleName())); mainConfig.addChild(everyoneRoleNameElem); // add the main config properties addPropertyElements( factory, mainConfig, null, realmConfig.getDescription(), realmConfig.getRealmProperties()); // add the user store manager properties OMElement userStoreManagerElement = factory.createOMElement( new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER)); realmElement.addChild(userStoreManagerElement); addPropertyElements( factory, userStoreManagerElement, realmConfig.getUserStoreClass(), realmConfig.getDescription(), realmConfig.getUserStoreProperties()); RealmConfiguration secondaryRealmConfiguration = null; secondaryRealmConfiguration = realmConfig.getSecondaryRealmConfig(); while (secondaryRealmConfiguration != null) { OMElement secondaryElement = factory.createOMElement( new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER)); realmElement.addChild(secondaryElement); addPropertyElements( factory, secondaryElement, secondaryRealmConfiguration.getUserStoreClass(), secondaryRealmConfiguration.getDescription(), secondaryRealmConfiguration.getUserStoreProperties()); secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig(); } // add the user authorization properties OMElement authorizerManagerElement = factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ATHZ_MANAGER)); realmElement.addChild(authorizerManagerElement); addPropertyElements( factory, authorizerManagerElement, realmConfig.getAuthorizationManagerClass(), realmConfig.getDescription(), realmConfig.getAuthzProperties()); return rootElement; }
public void toHeader(SOAPHeader header) throws SandeshaException { SOAPHeaderBlock sequenceAcknowledgementHeaderBlock = header.addHeaderBlock(Sandesha2Constants.WSRM_COMMON.SEQUENCE_ACK, omNamespace); if (identifier == null) throw new OMException( SandeshaMessageHelper.getMessage( SandeshaMessageKeys.invalidIdentifier, header.toString())); // SequenceACK messages should always have the MustUnderstand flag set to true // Unless it is a piggybacked ack if (piggybacked) { sequenceAcknowledgementHeaderBlock.setMustUnderstand(false); } else { sequenceAcknowledgementHeaderBlock.setMustUnderstand(true); } identifier.toOMElement(sequenceAcknowledgementHeaderBlock, omNamespace); Iterator<Range> ackRangeIt = acknowledgementRangeList.iterator(); while (ackRangeIt.hasNext()) { Range ackRange = (Range) ackRangeIt.next(); if (ackRange.upperValue <= 0 || ackRange.lowerValue <= 0 || ackRange.lowerValue > ackRange.upperValue) throw new OMException( SandeshaMessageHelper.getMessage( SandeshaMessageKeys.ackRandDoesNotHaveCorrectValues, ackRange.upperValue + ":" + ackRange.lowerValue)); OMFactory factory = sequenceAcknowledgementHeaderBlock.getOMFactory(); OMAttribute lowerAttrib = factory.createOMAttribute( Sandesha2Constants.WSRM_COMMON.LOWER, null, Long.toString(ackRange.lowerValue)); OMAttribute upperAttrib = factory.createOMAttribute( Sandesha2Constants.WSRM_COMMON.UPPER, null, Long.toString(ackRange.upperValue)); OMElement acknowledgementRangeElement = factory.createOMElement(Sandesha2Constants.WSRM_COMMON.ACK_RANGE, omNamespace); acknowledgementRangeElement.addAttribute(lowerAttrib); acknowledgementRangeElement.addAttribute(upperAttrib); sequenceAcknowledgementHeaderBlock.addChild(acknowledgementRangeElement); } Iterator<Long> nackIt = nackList.iterator(); while (nackIt.hasNext()) { Long nack = (Long) nackIt.next(); if (nack.longValue() <= 0) throw new OMException( SandeshaMessageHelper.getMessage(SandeshaMessageKeys.nackDoesNotContainValidLongValue)); OMElement nackElement = sequenceAcknowledgementHeaderBlock .getOMFactory() .createOMElement(Sandesha2Constants.WSRM_COMMON.NACK, omNamespace); nackElement.setText(nack.toString()); sequenceAcknowledgementHeaderBlock.addChild(nackElement); } String rmSpecVersion = SpecSpecificConstants.getSpecVersionString(namespaceValue); // setting a 'None' when nothing is there (for the correct RM version) if (ackNone == false && acknowledgementRangeList.size() == 0 && nackList.size() == 0 && SpecSpecificConstants.isAckNoneAllowed(rmSpecVersion)) { ackNone = true; } if (ackNone != false) { if (!SpecSpecificConstants.isAckNoneAllowed(rmSpecVersion)) { throw new SandeshaException( SandeshaMessageHelper.getMessage( SandeshaMessageKeys.noneNotAllowedNamespace, rmSpecVersion)); } if (acknowledgementRangeList.size() > 0) { throw new SandeshaException( SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noneNotAllowedAckRangesPresent)); } if (nackList.size() > 0) { throw new SandeshaException( SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noneNotAllowedNackPresent)); } OMElement noneElement = sequenceAcknowledgementHeaderBlock .getOMFactory() .createOMElement(Sandesha2Constants.WSRM_COMMON.NONE, omNamespace); sequenceAcknowledgementHeaderBlock.addChild(noneElement); } if (ackFinal != false) { if (!SpecSpecificConstants.isAckFinalAllowed(rmSpecVersion)) { throw new SandeshaException( SandeshaMessageHelper.getMessage(SandeshaMessageKeys.finalNotAllowedNamespace)); } if (nackList.size() > 0) { throw new SandeshaException( SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotHaveFinalWithNack)); } OMElement finalElement = sequenceAcknowledgementHeaderBlock .getOMFactory() .createOMElement(Sandesha2Constants.WSRM_COMMON.FINAL, omNamespace); sequenceAcknowledgementHeaderBlock.addChild(finalElement); } }