Search in sources :

Example 26 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class JaxWsServiceConfiguration method isOperation.

@Override
public Boolean isOperation(final Method method) {
    if (Object.class.equals(method.getDeclaringClass())) {
        return false;
    }
    if (method.getDeclaringClass() == implInfo.getSEIClass()) {
        WebMethod wm = method.getAnnotation(WebMethod.class);
        if (wm != null && wm.exclude()) {
            Message message = new Message("WEBMETHOD_EXCLUDE_NOT_ALLOWED", LOG, method.getName());
            throw new JaxWsConfigurationException(message);
        }
    }
    Class<?> implClz = implInfo.getImplementorClass();
    Method m = getDeclaredMethod(implClz, method);
    if (m != null) {
        WebMethod wm = m.getAnnotation(WebMethod.class);
        if (wm != null && wm.exclude()) {
            return Boolean.FALSE;
        }
    }
    if (isWebMethod(m)) {
        return true;
    }
    return isWebMethod(getDeclaredMethod(method));
}
Also used : WebMethod(javax.jws.WebMethod) JaxWsConfigurationException(org.apache.cxf.jaxws.JaxWsConfigurationException) Message(org.apache.cxf.common.i18n.Message) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod)

Example 27 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class EndpointImpl method createBinding.

final void createBinding(BindingInfo bi) throws EndpointException {
    if (null != bi) {
        String namespace = bi.getBindingId();
        try {
            final BindingFactory bf = bus.getExtension(BindingFactoryManager.class).getBindingFactory(namespace);
            if (null == bf) {
                Message msg = new Message("NO_BINDING_FACTORY", BUNDLE, namespace);
                throw new EndpointException(msg);
            }
            binding = bf.createBinding(bi);
        } catch (BusException ex) {
            throw new EndpointException(ex);
        }
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) BusException(org.apache.cxf.BusException) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 28 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AegisXMLStreamDataReader method read.

/**
 * {@inheritDoc}
 */
public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception {
    setupReaderPosition(reader);
    ElementReader elReader = new ElementReader(reader);
    if (elReader.isXsiNil()) {
        elReader.readToEnd();
        return null;
    }
    AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType);
    if (type == null) {
        throw new DatabindingException(new Message("NO_MAPPING", LOG));
    }
    return type.readObject(elReader, context);
}
Also used : Message(org.apache.cxf.common.i18n.Message) AegisType(org.apache.cxf.aegis.type.AegisType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 29 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class SchemaJavascriptBuilder method generateCodeForSchema.

public String generateCodeForSchema(XmlSchema schema) {
    xmlSchema = schema;
    code = new StringBuilder();
    code.append("//\n");
    code.append("// Definitions for schema: ").append(schema.getTargetNamespace());
    if (schema.getSourceURI() != null) {
        code.append("\n//  ").append(schema.getSourceURI());
    }
    code.append("\n//\n");
    Map<QName, XmlSchemaType> schemaTypes = schema.getSchemaTypes();
    for (Map.Entry<QName, XmlSchemaType> e : schemaTypes.entrySet()) {
        XmlSchemaType type = e.getValue();
        if (type instanceof XmlSchemaComplexType) {
            try {
                XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
                if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) {
                    complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
                    complexTypeSerializerFunction(complexType.getQName(), complexType);
                    domDeserializerFunction(complexType.getQName(), complexType);
                }
            } catch (UnsupportedConstruct usc) {
                LOG.warning(usc.toString());
                // it could be empty, but the style checker
                continue;
            // would complain.
            }
        } else if (type instanceof XmlSchemaSimpleType) {
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
            if (XmlSchemaUtils.isEumeration(simpleType)) {
                List<String> values = XmlSchemaUtils.enumeratorValues(simpleType);
                code.append("//\n");
                code.append("// Simple type (enumeration) ").append(simpleType.getQName()).append('\n');
                code.append("//\n");
                for (String value : values) {
                    code.append("// - ").append(value).append('\n');
                }
            }
        }
    }
    for (Map.Entry<QName, XmlSchemaElement> e : schema.getElements().entrySet()) {
        XmlSchemaElement element = e.getValue();
        try {
            if (element.getSchemaTypeName() == null && element.getSchemaType() == null) {
                Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), element.getSchemaTypeName(), schema.getTargetNamespace());
                LOG.warning(message.toString());
                continue;
            }
            XmlSchemaType type;
            if (element.getSchemaType() != null) {
                type = element.getSchemaType();
            } else {
                type = schema.getTypeByName(element.getSchemaTypeName());
            }
            if (!(type instanceof XmlSchemaComplexType)) {
                // we never make classes for simple type.
                continue;
            }
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
            // element.
            if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) {
                complexTypeConstructorAndAccessors(element.getQName(), complexType);
                complexTypeSerializerFunction(element.getQName(), complexType);
                domDeserializerFunction(element.getQName(), complexType);
            }
        } catch (UnsupportedConstruct usc) {
            LOG.warning(usc.getMessage());
            // it could be empty, but the style checker
            continue;
        // would complain.
        }
    }
    String returnValue = code.toString();
    LOG.finer(returnValue);
    return returnValue;
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) List(java.util.List) Map(java.util.Map)

Example 30 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class DynamicClientFactory method createClient.

