use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JMSEndpointWSDLUtil method getWSDLExtensor.
public static <T> T getWSDLExtensor(EndpointInfo ei, Class<T> cls) {
ServiceInfo si = ei.getService();
BindingInfo bi = ei.getBinding();
Object o = ei.getExtensor(cls);
if (o == null && si != null) {
o = si.getExtensor(cls);
}
if (o == null && bi != null) {
o = bi.getExtensor(cls);
}
if (o == null) {
return null;
}
if (cls.isInstance(o)) {
return cls.cast(o);
}
return null;
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class RMEndpoint method createEndpoint.
void createEndpoint(org.apache.cxf.transport.Destination d, ProtocolVariation protocol) {
final QName bindingQName = new QName(protocol.getWSRMNamespace(), BINDING_NAME);
WrappedService service = services.get(protocol);
ServiceInfo si = service.getServiceInfo();
buildBindingInfo(si, protocol);
EndpointInfo aei = applicationEndpoint.getEndpointInfo();
String transportId = aei.getTransportId();
EndpointInfo ei = new EndpointInfo(si, transportId);
if (d != null) {
ei.setProperty(MAPAggregator.DECOUPLED_DESTINATION, d);
}
ei.setAddress(aei.getAddress());
ei.setName(RMUtils.getConstants(protocol.getWSRMNamespace()).getPortName());
ei.setBinding(si.getBinding(bindingQName));
// if addressing was enabled on the application endpoint by means
// of the UsingAddressing element extensor, use this for the
// RM endpoint also
Object ua = getUsingAddressing(aei);
if (null != ua) {
ei.addExtensor(ua);
}
si.addEndpoint(ei);
ei.setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
Endpoint endpoint = new WrappedEndpoint(applicationEndpoint, ei, service);
if (applicationEndpoint.getEndpointInfo() != null && applicationEndpoint.getEndpointInfo().getProperties() != null) {
for (String key : applicationEndpoint.getEndpointInfo().getProperties().keySet()) {
endpoint.getEndpointInfo().setProperty(key, applicationEndpoint.getEndpointInfo().getProperty(key));
}
}
service.setEndpoint(endpoint);
endpoints.put(protocol, endpoint);
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JAXBDataBinding method addSchemas.
private void addSchemas(Options opts, SchemaCompiler schemaCompiler, SchemaCollection schemaCollection) {
Set<String> ids = new HashSet<>();
@SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
for (ServiceInfo si : serviceList) {
for (SchemaInfo sci : si.getSchemas()) {
String key = sci.getSystemId();
if (ids.contains(key)) {
continue;
}
ids.add(key);
}
}
Bus bus = context.get(Bus.class);
OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
if (ids.contains(key)) {
continue;
}
if (!key.startsWith("file:") && !key.startsWith("jar:")) {
XmlSchemaSerializer xser = new XmlSchemaSerializer();
xser.setExtReg(schemaCollection.getExtReg());
Document[] docs;
try {
docs = xser.serializeSchema(schema, false);
} catch (XmlSchemaSerializerException e) {
throw new RuntimeException(e);
}
Element ele = docs[0].getDocumentElement();
if (context.fullValidateWSDL()) {
String uri = null;
try {
uri = docs[0].getDocumentURI();
} catch (Throwable ex) {
// ignore - DOM level 3
}
validateSchema(ele, uri, catalog, schemaCollection);
}
ele = removeImportElement(ele, key, catalog);
try {
docs[0].setDocumentURI(key);
} catch (Throwable t) {
// ignore - DOM level 3
}
InputSource is = new InputSource((InputStream) null);
// key = key.replaceFirst("#types[0-9]+$", "");
is.setSystemId(key);
is.setPublicId(key);
opts.addGrammar(is);
try {
schemaCompiler.parseSchema(key, createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)));
} catch (XMLStreamException e) {
throw new ToolException(e);
}
}
}
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
String tns = schema.getTargetNamespace();
String ltns = schema.getLogicalTargetNamespace();
// accepting also a null tns (e.g., reported by apache.ws.xmlschema for no-namespace)
if (ids.contains(key) || (tns == null && !StringUtils.isEmpty(ltns))) {
continue;
}
if (key.startsWith("file:") || key.startsWith("jar:")) {
InputStream in = null;
try {
// NOPMD
if (key.startsWith("file:")) {
in = Files.newInputStream(new File(new URI(key)).toPath());
} else {
in = new URL(key).openStream();
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
reader = createNoCDATAReader(new LocationFilterReader(reader, catalog));
InputSource is = new InputSource(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, reader);
reader.close();
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
addSchemasForServiceInfos(catalog, serviceList, opts, schemaCompiler, schemaCollection);
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JAXBDataBinding method addSchemasForServiceInfos.
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);
}
}
}
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JavaScriptContainer method execute.
@SuppressWarnings("unchecked")
public void execute() throws ToolException {
if (hasInfoOption()) {
return;
}
buildToolContext();
validate(context);
WSDLConstants.WSDLVersion version = getWSDLVersion();
String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
if (serviceList == null) {
serviceList = new ArrayList<>();
PluginLoader pluginLoader = PluginLoader.newInstance();
// for JavaScript generation, we always use JAX-WS.
FrontEndProfile frontend = pluginLoader.getFrontEndProfile("jaxws");
// Build the ServiceModel from the WSDLModel
if (version == WSDLConstants.WSDLVersion.WSDL11) {
AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
builder.setContext(context);
builder.setBus(getBus());
context.put(Bus.class, getBus());
builder.build(URIParserUtil.getAbsoluteURI(wsdlURL));
builder.customize();
Definition definition = builder.getWSDLModel();
context.put(Definition.class, definition);
builder.validate(definition);
WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
if (serviceName != null) {
List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
serviceList.addAll(services);
} else if (definition.getServices().size() > 0) {
serviceList = serviceBuilder.buildServices(definition);
} else {
serviceList = serviceBuilder.buildMockServices(definition);
}
} else {
// TODO: wsdl2.0 support
throw new ToolException("Only WSDL 1.1 supported");
}
}
if (serviceList.isEmpty()) {
throw new ToolException("Did not find any services in WSDL");
}
Map<String, InterfaceInfo> interfaces = new LinkedHashMap<>();
ServiceInfo service0 = serviceList.get(0);
SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
context.put(ToolConstants.PORTTYPE_MAP, interfaces);
context.put(ClassCollector.class, new ClassCollector());
WSDLToJavaScriptProcessor processor = new WSDLToJavaScriptProcessor();
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
validate(service);
processor.setEnvironment(context);
processor.process();
}
}
Aggregations