use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class WSDLManagerImpl method getDefinition.
public Definition getDefinition(final Element el) throws WSDLException {
synchronized (definitionsMap) {
if (definitionsMap.containsKey(el)) {
return definitionsMap.get(el);
}
}
final WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", false);
reader.setExtensionRegistry(registry);
final Definition def;
// This is needed to avoid security exceptions when running with a security manager
if (System.getSecurityManager() == null) {
def = reader.readWSDL("", el);
} else {
try {
def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL("", el));
} catch (PrivilegedActionException paex) {
throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
}
}
synchronized (definitionsMap) {
definitionsMap.put(el, def);
}
return def;
}
use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class WSDLManagerImpl method loadDefinition.
protected Definition loadDefinition(String url) throws WSDLException {
final WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", false);
reader.setFeature("javax.wsdl.importDocuments", true);
reader.setExtensionRegistry(registry);
// we'll create a new String here to make sure the passed in key is not referenced in the loading of
// the wsdl and thus would be held onto from the cached map from both the weak reference (key) and
// from the strong reference (Definition). For example, the Definition sometimes keeps the original
// string as the documentBaseLocation which would result in it being held onto strongly
// from the definition. With this, the String the definition holds onto would be unique
url = new String(url);
CatalogWSDLLocator catLocator = new CatalogWSDLLocator(url, bus);
final ResourceManagerWSDLLocator wsdlLocator = new ResourceManagerWSDLLocator(url, catLocator, bus);
InputSource src = wsdlLocator.getBaseInputSource();
final Definition def;
if (src.getByteStream() != null || src.getCharacterStream() != null) {
final Document doc;
XMLStreamReader xmlReader = null;
try {
xmlReader = StaxUtils.createXMLStreamReader(src);
if (xmlStreamReaderWrapper != null) {
xmlReader = xmlStreamReaderWrapper.wrap(xmlReader);
}
doc = StaxUtils.read(xmlReader, true);
if (src.getSystemId() != null) {
try {
doc.setDocumentURI(new String(src.getSystemId()));
} catch (Exception e) {
// ignore - probably not DOM level 3
}
}
} catch (Exception e) {
throw new WSDLException(WSDLException.PARSER_ERROR, e.getMessage(), e);
} finally {
try {
StaxUtils.close(xmlReader);
} catch (XMLStreamException ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, ex.getMessage(), ex);
}
}
// This is needed to avoid security exceptions when running with a security manager
if (System.getSecurityManager() == null) {
def = reader.readWSDL(wsdlLocator, doc.getDocumentElement());
} else {
try {
def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator, doc.getDocumentElement()));
} catch (PrivilegedActionException paex) {
throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
}
}
} else {
if (System.getSecurityManager() == null) {
def = reader.readWSDL(wsdlLocator);
} else {
try {
def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator));
} catch (PrivilegedActionException paex) {
throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
}
}
}
return def;
}
use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class PublishedEndpointUrlTest method testPublishedEndpointUrl.
@Test
public void testPublishedEndpointUrl() throws Exception {
Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
Bus bus = BusFactory.getDefaultBus();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setBus(bus);
svrFactory.setServiceClass(Greeter.class);
svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
svrFactory.setServiceBean(implementor);
Server server = svrFactory.create();
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
assertEquals(500, connect.getResponseCode());
Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
assertNotNull(wsdl);
Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
final String failMesg = "WSDL provided incorrect soap:address location";
for (Service service : services) {
Collection<Port> ports = CastUtils.cast(service.getPorts().values());
for (Port port : ports) {
List<?> extensions = port.getExtensibilityElements();
for (Object extension : extensions) {
String actualUrl = null;
if (extension instanceof SOAP12Address) {
actualUrl = ((SOAP12Address) extension).getLocationURI();
} else if (extension instanceof SOAPAddress) {
actualUrl = ((SOAPAddress) extension).getLocationURI();
}
// System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
assertEquals(failMesg, publishedEndpointUrl, actualUrl);
}
}
}
server.stop();
server.destroy();
bus.shutdown(true);
}
use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class ServiceWSDLBuilderTest method setupWSDL.
private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
String wsdlUrl = getClass().getResource(wsdlPath).toString();
LOG.info("the path of wsdl file is " + wsdlUrl);
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
def = wsdlReader.readWSDL(wsdlUrl);
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
destinationFactory = control.createMock(DestinationFactory.class);
wsdlServiceBuilder = new WSDLServiceBuilder(bus, false);
for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
if (serv != null) {
service = serv;
break;
}
}
EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(new WSDLManagerImpl()).anyTimes();
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager);
EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory);
control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
builder.setUseSchemaImports(doXsdImports);
builder.setBaseFileName("HelloWorld");
newDef = builder.build(new HashMap<String, SchemaInfo>());
}
use of javax.wsdl.xml.WSDLReader in project cxf by apache.
the class WSDLServiceBuilderTest method setUpDefinition.
private void setUpDefinition(String wsdl, int serviceSeq) throws Exception {
URL url = getClass().getResource(wsdl);
assertNotNull("could not find wsdl " + wsdl, url);
String wsdlUrl = url.toString();
LOG.info("the path of wsdl file is " + wsdlUrl);
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
def = wsdlReader.readWSDL(new CatalogWSDLLocator(wsdlUrl));
int seq = 0;
for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
if (serv != null) {
service = serv;
if (seq == serviceSeq) {
break;
}
seq++;
}
}
}
Aggregations