public Client createClient(String wsdlUrl, QName service, ClassLoader classLoader, QName port, List<String> bindingFiles) {
    if (classLoader == null) {
        classLoader = Thread.currentThread().getContextClassLoader();
    }
    LOG.log(Level.FINE, "Creating client from WSDL " + wsdlUrl);
    WSDLServiceFactory sf = (service == null) ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, service));
    sf.setAllowElementRefs(allowRefs);
    Service svc = sf.create();
    // all SI's should have the same schemas
    SchemaCollection schemas = svc.getServiceInfos().get(0).getXmlSchemaCollection();
    SchemaCompiler compiler = createSchemaCompiler();
    InnerErrorListener listener = new InnerErrorListener(wsdlUrl);
    Object elForRun = ReflectionInvokationHandler.createProxyWrapper(listener, JAXBUtils.getParamClass(compiler, "setErrorListener"));
    compiler.setErrorListener(elForRun);
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    hackInNewInternalizationLogic(compiler, catalog);
    addSchemas(compiler.getOptions(), compiler, svc.getServiceInfos(), schemas);
    addBindingFiles(bindingFiles, compiler);
    applySchemaCompilerOptions(compiler);
    S2JJAXBModel intermediateModel = compiler.bind();
    listener.throwException();
    JCodeModel codeModel = intermediateModel.generateCode(null, elForRun);
    StringBuilder sb = new StringBuilder();
    boolean firstnt = false;
    for (Iterator<JPackage> packages = codeModel.packages(); packages.hasNext(); ) {
        JPackage jpackage = packages.next();
        if (!isValidPackage(jpackage)) {
            continue;
        }
        if (firstnt) {
            sb.append(':');
        } else {
            firstnt = true;
        }
        sb.append(jpackage.name());
    }
    JAXBUtils.logGeneratedClassNames(LOG, codeModel);
    String packageList = sb.toString();
    // our hashcode + timestamp ought to be enough.
    String stem = toString() + "-" + System.currentTimeMillis();
    File src = new File(tmpdir, stem + "-src");
    if (!src.mkdir()) {
        throw new IllegalStateException("Unable to create working directory " + src.getPath());
    }
    try {
        Object writer = JAXBUtils.createFileCodeWriter(src);
        codeModel.build(writer);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to write generated Java files for schemas: " + e.getMessage(), e);
    }
    File classes = new File(tmpdir, stem + "-classes");
    if (!classes.mkdir()) {
        throw new IllegalStateException("Unable to create working directory " + classes.getPath());
    }
    StringBuilder classPath = new StringBuilder();
    try {
        setupClasspath(classPath, classLoader);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    List<File> srcFiles = FileUtils.getFilesRecurseUsingSuffix(src, ".java");
    if (!srcFiles.isEmpty() && !compileJavaSrc(classPath.toString(), srcFiles, classes.toString())) {
        LOG.log(Level.SEVERE, new Message("COULD_NOT_COMPILE_SRC", LOG, wsdlUrl).toString());
    }
    FileUtils.removeDir(src);
    final URL[] urls;
    try {
        urls = new URL[] { classes.toURI().toURL() };
    } catch (MalformedURLException mue) {
        throw new IllegalStateException("Internal error; a directory returns a malformed URL: " + mue.getMessage(), mue);
    }
    final ClassLoader cl = ClassLoaderUtils.getURLClassLoader(urls, classLoader);
    JAXBContext context;
    Map<String, Object> contextProperties = jaxbContextProperties;
    if (contextProperties == null) {
        contextProperties = Collections.emptyMap();
    }
    try {
        if (StringUtils.isEmpty(packageList)) {
            context = JAXBContext.newInstance(new Class[0], contextProperties);
        } else {
            context = JAXBContext.newInstance(packageList, cl, contextProperties);
        }
    } catch (JAXBException jbe) {
        throw new IllegalStateException("Unable to create JAXBContext for generated packages: " + jbe.getMessage(), jbe);
    }
    JAXBDataBinding databinding = new JAXBDataBinding();
    databinding.setContext(context);
    svc.setDataBinding(databinding);
    ClientImpl client = new DynamicClientImpl(bus, svc, port, getEndpointImplFactory(), cl);
    ServiceInfo svcfo = client.getEndpoint().getEndpointInfo().getService();
    // Setup the new classloader!
    ClassLoaderUtils.setThreadContextClassloader(cl);
    TypeClassInitializer visitor = new TypeClassInitializer(bus, svcfo, intermediateModel, allowWrapperOps());
    visitor.walk();
    // delete the classes files
    FileUtils.removeDir(classes);
    return client;
}
Also used : MalformedURLException(java.net.MalformedURLException) Message(org.apache.cxf.common.i18n.Message) JAXBContext(javax.xml.bind.JAXBContext) SchemaCompiler(org.apache.cxf.common.jaxb.JAXBUtils.SchemaCompiler) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) URLClassLoader(java.net.URLClassLoader) S2JJAXBModel(org.apache.cxf.common.jaxb.JAXBUtils.S2JJAXBModel) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) JAXBException(javax.xml.bind.JAXBException) JPackage(org.apache.cxf.common.jaxb.JAXBUtils.JPackage) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) JCodeModel(org.apache.cxf.common.jaxb.JAXBUtils.JCodeModel) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) JDefinedClass(org.apache.cxf.common.jaxb.JAXBUtils.JDefinedClass) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

Message (org.apache.cxf.common.i18n.Message)201 ToolException (org.apache.cxf.tools.common.ToolException)69 IOException (java.io.IOException)45 QName (javax.xml.namespace.QName)42 Fault (org.apache.cxf.interceptor.Fault)34 XMLStreamException (javax.xml.stream.XMLStreamException)27 JAXBException (javax.xml.bind.JAXBException)23 ArrayList (java.util.ArrayList)19 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)17 Element (org.w3c.dom.Element)17 File (java.io.File)16 WSDLException (javax.wsdl.WSDLException)15 Method (java.lang.reflect.Method)14 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)13 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)12 InputStream (java.io.InputStream)11 HashMap (java.util.HashMap)11 List (java.util.List)11 Map (java.util.Map)11 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)11