Search in sources :

Example 26 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class JaxWsServiceFactoryBean method bindOperation.

protected void bindOperation(OperationInfo op, Method method) {
    try {
        // Find the Async method which returns a Response
        Method responseMethod = ReflectionUtil.getDeclaredMethod(method.getDeclaringClass(), method.getName() + "Async", method.getParameterTypes());
        // Find the Async method whic has a Future & AsyncResultHandler
        List<Class<?>> asyncHandlerParams = Arrays.asList(method.getParameterTypes());
        // copy it to may it non-readonly
        asyncHandlerParams = new ArrayList<>(asyncHandlerParams);
        asyncHandlerParams.add(AsyncHandler.class);
        Method futureMethod = ReflectionUtil.getDeclaredMethod(method.getDeclaringClass(), method.getName() + "Async", asyncHandlerParams.toArray(new Class<?>[0]));
        getMethodDispatcher().bind(op, method, responseMethod, futureMethod);
    } catch (SecurityException e) {
        throw new ServiceConstructionException(e);
    } catch (NoSuchMethodException e) {
        getMethodDispatcher().bind(op, method);
    }
}
Also used : Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

Example 27 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class RMEndpoint method createService.

void createService(ProtocolVariation protocol) {
    ServiceInfo si = new ServiceInfo();
    si.setProperty(Schema.class.getName(), getSchema());
    QName serviceQName = new QName(protocol.getWSRMNamespace(), SERVICE_NAME);
    si.setName(serviceQName);
    buildInterfaceInfo(si, protocol);
    WrappedService service = new WrappedService(applicationEndpoint.getService(), serviceQName, si);
    Class<?> create = protocol.getCodec().getCreateSequenceType();
    try {
        JAXBContext ctx = JAXBContext.newInstance(PackageUtils.getPackageName(create), create.getClassLoader());
        service.setDataBinding(new JAXBDataBinding(ctx));
    } catch (JAXBException e) {
        throw new ServiceConstructionException(e);
    }
    service.setInvoker(servant);
    services.put(protocol, service);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) QName(javax.xml.namespace.QName) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

Example 28 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class ReflectionServiceFactoryBean method checkForElement.

protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) {
    SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(), getQualifyWrapperSchema());
    XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart());
    if (e != null) {
        mpi.setXmlSchema(e);
        return;
    }
    XmlSchema schema = si.getSchema();
    // cached element is now invalid
    si.setElement(null);
    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(mpi.getElementQName().getLocalPart());
    el.setNillable(true);
    XmlSchemaType tp = (XmlSchemaType) mpi.getXmlSchema();
    if (tp == null) {
        throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG, mpi.getName(), mpi.getMessageInfo().getName()));
    }
    el.setSchemaTypeName(tp.getQName());
    mpi.setXmlSchema(el);
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 29 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class ReflectionServiceFactoryBean method buildServiceFromClass.

protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG, getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;
    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }
    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());
    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();
    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());
    sendEvent(Event.SERVICE_SET, getService());
    createInterface(serviceInfo);
    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();
    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }
    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method) opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }
        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }
        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName) fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) ServiceModelSchemaValidator(org.apache.cxf.service.ServiceModelSchemaValidator) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) MimeSerializer(org.apache.cxf.databinding.source.mime.MimeSerializer) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 30 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class ReflectionServiceFactoryBean method validateSchemas.

private void validateSchemas(SchemaCollection xmlSchemaCollection) {
    final StringBuilder errorBuilder = new StringBuilder();
    XercesXsdValidationImpl v = new XercesXsdValidationImpl();
    v.validateSchemas(xmlSchemaCollection.getXmlSchemaCollection(), new DOMErrorHandler() {

        public boolean handleError(DOMError error) {
            errorBuilder.append(error.getMessage());
            LOG.warning(error.getMessage());
            return true;
        }
    });
    if (errorBuilder.length() > 0) {
        throw new ServiceConstructionException(new Message("XSD_VALIDATION_ERROR", LOG, errorBuilder.toString()));
    }
}
Also used : DOMErrorHandler(org.w3c.dom.DOMErrorHandler) Message(org.apache.cxf.common.i18n.Message) DOMError(org.w3c.dom.DOMError) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

Aggregations

ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)32 Message (org.apache.cxf.common.i18n.Message)10 Endpoint (org.apache.cxf.endpoint.Endpoint)8 Method (java.lang.reflect.Method)7 QName (javax.xml.namespace.QName)7 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 BusException (org.apache.cxf.BusException)5 Annotation (java.lang.annotation.Annotation)4 Collection (java.util.Collection)4 Bus (org.apache.cxf.Bus)4 EndpointException (org.apache.cxf.endpoint.EndpointException)4 IOException (java.io.IOException)3 Application (javax.ws.rs.core.Application)3 Provider (javax.ws.rs.ext.Provider)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 MalformedURLException (java.net.MalformedURLException)2