/** * Read the wsdl and clean the actual service endpoint instead of that set the gateway endpoint. * * @return {@link OMElement} - the OMElemnt of the new WSDL content * @throws APIManagementException */ public OMElement readAndCleanWsdl() throws APIManagementException { try { Definition wsdlDefinition = readWSDLFile(); setServiceDefinition(wsdlDefinition); WSDLWriter writer = getWsdlFactoryInstance().newWSDLWriter(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); writer.writeWSDL(wsdlDefinition, byteArrayOutputStream); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); OMElement wsdlElement = APIUtil.buildOMElement(byteArrayInputStream); return wsdlElement; } catch (Exception e) { String msg = " Error occurs when change the addres URL of the WSDL"; log.error(msg); throw new APIManagementException(msg, e); } }
public File writeDefinition(File targetDir, File defnFile) throws Exception { File bkFile = new File(targetDir, "bk_" + defnFile.getName()); FileWriter writer = new FileWriter(bkFile); WSDLFactory factory = WSDLFactory.newInstance("org.apache.cxf.tools.corba.utils.TestWSDLCorbaFactoryImpl"); WSDLReader reader = factory.newWSDLReader(); reader.setFeature("javax.wsdl.importDocuments", false); ExtensionRegistry extReg = new ExtensionRegistry(); addExtensions(extReg); reader.setExtensionRegistry(extReg); Definition wsdlDefn = reader.readWSDL(defnFile.toString()); WSDLWriter wsdlWriter = factory.newWSDLWriter(); wsdlWriter.writeWSDL(wsdlDefn, writer); writer.close(); writer = null; reader = null; return bkFile; }
@Override public void writeResponse( String baseUri, String ctxUri, EndpointInfo endpointInfo, OutputStream os) { try { int idx = baseUri.toLowerCase().indexOf("?"); Map<String, String> params = UrlUtils.parseQueryString(baseUri.substring(idx + 1)); String base; if (endpointInfo.getProperty("publishedEndpointUrl") != null) { base = String.valueOf(endpointInfo.getProperty("publishedEndpointUrl")); } else { base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?")); } String wsdl = params.get("wsdl"); if (wsdl != null) { // Always use the URL decoded version to ensure that we have a // canonical representation of the import URL for lookup. wsdl = URLDecoder.decode(wsdl, "utf-8"); } String xsd = params.get("xsd"); if (xsd != null) { // Always use the URL decoded version to ensure that we have a // canonical representation of the import URL for lookup. xsd = URLDecoder.decode(xsd, "utf-8"); } Map<String, Definition> mp = CastUtils.cast( (Map) endpointInfo.getService().getProperty(WSDLQueryHandler.class.getName())); Map<String, SchemaReference> smp = CastUtils.cast( (Map) endpointInfo .getService() .getProperty(WSDLQueryHandler.class.getName() + ".Schemas")); if (mp == null) { endpointInfo .getService() .setProperty(WSDLQueryHandler.class.getName(), new ConcurrentHashMap()); mp = CastUtils.cast( (Map) endpointInfo.getService().getProperty(WSDLQueryHandler.class.getName())); } if (smp == null) { endpointInfo .getService() .setProperty(WSDLQueryHandler.class.getName() + ".Schemas", new ConcurrentHashMap()); smp = CastUtils.cast( (Map) endpointInfo .getService() .getProperty(WSDLQueryHandler.class.getName() + ".Schemas")); } if (!mp.containsKey("")) { Definition def = getDefinition(endpointInfo); mp.put("", def); updateDefinition(def, mp, smp, base, endpointInfo); } Document doc; if (xsd == null) { Definition def = mp.get(wsdl); if (def == null) { String wsdl2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), wsdl, base); if (wsdl2 != null) { def = mp.get(wsdl2); } } if (def == null) { throw new WSDLQueryException( new org.apache.cxf.common.i18n.Message("WSDL_NOT_FOUND", LOG, wsdl), null); } synchronized (def) { // writing a def is not threadsafe. Sync on it to make sure // we don't get any ConcurrentModificationExceptions if (endpointInfo.getProperty("publishedEndpointUrl") != null) { String publishingUrl = String.valueOf(endpointInfo.getProperty("publishedEndpointUrl")); updatePublishedEndpointUrl(publishingUrl, def, endpointInfo.getName()); } WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter(); def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); doc = wsdlWriter.getDocument(def); } } else { SchemaReference si = smp.get(xsd); if (si == null) { String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), xsd, base); if (xsd2 != null) { si = smp.get(xsd2); } } if (si == null) { throw new WSDLQueryException( new org.apache.cxf.common.i18n.Message("SCHEMA_NOT_FOUND", LOG, wsdl), null); } String uri = si.getReferencedSchema().getDocumentBaseURI(); uri = resolveWithCatalogs( OASISCatalogManager.getCatalogManager(bus), uri, si.getReferencedSchema().getDocumentBaseURI()); if (uri == null) { uri = si.getReferencedSchema().getDocumentBaseURI(); } ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri, bus); InputSource src = rml.getBaseInputSource(); doc = XMLUtils.getParser().parse(src); } updateDoc(doc, base, mp, smp, endpointInfo); String enc = null; try { enc = doc.getXmlEncoding(); } catch (Exception ex) { // ignore - not dom level 3 } if (enc == null) { enc = "utf-8"; } XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, enc); StaxUtils.writeNode(doc, writer, true); writer.flush(); } catch (WSDLQueryException wex) { throw wex; } catch (Exception wex) { throw new WSDLQueryException( new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, baseUri), wex); } }
public void printSchema(Definition def, OutputStream out) throws WSDLException { WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); writer.writeWSDL(def, out); }
@org.junit.Test public void testAnnotations() throws Exception { Bus bus = BusFactory.getDefaultBus(); JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setBus(bus); factory.setServiceBean(new TestImpl()); factory.setStart(false); List<String> tp = Arrays.asList( "http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat"); LocalTransportFactory f = new LocalTransportFactory(bus); f.getUriPrefixes().add("http"); f.setTransportIds(tp); f.setBus(bus); f.register(); Server s = factory.create(); try { ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos()); Definition def = builder.build(); WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter(); def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry()); Element wsdl = wsdlWriter.getDocument(def).getDocumentElement(); Map<String, String> ns = new HashMap<String, String>(); ns.put("wsdl", WSDLConstants.NS_WSDL11); ns.put( "wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); ns.put("wsp", Constants.URI_POLICY_13_NS); XPathUtils xpu = new XPathUtils(ns); // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl); check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy"); check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input", "echoIntPortTypeOpInputPolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output", "echoIntPortTypeOpOutputPolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestImplServiceSoapBindingBindingPolicy"); check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input", "echoIntBindingOpInputPolicy"); check( xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output", "echoIntBindingOpOutputPolicy"); check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy"); EndpointPolicy policy = bus.getExtension(PolicyEngine.class) .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null); assertNotNull(policy); assertEquals(1, policy.getChosenAlternative().size()); } finally { bus.shutdown(true); } }