Search in sources :

Example 6 with DescriptionInfo

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();
}
Also used : Policy(org.apache.neethi.Policy) QName(javax.xml.namespace.QName) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) Test(org.junit.Test)

Example 7 with DescriptionInfo

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;
}
Also used : UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) Document(org.w3c.dom.Document) URL(java.net.URL) Attr(org.w3c.dom.Attr)

Example 8 with DescriptionInfo

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;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo)

Example 9 with DescriptionInfo

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;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) BusException(org.apache.cxf.BusException)

Example 10 with DescriptionInfo

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;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo)

Aggregations

DescriptionInfo (org.apache.cxf.service.model.DescriptionInfo)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 QName (javax.xml.namespace.QName)5 Policy (org.apache.neethi.Policy)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)4 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)4 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)3 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)3 Binding (javax.wsdl.Binding)2 BindingOperation (javax.wsdl.BindingOperation)2 Definition (javax.wsdl.Definition)2 Message (javax.wsdl.Message)2 PortType (javax.wsdl.PortType)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2 Extensible (org.apache.cxf.service.model.Extensible)2 URL (java.net.URL)1 HashSet (java.util.HashSet)1