use of org.apache.cxf.service.model.DescriptionInfo in project cxf by apache.
the class ReferenceResolverTest method testLocalServiceModelReferenceResolver.
@Test
public void testLocalServiceModelReferenceResolver() {
DescriptionInfo di = control.createMock(DescriptionInfo.class);
PolicyBuilder builder = control.createMock(PolicyBuilder.class);
LocalServiceModelReferenceResolver resolver = new LocalServiceModelReferenceResolver(di, builder);
List<UnknownExtensibilityElement> extensions = new ArrayList<>();
EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
control.replay();
assertNull(resolver.resolveReference("A"));
control.verify();
control.reset();
UnknownExtensibilityElement extension = control.createMock(UnknownExtensibilityElement.class);
extensions.add(extension);
EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
Element e = control.createMock(Element.class);
EasyMock.expect(extension.getElement()).andReturn(e).times(2);
QName qn = new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY);
EasyMock.expect(extension.getElementType()).andReturn(qn).anyTimes();
EasyMock.expect(e.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_ID_ATTR_NAME)).andReturn("A");
Policy p = control.createMock(Policy.class);
EasyMock.expect(builder.getPolicy(e)).andReturn(p);
control.replay();
assertSame(p, resolver.resolveReference("A"));
control.verify();
}
use of org.apache.cxf.service.model.DescriptionInfo in project cxf by apache.
the class PolicyAnnotationListener method addPolicy.
private Element addPolicy(ServiceInfo service, Policy p, Class<?> cls, String defName) {
String uri = p.uri();
String ns = Constants.URI_POLICY_NS;
if (p.includeInWSDL()) {
Element element = loadPolicy(uri, defName);
if (element == null) {
return null;
}
// might have been updated on load policy
uri = getPolicyId(element);
ns = element.getNamespaceURI();
if (service.getDescription() == null && cls != null) {
service.setDescription(new DescriptionInfo());
URL u = cls.getResource("/");
if (u != null) {
service.getDescription().setBaseURI(u.toString());
}
}
// and just create the policy reference.
if (!isExistsPolicy(service.getDescription().getExtensors().get(), uri)) {
UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
uee.setElement(element);
uee.setRequired(true);
uee.setElementType(DOMUtils.getElementQName(element));
service.getDescription().addExtensor(uee);
}
uri = "#" + uri;
}
Document doc = DOMUtils.getEmptyDocument();
Element el = doc.createElementNS(ns, "wsp:" + Constants.ELEM_POLICY_REF);
Attr att = doc.createAttributeNS(null, "URI");
att.setValue(uri);
el.setAttributeNodeNS(att);
return el;
}
use of org.apache.cxf.service.model.DescriptionInfo in project cxf by apache.
the class WSDLServiceBuilder method buildServices.
public List<ServiceInfo> buildServices(Definition d) {
DescriptionInfo description = new DescriptionInfo();
if (recordOriginal) {
description.setProperty(WSDL_DEFINITION, d);
}
description.setName(d.getQName());
description.setBaseURI(d.getDocumentBaseURI());
copyExtensors(description, d.getExtensibilityElements());
copyExtensionAttributes(description, d);
List<ServiceInfo> serviceList = new ArrayList<>();
for (java.util.Iterator<QName> ite = CastUtils.cast(d.getServices().keySet().iterator()); ite.hasNext(); ) {
QName qn = ite.next();
serviceList.addAll(buildServices(d, qn, null, description));
}
return serviceList;
}
use of org.apache.cxf.service.model.DescriptionInfo in project cxf by apache.
the class WSDLServiceBuilder method buildEndpoint.
public EndpointInfo buildEndpoint(ServiceInfo service, BindingInfo bi, Port port) {
List<?> elements = port.getExtensibilityElements();
String ns = null;
DestinationFactory factory = null;
EndpointInfo ei = null;
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
ns = el.getElementType().getNamespaceURI();
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
if (factory != null) {
break;
}
}
if (factory == null) {
ns = ((ExtensibilityElement) elements.get(0)).getElementType().getNamespaceURI();
}
}
if (factory == null) {
// get the transport id from bindingInfo
elements = port.getBinding().getExtensibilityElements();
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
if (el instanceof SOAPBinding) {
ns = ((SOAPBinding) el).getTransportURI();
break;
} else if (el instanceof SOAP12Binding) {
ns = ((SOAP12Binding) el).getTransportURI();
break;
// TODO: this is really ugly, but how to link between
// this binding and this transport ?
}
}
}
if (ns == null) {
if (ignoreUnknownBindings) {
return null;
}
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("MISSING_DESTINATION_FACTORY", LOG, port.getName());
throw new WSDLRuntimeException(msg);
}
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
}
if (factory instanceof WSDLEndpointFactory) {
WSDLEndpointFactory wFactory = (WSDLEndpointFactory) factory;
ei = wFactory.createEndpointInfo(bus, service, bi, port.getExtensibilityElements());
}
if (ei == null) {
ei = new EndpointInfo(service, ns);
}
copyDocumentation(ei, port);
ei.setName(new QName(service.getName().getNamespaceURI(), port.getName()));
ei.setBinding(bi);
copyExtensors(ei, port.getExtensibilityElements());
copyExtensionAttributes(ei, port);
service.addEndpoint(ei);
DescriptionInfo d = service.getDescription();
if (null != d) {
d.getDescribed().add(ei);
}
return ei;
}
use of org.apache.cxf.service.model.DescriptionInfo in project cxf by apache.
the class WSDLServiceBuilder method buildMockService.
public ServiceInfo buildMockService(Definition def, PortType p) {
DescriptionInfo description = new DescriptionInfo();
if (recordOriginal) {
description.setProperty(WSDL_DEFINITION, def);
}
description.setName(def.getQName());
description.setBaseURI(def.getDocumentBaseURI());
copyExtensors(description, def.getExtensibilityElements());
copyExtensionAttributes(description, def);
ServiceInfo service = new ServiceInfo();
service.setDescription(description);
if (recordOriginal) {
service.setProperty(WSDL_DEFINITION, def);
}
getSchemas(def, service);
service.setProperty(WSDL_SCHEMA_ELEMENT_LIST, this.schemaList);
buildInterface(service, p);
return service;
}
Aggregations