Java Code Examples for org.apache.cxf.service.model.ServiceInfo#getSchemas()
The following examples show how to use
org.apache.cxf.service.model.ServiceInfo#getSchemas() .
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: JavascriptTestUtilities.java From cxf with Apache License 2.0 | 6 votes |
public void loadJavascriptForService(ServiceInfo serviceInfo) { Collection<SchemaInfo> schemata = serviceInfo.getSchemas(); BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo); NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo .getXmlSchemaCollection()); for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixManager, nameManager); String allThatJavascript = builder.generateCodeForSchema(schema.getSchema()); readStringIntoRhino(allThatJavascript, schema.toString() + ".js"); } ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager); serviceBuilder.walk(); String serviceJavascript = serviceBuilder.getCode(); readStringIntoRhino(serviceJavascript, serviceInfo.getName() + ".js"); }
Example 2
Source File: AttributeTest.java From cxf with Apache License 2.0 | 6 votes |
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException { testUtilities.setBus(getBean(Bus.class, "cxf")); testUtilities.initializeRhino(); testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js"); clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId); client = clientProxyFactory.getClientFactoryBean().create(); serviceInfos = client.getEndpoint().getService().getServiceInfos(); // there can only be one. assertEquals(1, serviceInfos.size()); ServiceInfo serviceInfo = serviceInfos.get(0); schemata = serviceInfo.getSchemas(); nameManager = BasicNameManager.newNameManager(serviceInfo); NamespacePrefixAccumulator prefixAccumulator = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection()); for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixAccumulator, nameManager); String allThatJavascript = builder.generateCodeForSchema(schema.getSchema()); assertNotNull(allThatJavascript); testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js"); } }
Example 3
Source File: SerializationTest.java From cxf with Apache License 2.0 | 6 votes |
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException { testUtilities.setBus(getBean(Bus.class, "cxf")); testUtilities.initializeRhino(); testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js"); clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId); client = clientProxyFactory.getClientFactoryBean().create(); serviceInfos = client.getEndpoint().getService().getServiceInfos(); // there can only be one. assertEquals(1, serviceInfos.size()); ServiceInfo serviceInfo = serviceInfos.get(0); schemata = serviceInfo.getSchemas(); nameManager = BasicNameManager.newNameManager(serviceInfo); NamespacePrefixAccumulator prefixAccumulator = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection()); for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixAccumulator, nameManager); String allThatJavascript = builder.generateCodeForSchema(schema.getSchema()); assertNotNull(allThatJavascript); testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js"); } }
Example 4
Source File: JAXBDataBinding.java From cxf with Apache License 2.0 | 5 votes |
private void addSchemasForServiceInfos(OASISCatalogManager catalog, List<ServiceInfo> serviceList, Options opts, SchemaCompiler schemaCompiler, SchemaCollection schemaCollection) { Set<String> ids = new HashSet<>(); for (ServiceInfo si : serviceList) { for (SchemaInfo sci : si.getSchemas()) { String key = sci.getSystemId(); if (ids.contains(key)) { continue; } ids.add(key); Element ele = sci.getElement(); if (context.fullValidateWSDL()) { validateSchema(ele, sci.getSystemId(), catalog, schemaCollection); } ele = removeImportElement(ele, key, catalog); InputSource is = new InputSource((InputStream)null); //key = key.replaceFirst("#types[0-9]+$", ""); is.setSystemId(key); is.setPublicId(key); opts.addGrammar(is); try { XMLStreamReader reader = createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)); schemaCompiler.parseSchema(key, reader); } catch (XMLStreamException e) { throw new RuntimeException(e); } } } }
Example 5
Source File: GenericAegisTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGenerateJavascript() throws Exception { // Create our service implementation GenericGenericClass<String> impl = new GenericGenericClass<>(); // Create our Server ServerFactoryBean svrFactory = new ServerFactoryBean(); // we sure can't get a .class for the interface, can we? svrFactory.setServiceClass(impl.getClass()); svrFactory.setAddress("http://localhost:" + PORT + "/aegisgeneric"); svrFactory.setServiceBean(impl); Server server = svrFactory.create(); ServiceInfo serviceInfo = ((EndpointImpl)server.getEndpoint()).getEndpointInfo().getService(); Collection<SchemaInfo> schemata = serviceInfo.getSchemas(); BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo); NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo .getXmlSchemaCollection()); for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixManager, nameManager); String allThatJavascript = builder.generateCodeForSchema(schema.getSchema()); assertNotNull(allThatJavascript); } ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager); serviceBuilder.walk(); String serviceJavascript = serviceBuilder.getCode(); assertNotNull(serviceJavascript); }
Example 6
Source File: JavascriptGetInterceptor.java From cxf with Apache License 2.0 | 5 votes |
private void writeResponse(URI uri, Map<String, String> map, OutputStream os, Endpoint serverEndpoint) { OutputStreamWriter writer = new OutputStreamWriter(os, UTF_8); if (!map.containsKey(NO_UTILS_QUERY_KEY)) { writeUtilsToResponseStream(JavascriptGetInterceptor.class, os); } if (map.containsKey(CODE_QUERY_KEY)) { ServiceInfo serviceInfo = serverEndpoint.getService().getServiceInfos().get(0); Collection<SchemaInfo> schemata = serviceInfo.getSchemas(); // we need to move this to the bus. BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, serverEndpoint); NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo .getXmlSchemaCollection()); try { for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixManager, nameManager); String allThatJavascript = builder.generateCodeForSchema(schema.getSchema()); writer.append(allThatJavascript); } ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, serverEndpoint.getEndpointInfo().getAddress(), prefixManager, nameManager); serviceBuilder.walk(); String serviceJavascript = serviceBuilder.getCode(); writer.append(serviceJavascript); writer.flush(); } catch (IOException e) { throw new UncheckedException(e); } } else { throw new RuntimeException("Invalid query " + uri.toString()); } }
Example 7
Source File: ReflectionServiceFactoryBean.java From cxf with Apache License 2.0 | 5 votes |
/** * Code elsewhere in this function will fill in the name of the type of an * element but not the reference to the type. This function fills in the * type references. This does not set the type reference for elements that * are declared as refs to other elements. It is a giant pain to find them, * since they are not (generally) root elements and the code would have to * traverse all the types to find all of them. Users should look them up * through the collection, that's what it is for. */ private void fillInSchemaCrossreferences() { Service service = getService(); for (ServiceInfo serviceInfo : service.getServiceInfos()) { SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection(); // First pass, fill in any types for which we have a name but no // type. for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) { Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements(); for (XmlSchemaElement element : elementsTable.values()) { if (element.getSchemaType() == null) { QName typeName = element.getSchemaTypeName(); if (typeName != null) { XmlSchemaType type = schemaCollection.getTypeByQName(typeName); if (type == null) { Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element .getQName(), typeName, service.getName()); LOG.severe(message.toString()); } else { element.setSchemaType(type); } } } } } } }
Example 8
Source File: JavaToJSProcessor.java From cxf with Apache License 2.0 | 4 votes |
public void process() throws ToolException { String oldClassPath = System.getProperty(JAVA_CLASS_PATH); LOG.log(Level.INFO, "OLD_CP", oldClassPath); if (context.get(ToolConstants.CFG_CLASSPATH) != null) { String newCp = (String)context.get(ToolConstants.CFG_CLASSPATH); System.setProperty(JAVA_CLASS_PATH, newCp + File.pathSeparator + oldClassPath); LOG.log(Level.INFO, "NEW_CP", newCp); } // check for command line specification of data binding. ServiceBuilder builder = getServiceBuilder(); ServiceInfo serviceInfo = builder.createService(); File jsFile = getOutputFile(builder.getOutputFile(), serviceInfo.getName().getLocalPart() + ".js"); BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null); NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo .getXmlSchemaCollection()); Collection<SchemaInfo> schemata = serviceInfo.getSchemas(); try { OutputStream outputStream = Files.newOutputStream(jsFile.toPath()); if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) { JavascriptGetInterceptor.writeUtilsToResponseStream(JavaToJSProcessor.class, outputStream); } OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF_8); try (BufferedWriter writer = new BufferedWriter(outputStreamWriter)) { for (SchemaInfo schema : schemata) { SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo .getXmlSchemaCollection(), prefixManager, nameManager); String allThatJavascript = jsBuilder.generateCodeForSchema(schema.getSchema()); writer.append(allThatJavascript); } ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager); serviceBuilder.walk(); String serviceJavascript = serviceBuilder.getCode(); writer.append(serviceJavascript); } } catch (IOException e) { throw new ToolException(e); } System.setProperty(JAVA_CLASS_PATH, oldClassPath); LOG.log(Level.INFO, "RESUME_CP", oldClassPath); }
Example 9
Source File: JaxWsServiceFactoryBeanTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testWrappedDocLit() throws Exception { ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(); Bus bus = getBus(); bean.setBus(bus); bean.setServiceClass(org.apache.hello_world_doc_lit.Greeter.class); Service service = bean.create(); ServiceInfo si = service.getServiceInfos().get(0); InterfaceInfo intf = si.getInterface(); assertEquals(4, intf.getOperations().size()); String ns = si.getName().getNamespaceURI(); assertEquals("http://apache.org/hello_world_doc_lit", ns); OperationInfo greetMeOp = intf.getOperation(new QName(ns, "greetMe")); assertNotNull(greetMeOp); assertEquals("greetMe", greetMeOp.getInput().getName().getLocalPart()); assertEquals("http://apache.org/hello_world_doc_lit", greetMeOp.getInput().getName() .getNamespaceURI()); List<MessagePartInfo> messageParts = greetMeOp.getInput().getMessageParts(); assertEquals(1, messageParts.size()); MessagePartInfo inMessagePart = messageParts.get(0); assertEquals("http://apache.org/hello_world_doc_lit", inMessagePart.getName().getNamespaceURI()); assertEquals("http://apache.org/hello_world_doc_lit/types", inMessagePart.getElementQName() .getNamespaceURI()); // test output messageParts = greetMeOp.getOutput().getMessageParts(); assertEquals(1, messageParts.size()); assertEquals("greetMeResponse", greetMeOp.getOutput().getName().getLocalPart()); MessagePartInfo outMessagePart = messageParts.get(0); //assertEquals("result", outMessagePart.getName().getLocalPart()); assertEquals("http://apache.org/hello_world_doc_lit", outMessagePart.getName().getNamespaceURI()); assertEquals("http://apache.org/hello_world_doc_lit/types", outMessagePart.getElementQName() .getNamespaceURI()); OperationInfo greetMeOneWayOp = si.getInterface().getOperation(new QName(ns, "greetMeOneWay")); assertEquals(1, greetMeOneWayOp.getInput().getMessageParts().size()); assertNull(greetMeOneWayOp.getOutput()); Collection<SchemaInfo> schemas = si.getSchemas(); assertEquals(1, schemas.size()); }
Example 10
Source File: ReflectionServiceFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) { MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput(); final List<MessagePartInfo> messageParts = message.getMessageParts(); if (messageParts.isEmpty()) { return; } Method method = (Method)opInfo.getProperty(METHOD); int paraNumber = 0; for (MessagePartInfo mpi : messageParts) { SchemaInfo schemaInfo = null; XmlSchema schema = null; QName qname = (QName)mpi.getProperty(ELEMENT_NAME); if (messageParts.size() == 1 && qname == null) { qname = !isOut ? getInParameterName(opInfo, method, -1) : getOutParameterName(opInfo, method, -1); if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) { qname = isOut ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname .getNamespaceURI(), method.getName()); } } else if (isOut && messageParts.size() > 1 && qname == null) { while (!isOutParam(method, paraNumber)) { paraNumber++; } qname = getOutParameterName(opInfo, method, paraNumber); } else if (qname == null) { qname = getInParameterName(opInfo, method, paraNumber); } for (SchemaInfo s : serviceInfo.getSchemas()) { if (s.getNamespaceURI().equals(qname.getNamespaceURI())) { schemaInfo = s; break; } } if (schemaInfo == null) { schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true); schema = schemaInfo.getSchema(); } else { schema = schemaInfo.getSchema(); if (schema != null && schema.getElementByName(qname) != null) { mpi.setElement(true); mpi.setElementQName(qname); mpi.setXmlSchema(schema.getElementByName(qname)); paraNumber++; continue; } } schemaInfo.setElement(null); //cached element is now invalid XmlSchemaElement el = new XmlSchemaElement(schema, true); el.setName(qname.getLocalPart()); el.setNillable(true); if (mpi.isElement()) { XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema(); if (null != oldEl && !oldEl.getQName().equals(qname)) { el.setSchemaTypeName(oldEl.getSchemaTypeName()); el.setSchemaType(oldEl.getSchemaType()); if (oldEl.getSchemaTypeName() != null) { addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI()); } } mpi.setElement(true); mpi.setXmlSchema(el); mpi.setElementQName(qname); mpi.setConcreteName(qname); continue; } if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) { throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG, method.getDeclaringClass().getName(), method.getName(), mpi.getName())); } if (mpi.getTypeQName() != null) { el.setSchemaTypeName(mpi.getTypeQName()); } else { el.setSchemaType((XmlSchemaType)mpi.getXmlSchema()); } mpi.setXmlSchema(el); mpi.setConcreteName(qname); if (mpi.getTypeQName() != null) { addImport(schema, mpi.getTypeQName().getNamespaceURI()); } mpi.setElement(true); mpi.setElementQName(qname); paraNumber++; } }
Example 11
Source File: ReflectionServiceFactoryBean.java From cxf with Apache License 2.0 | 4 votes |
private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo, String namespaceURI, boolean qualified) { for (SchemaInfo s : serviceInfo.getSchemas()) { if (s.getNamespaceURI().equals(namespaceURI)) { return s; } } SchemaInfo schemaInfo = new SchemaInfo(namespaceURI); SchemaCollection col = serviceInfo.getXmlSchemaCollection(); XmlSchema schema = col.getSchemaByTargetNamespace(namespaceURI); if (schema != null) { schemaInfo.setSchema(schema); serviceInfo.addSchema(schemaInfo); return schemaInfo; } schema = col.newXmlSchemaInCollection(namespaceURI); if (qualified) { schema.setElementFormDefault(XmlSchemaForm.QUALIFIED); } schemaInfo.setSchema(schema); Map<String, String> explicitNamespaceMappings = this.getDataBinding().getDeclaredNamespaceMappings(); if (explicitNamespaceMappings == null) { explicitNamespaceMappings = Collections.emptyMap(); } NamespaceMap nsMap = new NamespaceMap(); for (Map.Entry<String, String> mapping : explicitNamespaceMappings.entrySet()) { nsMap.add(mapping.getValue(), mapping.getKey()); } if (!explicitNamespaceMappings.containsKey(WSDLConstants.NS_SCHEMA_XSD)) { nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); } if (!explicitNamespaceMappings.containsKey(serviceInfo.getTargetNamespace())) { nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, serviceInfo.getTargetNamespace()); } schema.setNamespaceContext(nsMap); serviceInfo.addSchema(schemaInfo); return schemaInfo; }
Example 12
Source File: Stax2ValidationUtils.java From cxf with Apache License 2.0 | 4 votes |
/** * Create woodstox validator for a schema set. * * @throws XMLStreamException */ private XMLValidationSchema getValidator(Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException { synchronized (endpoint) { XMLValidationSchema ret = (XMLValidationSchema) endpoint.get(KEY); if (ret == null) { if (endpoint.containsKey(KEY)) { return null; } Map<String, Source> sources = new TreeMap<>(); for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) { XmlSchema sch = schemaInfo.getSchema(); String uri = sch.getTargetNamespace(); if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri)) { continue; } if (sch.getTargetNamespace() == null && !sch.getExternals().isEmpty()) { for (XmlSchemaExternal xmlSchemaExternal : sch.getExternals()) { addSchema(sources, xmlSchemaExternal.getSchema(), getElement(xmlSchemaExternal.getSchema().getSourceURI())); } continue; } else if (sch.getTargetNamespace() == null) { throw new IllegalStateException("An Schema without imports must have a targetNamespace"); } addSchema(sources, sch, schemaInfo.getElement()); } try { // I don't think that we need the baseURI. Method method = multiSchemaFactory.getMethod("createSchema", String.class, Map.class); ret = (XMLValidationSchema) method.invoke(multiSchemaFactory.newInstance(), null, sources); endpoint.put(KEY, ret); } catch (Throwable t) { LOG.log(Level.INFO, "Problem loading schemas. Falling back to slower method.", ret); endpoint.put(KEY, null); } } return ret; } }