List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaLoader.java
private void addImportsFromDefinition(Definition definition) throws OpenEJBException { Types types = definition.getTypes(); if (types != null) { for (Object extensibilityElement : types.getExtensibilityElements()) { if (extensibilityElement instanceof Schema) { Schema unknownExtensibilityElement = (Schema) extensibilityElement; QName elementType = unknownExtensibilityElement.getElementType(); if (new QName("http://www.w3.org/2001/XMLSchema", "schema").equals(elementType)) { Element element = unknownExtensibilityElement.getElement(); xmlSchemaCollection.read(element); }// w ww.j av a 2s . c o m } else if (extensibilityElement instanceof UnknownExtensibilityElement) { //This is allegedly obsolete as of axis-wsdl4j-1.2-RC3.jar which includes the Schema extension above. //The change notes imply that imported schemas should end up in Schema elements. They don't, so this is still needed. UnknownExtensibilityElement unknownExtensibilityElement = (UnknownExtensibilityElement) extensibilityElement; Element element = unknownExtensibilityElement.getElement(); String elementNamespace = element.getNamespaceURI(); String elementLocalName = element.getNodeName(); if ("http://www.w3.org/2001/XMLSchema".equals(elementNamespace) && "schema".equals(elementLocalName)) { xmlSchemaCollection.read(element); } } } } //noinspection unchecked Map<String, List<Import>> imports = definition.getImports(); if (imports != null) { for (Map.Entry<String, List<Import>> entry : imports.entrySet()) { String namespaceURI = entry.getKey(); List<Import> importList = entry.getValue(); for (Import anImport : importList) { //according to the 1.1 jwsdl mr shcema imports are supposed to show up here, //but according to the 1.0 spec there is supposed to be no Definition. Definition importedDef = anImport.getDefinition(); if (importedDef != null) { addImportsFromDefinition(importedDef); } else { log.warn("Missing definition in import for namespace " + namespaceURI); } } } } }
From source file:org.apache.rampart.PolicyBasedResultsValidator.java
protected void validateSignedPartsHeaders(ValidatorData data, Vector signatureParts, Vector results) throws RampartException { RampartMessageData rmd = data.getRampartMessageData(); Node envelope = rmd.getDocument().getFirstChild(); WSSecurityEngineResult[] actionResults = fetchActionResults(results, WSConstants.SIGN); // Find elements that are signed Vector actuallySigned = new Vector(); if (actionResults != null) { for (int j = 0; j < actionResults.length; j++) { WSSecurityEngineResult actionResult = actionResults[j]; List wsDataRefs = (List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS); // if header was encrypted before it was signed, protected // element is 'EncryptedHeader.' the actual element is // first child element for (Iterator k = wsDataRefs.iterator(); k.hasNext();) { WSDataRef wsDataRef = (WSDataRef) k.next(); Element protectedElement = wsDataRef.getProtectedElement(); if (protectedElement.getLocalName().equals("EncryptedHeader")) { NodeList nodeList = protectedElement.getChildNodes(); for (int x = 0; x < nodeList.getLength(); x++) { if (nodeList.item(x).getNodeType() == Node.ELEMENT_NODE) { String ns = ((Element) nodeList.item(x)).getNamespaceURI(); String ln = ((Element) nodeList.item(x)).getLocalName(); actuallySigned.add(new QName(ns, ln)); break; }//from w ww. j a v a2 s . c o m } } else { String ns = protectedElement.getNamespaceURI(); String ln = protectedElement.getLocalName(); actuallySigned.add(new QName(ns, ln)); } } } } for (int i = 0; i < signatureParts.size(); i++) { WSEncryptionPart wsep = (WSEncryptionPart) signatureParts.get(i); if (wsep.getType() == WSConstants.PART_TYPE_BODY) { QName bodyQName; if (WSConstants.URI_SOAP11_ENV.equals(envelope.getNamespaceURI())) { bodyQName = new SOAP11Constants().getBodyQName(); } else { bodyQName = new SOAP12Constants().getBodyQName(); } if (!actuallySigned.contains(bodyQName) && !rmd.getPolicyData().isSignBodyOptional()) { // soap body is not signed throw new RampartException("bodyNotSigned"); } } else if (wsep.getType() == WSConstants.PART_TYPE_HEADER || wsep.getType() == WSConstants.PART_TYPE_ELEMENT) { Element element = (Element) WSSecurityUtil.findElement(envelope, wsep.getName(), wsep.getNamespace()); if (element == null) { // The signedpart header or element we are checking is not present in // soap envelope - this is allowed continue; } // header or the element present in soap envelope - verify that it is part of // signature if (actuallySigned.contains(new QName(element.getNamespaceURI(), element.getLocalName()))) { continue; } String msg = wsep.getType() == WSConstants.PART_TYPE_HEADER ? "signedPartHeaderNotSigned" : "signedElementNotSigned"; // header or the element defined in policy is present but not signed throw new RampartException(msg, new String[] { wsep.getNamespace() + ":" + wsep.getName() }); } } }
From source file:org.apache.rave.portal.service.impl.DefaultOmdlService.java
private void parseOmdlFile(Document xml, OmdlInputAdapter omdlInputAdapter) throws BadOmdlXmlFormatException { Element rootEl = xml.getDocumentElement(); String rootNodename = rootEl.getNodeName(); String namespace = rootEl.getNamespaceURI(); if (rootNodename != WORKSPACE) { throw new BadOmdlXmlFormatException("Root node must be <" + WORKSPACE + ">"); }//w ww. j a v a 2 s . c o m // TODO - which is it - spec examples show both? if (namespace != NAMESPACE && namespace != NAMESPACE + "/") { throw new BadOmdlXmlFormatException("Default xml namespace must be " + NAMESPACE); } //child <identifier> - omit //child <goal> - omit //child <status> - omit //child <description> - omit //child <creator> - omit //child <date> - omit // Try to get the page name (title in omdl) String title = null; NodeList nodeList = rootEl.getElementsByTagNameNS(namespace, TITLE); if (nodeList.getLength() > 0) { Node node = rootEl.getElementsByTagNameNS(namespace, TITLE).item(0); if (node.getTextContent() != null) { title = node.getTextContent(); } } // store this if found, although at present it will be overwritten by the users page name omdlInputAdapter.setName(title); String layoutCode = null; // Try to get the layoutCode nodeList = rootEl.getElementsByTagNameNS(namespace, LAYOUT); if (nodeList.getLength() > 0) { Node node = rootEl.getElementsByTagNameNS(namespace, LAYOUT).item(0); if (node.getTextContent() != null) { layoutCode = node.getTextContent(); } } // Next try to find all the <app> elements (widgets) nodeList = rootEl.getElementsByTagNameNS(namespace, APP); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Element appElement = (Element) nodeList.item(i); String id = appElement.getAttribute(ID_ATTRIBUTE); if (id != null) { String position = null; String hrefLink = null; String hrefType = null; Node positionNode = appElement.getElementsByTagNameNS(namespace, POSITION).item(0); if (positionNode != null) { Element positionElement = (Element) positionNode; position = positionElement.getTextContent(); } Node linkNode = appElement.getElementsByTagNameNS(namespace, LINK).item(0); if (linkNode != null) { Element linkElement = (Element) linkNode; hrefLink = linkElement.getAttribute(HREF); hrefType = linkElement.getAttribute(TYPE_ATTRIBUTE); } omdlInputAdapter.addToAppMap(new OmdlWidgetReference(id, hrefLink, hrefType), position); } } } // store the string found in the xml file omdlInputAdapter.setLayoutCode(layoutCode); // update this string into a RAVE layout omdlInputAdapter.setLayoutCode(OmdlModelUtils.getRaveLayoutForImport(omdlInputAdapter)); }
From source file:org.apache.servicemix.http.HttpURITest.java
public void testResolveEndpoint() throws Exception { HttpComponent http = new HttpComponent(); HttpEndpoint ep = new HttpEndpoint(); ep.setRole(MessageExchange.Role.CONSUMER); ep.setService(ReceiverComponent.SERVICE); ep.setEndpoint(ReceiverComponent.ENDPOINT); ep.setLocationURI("http://localhost:8192/"); ep.setDefaultMep(MessageExchangeSupport.IN_ONLY); http.setEndpoints(new HttpEndpoint[] { ep }); jbi.activateComponent(http, "servicemix-http"); ReceiverComponent receiver = new ReceiverComponent(); jbi.activateComponent(receiver, "receiver"); DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); DocumentFragment epr = URIResolver.createWSAEPR("http://localhost:8192/?http.soap=true"); ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); assertNotNull(se);/*from ww w .ja v a 2 s.c om*/ InOnly inonly = client.createInOnlyExchange(); inonly.setEndpoint(se); inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); client.sendSync(inonly); assertEquals(ExchangeStatus.DONE, inonly.getStatus()); receiver.getMessageList().assertMessagesReceived(1); List msgs = receiver.getMessageList().flushMessages(); NormalizedMessage msg = (NormalizedMessage) msgs.get(0); Element elem = new SourceTransformer().toDOMElement(msg); assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); assertEquals("env:Envelope", elem.getNodeName()); logger.info(new SourceTransformer().contentToString(msg)); }
From source file:org.apache.servicemix.jbi.runtime.impl.AbstractComponentContext.java
/** * <p>//from ww w.j a v a 2 s . c om * Resolve an internal JBI EPR conforming to the format defined in the JBI specification. * </p> * * <p>The EPR would look like: * <pre> * <jbi:end-point-reference xmlns:jbi="http://java.sun.com/xml/ns/jbi/end-point-reference" * jbi:end-point-name="endpointName" * jbi:service-name="foo:serviceName" * xmlns:foo="urn:FooNamespace"/> * </pre> * </p> * * @author Maciej Szefler m s z e f l e r @ g m a i l . c o m * @param epr EPR fragment * @return internal service endpoint corresponding to the EPR, or <code>null</code> * if the EPR is not an internal EPR or if the EPR cannot be resolved */ public ServiceEndpoint resolveInternalEPR(DocumentFragment epr) { if (epr == null) { throw new NullPointerException("resolveInternalEPR(epr) called with null epr."); } NodeList nl = epr.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) { Node n = nl.item(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } Element el = (Element) n; // Namespace should be "http://java.sun.com/jbi/end-point-reference" if (el.getNamespaceURI() == null || !el.getNamespaceURI().equals(ServiceEndpointImpl.JBI_NAMESPACE)) { continue; } if (el.getLocalName() == null || !el.getLocalName().equals(ServiceEndpointImpl.JBI_ENDPOINT_REFERENCE)) { continue; } String serviceName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_SERVICE_NAME); // Now the DOM pain-in-the-you-know-what: we need to come up with QName for this; // fortunately, there is only one place where the xmlns:xxx attribute could be, on // the end-point-reference element! QName serviceQName = DOMUtil.createQName(el, serviceName); String endpointName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_ENDPOINT_NAME); return getEndpoint(serviceQName, endpointName); } return null; }
From source file:org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil.java
/** * Build a QName from the element name// w ww . j a va2 s.c o m * @param el * @return */ public static QName getQName(Element el) { if (el == null) { return null; } else if (el.getNamespaceURI() == null) { return new QName(el.getNodeName()); } else if (el.getPrefix() != null) { return new QName(el.getNamespaceURI(), el.getLocalName(), el.getPrefix()); } else { return new QName(el.getNamespaceURI(), el.getLocalName()); } }
From source file:org.apache.servicemix.jms.JmsURITest.java
public void testResolveEndpoint() throws Exception { JmsComponent jms = new JmsComponent(); jms.getConfiguration().setConnectionFactory(connectionFactory); JmsEndpoint ep = new JmsEndpoint(); ep.setRole(MessageExchange.Role.CONSUMER); ep.setService(ReceiverComponent.SERVICE); ep.setEndpoint(ReceiverComponent.ENDPOINT); ep.setDefaultMep(JbiConstants.IN_ONLY); ep.setJmsProviderDestinationName("foo.bar.myqueue"); ep.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); ep.setServiceUnit(new DefaultServiceUnit(jms)); jms.setEndpoints(new JmsEndpoint[] { ep }); container.activateComponent(jms, "servicemix-jms"); ReceiverComponent receiver = new ReceiverComponent(); container.activateComponent(receiver, "receiver"); DefaultServiceMixClient client = new DefaultServiceMixClient(container); DocumentFragment epr = URIResolver.createWSAEPR("jms://queue/foo.bar.myqueue?jms.soap=true"); ServiceEndpoint se = client.getContext().resolveEndpointReference(epr); assertNotNull(se);//from w w w .j ava 2s . co m InOnly inonly = client.createInOnlyExchange(); inonly.setEndpoint(se); inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); client.sendSync(inonly); assertEquals(ExchangeStatus.DONE, inonly.getStatus()); receiver.getMessageList().assertMessagesReceived(1); List msgs = receiver.getMessageList().flushMessages(); NormalizedMessage msg = (NormalizedMessage) msgs.get(0); Element elem = new SourceTransformer().toDOMElement(msg); assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI()); assertEquals("env:Envelope", elem.getNodeName()); logger.info(new SourceTransformer().contentToString(msg)); // Wait for DONE status Thread.sleep(50); }
From source file:org.apache.servicemix.wsn.AbstractCreatePullPoint.java
public CreatePullPointResponse handleCreatePullPoint( org.oasis_open.docs.wsn.b_2.CreatePullPoint createPullPointRequest, EndpointManager manager) throws UnableToCreatePullPointFault { AbstractPullPoint pullPoint = null;/*w ww .j a va 2 s.c om*/ boolean success = false; try { pullPoint = createPullPoint(createPullPointName(createPullPointRequest)); for (Iterator it = createPullPointRequest.getAny().iterator(); it.hasNext();) { Element el = (Element) it.next(); if ("address".equals(el.getLocalName()) && "http://servicemix.apache.org/wsn2005/1.0".equals(el.getNamespaceURI())) { String address = DOMUtil.getElementText(el).trim(); pullPoint.setAddress(address); } } pullPoint.setCreatePullPoint(this); // System.out.println("pullPoint.getAddress()----------------------"+pullPoint.getAddress()); pullPoints.put(pullPoint.getAddress(), pullPoint); pullPoint.create(createPullPointRequest); if (manager != null) { pullPoint.setManager(manager); } //pullPoint.register(); CreatePullPointResponse response = new CreatePullPointResponse(); response.setPullPoint(AbstractWSAClient.createWSA(pullPoint.getAddress())); System.out.println(response.getPullPoint().toString()); success = true; return response; } catch (Exception e) { log.warn("Unable to register new endpoint", e); UnableToCreatePullPointFaultType fault = new UnableToCreatePullPointFaultType(); throw new UnableToCreatePullPointFault("Unable to register new endpoint", fault, e); } finally { if (!success && pullPoint != null) { pullPoints.remove(pullPoint.getAddress()); try { pullPoint.destroy(); } catch (UnableToDestroyPullPointFault e) { log.info("Error destroying pullPoint", e); } } } }
From source file:org.apache.servicemix.wsn.AbstractCreatePullPoint.java
protected String createPullPointName(org.oasis_open.docs.wsn.b_2.CreatePullPoint createPullPointRequest) { // Let the creator decide which pull point name to use String name = null;/* w w w . j a v a 2 s. c o m*/ for (Iterator it = createPullPointRequest.getAny().iterator(); it.hasNext();) { Element el = (Element) it.next(); // System.out.println("el()----------------------"+el); if ("name".equals(el.getLocalName()) && "http://servicemix.apache.org/wsn2005/1.0".equals(el.getNamespaceURI())) { name = DOMUtil.getElementText(el).trim(); } // System.out.println("name1()----------------------"+name); } if (name == null) { // If no name is given, just generate one name = idGenerator.generateSanitizedId(); // System.out.println("name2()----------------------"+name); } return name; }
From source file:org.apache.syncope.core.logic.SAML2IdPLogic.java
private List<SAML2IdPTO> importIdPs(final InputStream input) throws Exception { List<EntityDescriptor> idpEntityDescriptors = new ArrayList<>(); Element root = OpenSAMLUtil.getParserPool().parse(new InputStreamReader(input)).getDocumentElement(); if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) { idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom(root)); } else if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntitiesDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) { NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (SAMLConstants.SAML20MD_NS.equals(child.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(child.getLocalName())) { NodeList descendants = child.getChildNodes(); for (int j = 0; j < descendants.getLength(); j++) { Node descendant = descendants.item(j); if (SAMLConstants.SAML20MD_NS.equals(descendant.getNamespaceURI()) && IDPSSODescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(descendant.getLocalName())) { idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom((Element) child)); }/*from w ww . ja v a 2s.com*/ } } } } List<SAML2IdPTO> result = new ArrayList<>(idpEntityDescriptors.size()); for (EntityDescriptor idpEntityDescriptor : idpEntityDescriptors) { SAML2IdPTO idpTO = new SAML2IdPTO(); idpTO.setEntityID(idpEntityDescriptor.getEntityID()); idpTO.setName(idpEntityDescriptor.getEntityID()); idpTO.setUseDeflateEncoding(false); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { saml2rw.write(new OutputStreamWriter(baos), idpEntityDescriptor, false); idpTO.setMetadata(Base64.getEncoder().encodeToString(baos.toByteArray())); } ItemTO connObjectKeyItem = new ItemTO(); connObjectKeyItem.setIntAttrName("username"); connObjectKeyItem.setExtAttrName("NameID"); idpTO.setConnObjectKeyItem(connObjectKeyItem); SAML2IdPEntity idp = cache.put(idpEntityDescriptor, idpTO); if (idp.getSSOLocation(SAML2BindingType.POST) != null) { idpTO.setBindingType(SAML2BindingType.POST); } else if (idp.getSSOLocation(SAML2BindingType.REDIRECT) != null) { idpTO.setBindingType(SAML2BindingType.REDIRECT); } else { throw new IllegalArgumentException( "Neither POST nor REDIRECT artifacts supported by " + idp.getId()); } result.add(idpTO); } return result; }