Java Code Examples for org.apache.cxf.helpers.DOMUtils#getChildrenWithName()
The following examples show how to use
org.apache.cxf.helpers.DOMUtils#getChildrenWithName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 6 votes |
private void checkGrammarsWithLinks(Element appElement, List<String> links) { assertFalse(links.isEmpty()); List<Element> grammarEls = DOMUtils.getChildrenWithName(appElement, WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(0, schemasEls.size()); List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0), WadlGenerator.WADL_NS, "include"); assertEquals(links.size(), includeEls.size()); for (Element el : includeEls) { assertTrue(links.contains(el.getAttribute("href"))); } }
Example 2
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testRootResourceWithSingleSlash() throws Exception { WadlGenerator wg = new WadlGenerator(); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(BookStoreWithSingleSlash.class, BookStoreWithSingleSlash.class, true, true); Message m = mockMessage("http://localhost:8080/baz", "/", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); List<Element> rootEls = getWadlResourcesInfo(doc, "http://localhost:8080/baz", 1); assertEquals(1, rootEls.size()); Element resource = rootEls.get(0); assertEquals("/", resource.getAttribute("path")); List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, WadlGenerator.WADL_NS, "resource"); assertEquals(1, resourceEls.size()); assertEquals("book", resourceEls.get(0).getAttribute("path")); verifyParameters(resourceEls.get(0), 1, new Param("id", "template", "xs:int")); checkGrammars(doc.getDocumentElement(), "thebook", null, "thechapter"); }
Example 3
Source File: JAXRSClientServerSpringBookTest.java From cxf with Apache License 2.0 | 6 votes |
private void checkWadlResourcesType(String baseURI, String requestTypeURI, String schemaRef) throws Exception { WebClient client = WebClient.create(requestTypeURI); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); Element root = doc.getDocumentElement(); assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI()); assertEquals("application", root.getLocalName()); List<Element> grammarEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0), WadlGenerator.WADL_NS, "include"); assertEquals(1, includeEls.size()); String href = includeEls.get(0).getAttribute("href"); assertEquals(baseURI + schemaRef, href); List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resources"); assertEquals(0, resourcesEls.size()); List<Element> resourceTypeEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resource_type"); assertEquals(1, resourceTypeEls.size()); }
Example 4
Source File: JAXRSClientServerSpringBookTest.java From cxf with Apache License 2.0 | 6 votes |
private void checkSchemas(String address, String schemaSegment, String includedSchema, String refAttrName) throws Exception { WebClient client = WebClient.create(address + schemaSegment); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000L); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); Element root = doc.getDocumentElement(); assertEquals(Constants.URI_2001_SCHEMA_XSD, root.getNamespaceURI()); assertEquals("schema", root.getLocalName()); if (includedSchema != null) { List<Element> includeEls = DOMUtils.getChildrenWithName(root, Constants.URI_2001_SCHEMA_XSD, refAttrName); assertEquals(1, includeEls.size()); String href = includeEls.get(0).getAttribute("schemaLocation"); assertEquals(address + includedSchema, href); } }
Example 5
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 6 votes |
private void checkGenericImplSchemaWithElements(Element schemaEl) { assertEquals("http://example.com", schemaEl.getAttribute("targetNamespace")); List<Element> importEls = DOMUtils.getChildrenWithName(schemaEl, Constants.URI_2001_SCHEMA_XSD, "import"); assertEquals(1, importEls.size()); List<Element> typeEls = DOMUtils.getChildrenWithName(schemaEl, Constants.URI_2001_SCHEMA_XSD, "element"); assertEquals(2, typeEls.size()); assertEquals("actual", typeEls.get(0).getAttribute("name")); assertEquals("actual", typeEls.get(0).getAttribute("type")); assertEquals("super", typeEls.get(1).getAttribute("name")); assertEquals("super", typeEls.get(1).getAttribute("type")); }
Example 6
Source File: JavaFirstPolicyServiceTest.java From cxf with Apache License 2.0 | 5 votes |
private void testJavaFirstAttachmentWsdl(Document doc) throws Exception { Element binding = DOMUtils.getFirstChildWithName(doc.getDocumentElement(), WSDL_NAMESPACE, "binding"); assertNotNull(binding); List<Element> operationMessages = DOMUtils.getChildrenWithName(binding, WSDL_NAMESPACE, "operation"); assertEquals(4, operationMessages.size()); Element doOperationLevelPolicy = getOperationElement("doOperationLevelPolicy", operationMessages); assertEquals("#UsernameToken", getOperationPolicyReferenceId(doOperationLevelPolicy, Constants.URI_POLICY_13_NS)); Element doInputMessagePolicy = getOperationElement("doInputMessagePolicy", operationMessages); assertEquals("#UsernameToken", getMessagePolicyReferenceId(doInputMessagePolicy, Type.INPUT, Constants.URI_POLICY_13_NS)); assertNull(getMessagePolicyReferenceId(doInputMessagePolicy, Type.OUTPUT, Constants.URI_POLICY_13_NS)); Element doOutputMessagePolicy = getOperationElement("doOutputMessagePolicy", operationMessages); assertEquals("#UsernameToken", getMessagePolicyReferenceId(doOutputMessagePolicy, Type.OUTPUT, Constants.URI_POLICY_13_NS)); assertNull(getMessagePolicyReferenceId(doOutputMessagePolicy, Type.INPUT, Constants.URI_POLICY_13_NS)); Element doNoPolicy = getOperationElement("doNoPolicy", operationMessages); assertNull(getMessagePolicyReferenceId(doNoPolicy, Type.INPUT, Constants.URI_POLICY_13_NS)); assertNull(getMessagePolicyReferenceId(doNoPolicy, Type.OUTPUT, Constants.URI_POLICY_13_NS)); // ensure that the policies are attached to the wsdl:definitions List<Element> policyMessages = DOMUtils.getChildrenWithName(doc.getDocumentElement(), Constants.URI_POLICY_13_NS, "Policy"); assertEquals(1, policyMessages.size()); assertEquals("UsernameToken", getPolicyId(policyMessages.get(0))); Element exactlyOne = DOMUtils.getFirstChildWithName(policyMessages.get(0), "", "ExactlyOne"); assertNull(exactlyOne); exactlyOne = DOMUtils.getFirstChildWithName(policyMessages.get(0), Constants.URI_POLICY_13_NS, "ExactlyOne"); assertNotNull(exactlyOne); }
Example 7
Source File: JAXRSClientServerResourceCreatedSpringProviderTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWadlPublishedEndpointUrl() throws Exception { String requestURI = "http://localhost:" + PORT + "/webapp/resources2"; WebClient client = WebClient.create(requestURI + "?_wadl&_type=xml"); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); Element root = doc.getDocumentElement(); assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI()); assertEquals("application", root.getLocalName()); List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resources"); assertEquals(1, resourcesEls.size()); Element resourcesEl = resourcesEls.get(0); assertEquals("http://proxy", resourcesEl.getAttribute("base")); }
Example 8
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGenericImplementation() throws Exception { setUpGenericImplementationTest(); WadlGenerator wg = new WadlGenerator(); wg.setApplicationTitle("My Application"); wg.setNamespacePrefix("ns"); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(ActualResource.class, ActualResource.class, true, true); Message m = mockMessage("http://example.com", "/", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); checkDocs(doc.getDocumentElement(), "My Application", "", ""); List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(2, schemasEls.size()); List<Element> importEls = DOMUtils.getChildrenWithName(schemasEls.get(0), Constants.URI_2001_SCHEMA_XSD, "import"); int schemaElementsIndex = !importEls.isEmpty() ? 0 : 1; int schemaTypesIndex = schemaElementsIndex == 0 ? 1 : 0; checkGenericImplSchemaWithTypes(schemasEls.get(schemaTypesIndex)); checkGenericImplSchemaWithElements(schemasEls.get(schemaElementsIndex)); List<Element> reps = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), WadlGenerator.WADL_NS, "representation"); assertEquals(2, reps.size()); assertEquals("ns1:actual", reps.get(0).getAttribute("element")); assertEquals("ns1:actual", reps.get(1).getAttribute("element")); }
Example 9
Source File: UndertowServerEngineFactoryParser.java From cxf with Apache License 2.0 | 5 votes |
public Metadata parse(Element element, ParserContext context) { //Endpoint definition MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class); if (!StringUtils.isEmpty(getIdOrName(element))) { ef.setId(getIdOrName(element)); } else { ef.setId("undertow.engine.factory-holder-" + UUID.randomUUID().toString()); } ef.setRuntimeClass(UndertowHTTPServerEngineFactoryHolder.class); // setup the HandlersMap property for the UndertowHTTPServerEngineFactoryHolder try { // Print the DOM node String xmlString = StaxUtils.toString(element); ef.addProperty("parsedElement", createValue(context, xmlString)); ef.setInitMethod("init"); ef.setActivation(ComponentMetadata.ACTIVATION_EAGER); ef.setDestroyMethod("destroy"); // setup the EngineConnector List<Element> engines = DOMUtils .getChildrenWithName(element, HTTPUndertowTransportNamespaceHandler.UNDERTOW_TRANSPORT, "engine"); ef.addProperty("handlersMap", parseEngineHandlers(engines, ef, context)); return ef; } catch (Exception e) { throw new RuntimeException("Could not process configuration.", e); } }
Example 10
Source File: XMLBeanTypeInfo.java From cxf with Apache License 2.0 | 5 votes |
private Element getPropertyElement(String name2) { for (Element mapping2 : mappings) { List<Element> elements = DOMUtils.getChildrenWithName(mapping2, "", "property"); for (int i = 0; i < elements.size(); i++) { Element e = elements.get(i); String name = DOMUtils.getAttributeValueEmptyNull(e, "name"); if (name != null && name.equals(name2)) { return e; } } } return null; }
Example 11
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
private void verifyResponseWithStatus(Element element, String status) { List<Element> responseEls = DOMUtils.getChildrenWithName(element, WadlGenerator.WADL_NS, "response"); assertEquals(1, responseEls.size()); assertEquals(status, responseEls.get(0).getAttribute("status")); assertEquals(0, DOMUtils.getChildrenWithName(responseEls.get(0), WadlGenerator.WADL_NS, "representation").size()); }
Example 12
Source File: WSDL11Generator.java From cxf with Apache License 2.0 | 5 votes |
private void updateImports(Element el, Map<String, SchemaInfo> imports) { List<Element> imps = DOMUtils.getChildrenWithName(el, WSDLConstants.NS_SCHEMA_XSD, "import"); for (Element e : imps) { String ns = e.getAttribute("namespace"); for (Map.Entry<String, SchemaInfo> ent : imports.entrySet()) { if (ent.getValue().getNamespaceURI().equals(ns)) { e.setAttribute("schemaLocation", ent.getKey()); } } } }
Example 13
Source File: JavaToProcessorTest.java From cxf with Apache License 2.0 | 5 votes |
private String findImport(Document doc) { List<Element> lst = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WSDLConstants.NS_SCHEMA_XSD, "import"); for (Element el : lst) { return el.getAttribute("schemaLocation"); } return null; }
Example 14
Source File: WSDLToJavaContainer.java From cxf with Apache License 2.0 | 5 votes |
private void updateImports(Element el, Map<String, String> sourceMap) { List<Element> imps = DOMUtils.getChildrenWithName(el, WSDLConstants.NS_SCHEMA_XSD, "import"); for (Element e : imps) { String ns = e.getAttribute("namespace"); updateSchemaLocation(sourceMap, ns, e); } }
Example 15
Source File: WSDLToJavaContainer.java From cxf with Apache License 2.0 | 5 votes |
private void updateIncludes(Element el, Map<String, String> sourceMap) { List<Element> imps = DOMUtils.getChildrenWithName(el, WSDLConstants.NS_SCHEMA_XSD, "include"); String ns = el.getAttribute("targetNamespace"); for (Element e : imps) { updateSchemaLocation(sourceMap, ns, e); } }
Example 16
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
private void checkDocs(Element el, String title, String value, String language) { List<Element> docsEls = DOMUtils.getChildrenWithName(el, WadlGenerator.WADL_NS, "doc"); assertEquals(1, docsEls.size()); assertEquals(title, docsEls.get(0).getAttribute("title")); assertEquals(value, docsEls.get(0).getTextContent()); assertEquals(language, docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang")); }
Example 17
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testTwoSchemasSameNs() throws Exception { WadlGenerator wg = new WadlGenerator(); wg.setApplicationTitle("My Application"); wg.setNamespacePrefix("ns"); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(TestResource.class, TestResource.class, true, true); Message m = mockMessage("http://localhost:8080/baz", "/", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); checkDocs(doc.getDocumentElement(), "My Application", "", ""); List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(2, schemasEls.size()); assertEquals("http://example.com/test", schemasEls.get(0).getAttribute("targetNamespace")); assertEquals("http://example.com/test", schemasEls.get(1).getAttribute("targetNamespace")); List<Element> reps = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), WadlGenerator.WADL_NS, "representation"); assertEquals(2, reps.size()); assertEquals("ns1:testCompositeObject", reps.get(0).getAttribute("element")); assertEquals("ns1:testCompositeObject", reps.get(1).getAttribute("element")); }
Example 18
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
private void verifyGetResourceMethod(Element element, String type, String docs) { List<Element> methodEls = DOMUtils.getChildrenWithName(element, WadlGenerator.WADL_NS, "method"); assertEquals(1, methodEls.size()); if (docs != null) { checkDocs(methodEls.get(0), "", docs, ""); } assertEquals("GET", methodEls.get(0).getAttribute("name")); assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), WadlGenerator.WADL_NS, "request").size()); List<Element> responseEls = DOMUtils.getChildrenWithName(methodEls.get(0), WadlGenerator.WADL_NS, "response"); assertEquals(1, responseEls.size()); verifyXmlJsonRepresentations(responseEls.get(0), type, null); }
Example 19
Source File: WadlGeneratorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCustomSchemaWithImportJaxbContextPrefixes() throws Exception { WadlGenerator wg = new WadlGenerator(); wg.setSchemaLocations(Collections.singletonList("classpath:/books.xsd")); ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true, true); Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY, cri); Response r = handleRequest(wg, m); checkResponse(r); Document doc = StaxUtils.read(new StringReader(r.getEntity().toString())); List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(), WadlGenerator.WADL_NS, "grammars"); assertEquals(1, grammarEls.size()); List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0), Constants.URI_2001_SCHEMA_XSD, "schema"); assertEquals(1, schemasEls.size()); assertEquals("http://books", schemasEls.get(0).getAttribute("targetNamespace")); List<Element> elementEls = DOMUtils.getChildrenWithName(schemasEls.get(0), Constants.URI_2001_SCHEMA_XSD, "element"); assertEquals(1, elementEls.size()); assertTrue(checkElement(elementEls, "books", "books")); List<Element> complexTypesEls = DOMUtils.getChildrenWithName(schemasEls.get(0), Constants.URI_2001_SCHEMA_XSD, "complexType"); assertEquals(1, complexTypesEls.size()); assertTrue(checkComplexType(complexTypesEls, "books")); List<Element> importEls = DOMUtils.getChildrenWithName(schemasEls.get(0), Constants.URI_2001_SCHEMA_XSD, "import"); assertEquals(1, importEls.size()); assertEquals("http://localhost:8080/baz/book1.xsd", importEls.get(0).getAttribute("schemaLocation")); }
Example 20
Source File: EndpointReferenceBuilder.java From cxf with Apache License 2.0 | 4 votes |
public EndpointReference getEndpointReference() { //if there is epr in wsdl, direct return this EPR List<ExtensibilityElement> portExtensors = endpoint.getEndpointInfo() .getExtensors(ExtensibilityElement.class); if (portExtensors != null) { Iterator<ExtensibilityElement> extensionElements = portExtensors.iterator(); QName wsaEpr = new QName(Names.WSA_NAMESPACE_NAME, "EndpointReference"); while (extensionElements.hasNext()) { ExtensibilityElement ext = extensionElements.next(); if (ext instanceof UnknownExtensibilityElement && wsaEpr.equals(ext.getElementType())) { Element eprEle = ((UnknownExtensibilityElement)ext).getElement(); List<Element> addressElements = DOMUtils.getChildrenWithName(eprEle, Names.WSA_NAMESPACE_NAME, Names.WSA_ADDRESS_NAME); if (!addressElements.isEmpty()) { /* * [WSA-WSDL Binding] : in a SOAP 1.1 port described using WSDL 1.1, the location * attribute of a soap11:address element (if present) would have the same value as the * wsa:Address child element of the wsa:EndpointReference element. */ addressElements.get(0).setTextContent(this.endpoint.getEndpointInfo().getAddress()); } return EndpointReference.readFrom(new DOMSource(eprEle)); } } } String bindingId = endpoint.getJaxwsBinding().getBindingID(); if (!SOAPBindingImpl.isSoapBinding(bindingId)) { throw new UnsupportedOperationException(new Message("GET_ENDPOINTREFERENCE_UNSUPPORTED_BINDING", LOG, bindingId).toString()); } W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder(); builder.address(this.endpoint.getEndpointInfo().getAddress()); builder.serviceName(this.endpoint.getService().getName()); builder.endpointName(this.endpoint.getEndpointInfo().getName()); if (this.endpoint.getEndpointInfo().getService().getDescription() != null) { builder.wsdlDocumentLocation(this.endpoint.getEndpointInfo().getService().getDescription() .getBaseURI()); } ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(EndpointReferenceBuilder.class.getClassLoader()); return builder.build(); } finally { Thread.currentThread().setContextClassLoader(cl); } }