Search in sources :

Example 61 with Message

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

the class JavaToJSProcessor method getOutputFile.

protected File getOutputFile(File nameFromClz, String defaultOutputFile) {
    String output = (String) context.get(ToolConstants.CFG_OUTPUTFILE);
    String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
    if (dir == null) {
        dir = "./";
    }
    File result;
    if (output != null) {
        result = new File(output);
        if (!result.isAbsolute()) {
            result = new File(new File(dir), output);
        }
    } else {
        result = new File(new File(dir), defaultOutputFile);
    }
    if (nameFromClz != null) {
        result = nameFromClz;
    }
    // rename the exising wsdl file
    if (result.exists() && !result.renameTo(new File(result.getParent(), result.getName()))) {
        throw new ToolException(new Message("OUTFILE_EXISTS", LOG));
    }
    return result;
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File)

Example 62 with Message

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

the class Wrapper method isWrapperBeanClassNotExist.

public boolean isWrapperBeanClassNotExist() {
    try {
        Message msg = new Message("LOADING_WRAPPER_CLASS", LOG, getJavaClass().getFullClassName());
        LOG.log(Level.FINE, msg.toString());
        getWrapperClass();
        return false;
    } catch (ToolException e) {
        return true;
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException)

Example 63 with Message

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

the class ReflectionServiceFactoryBean method setFaultClassInfo.

private void setFaultClassInfo(OperationInfo o, Method selected) {
    Class<?>[] types = selected.getExceptionTypes();
    Map<FaultInfo, List<MessagePartInfo>> mpiMap = null;
    if (types.length > 0) {
        // early iterate over FaultInfo before cycling on exception types
        // as fi.getMessageParts() is very time-consuming due to elements
        // copy in ArrayList constructor
        mpiMap = new HashMap<>();
        for (FaultInfo fi : o.getFaults()) {
            mpiMap.put(fi, fi.getMessageParts());
        }
    }
    for (int i = 0; i < types.length; i++) {
        Class<?> exClass = types[i];
        Class<?> beanClass = getBeanClass(exClass);
        if (beanClass == null) {
            continue;
        }
        QName name = getFaultName(o.getInterface(), o, exClass, beanClass);
        for (Entry<FaultInfo, List<MessagePartInfo>> entry : mpiMap.entrySet()) {
            FaultInfo fi = entry.getKey();
            List<MessagePartInfo> mpis = entry.getValue();
            if (mpis.size() != 1) {
                Message message = new Message("NO_FAULT_PART", LOG, fi.getFaultName());
                LOG.log(Level.WARNING, message.toString());
            }
            for (MessagePartInfo mpi : mpis) {
                final String ns;
                if (mpi.isElement()) {
                    ns = mpi.getElementQName().getNamespaceURI();
                } else {
                    ns = mpi.getTypeQName().getNamespaceURI();
                }
                if (mpi.getConcreteName().getLocalPart().equals(name.getLocalPart()) && name.getNamespaceURI().equals(ns)) {
                    fi.setProperty(Class.class.getName(), exClass);
                    mpi.setTypeClass(beanClass);
                    sendEvent(Event.OPERATIONINFO_FAULT, o, exClass, fi);
                }
            }
        }
    }
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) XmlList(javax.xml.bind.annotation.XmlList)

Example 64 with Message

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

the class ClassUtils method compile.

public void compile(ToolContext context) throws ToolException {
    Compiler compiler = (Compiler) context.get(ToolConstants.COMPILER);
    if (compiler == null) {
        compiler = new Compiler();
    }
    if (context.isVerbose()) {
        compiler.setVerbose(true);
    }
    compiler.setEncoding((String) context.get(ToolConstants.CFG_ENCODING));
    if (context.get(ToolConstants.CFG_CLASSDIR) != null) {
        compiler.setOutputDir((String) context.get(ToolConstants.CFG_CLASSDIR));
    }
    String javaClasspath = System.getProperty("java.class.path");
    if (javaClasspath != null) {
        if (context.get(ToolConstants.CFG_OUTPUTDIR) != null) {
            compiler.setClassPath(javaClasspath + File.pathSeparatorChar + context.get(ToolConstants.CFG_OUTPUTDIR));
        } else {
            compiler.setClassPath(javaClasspath);
        }
    }
    String outPutDir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
    Set<String> dirSet = new HashSet<>();
    ClassCollector classCollector = context.get(ClassCollector.class);
    List<String> fileList = new ArrayList<>();
    Iterator<String> ite = classCollector.getGeneratedFileInfo().iterator();
    while (ite.hasNext()) {
        String fileName = ite.next();
        fileName = fileName.replace('.', File.separatorChar);
        String dirName = fileName.substring(0, fileName.lastIndexOf(File.separator) + 1);
        String path = outPutDir + File.separator + dirName;
        if (dirSet.add(path)) {
            File file = new File(path);
            if (file.isDirectory() && file.list() != null) {
                for (String str : file.list()) {
                    if (str.endsWith("java")) {
                        fileList.add(path + str);
                    } else {
                        // copy generated xml file or others to class directory
                        Path otherFile = Paths.get(path, str);
                        String suffix = "xml";
                        if (Files.isReadable(otherFile) && str.regionMatches(true, str.length() - suffix.length(), suffix, 0, suffix.length()) && context.get(ToolConstants.CFG_CLASSDIR) != null) {
                            String targetDir = (String) context.get(ToolConstants.CFG_CLASSDIR);
                            try {
                                Files.copy(otherFile, Files.createDirectories(Paths.get(targetDir, dirName)).resolve(str));
                            } catch (IOException e) {
                                Message msg = new Message("FAIL_TO_COPY_GENERATED_RESOURCE_FILE", LOG);
                                throw new ToolException(msg, e);
                            }
                        }
                    }
                }
                // JAXB plugins will generate extra files under the runtime directory
                // Those files can not be allocated into the ClassCollector
                File jaxbRuntime = new File(path, "runtime");
                if (jaxbRuntime.isDirectory() && jaxbRuntime.exists()) {
                    List<File> files = FileUtils.getFilesUsingSuffix(jaxbRuntime, ".java");
                    files.forEach(f -> fileList.add(f.toString()));
                }
            }
        }
    }
    if (!compiler.compileFiles(fileList.toArray(new String[0]))) {
        Message msg = new Message("FAIL_TO_COMPILE_GENERATE_CODES", LOG);
        throw new ToolException(msg);
    }
}
Also used : Path(java.nio.file.Path) Compiler(org.apache.cxf.common.util.Compiler) Message(org.apache.cxf.common.i18n.Message) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Example 65 with Message

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

the class JavaMethod method addParameter.

public void addParameter(JavaParameter param) {
    if (hasParameter(param.getName())) {
        JavaParameter paramInList = getParameter(param.getName());
        if (isEquiv(paramInList.getClassName(), param.getClassName()) && paramInList.isIN() || paramInList.isINOUT()) {
            // removeParameter(paramInList);
            replaceParameter(paramInList, param);
            return;
        }
        Message message = new Message("PARAMETER_ALREADY_EXIST", LOG, param.getName(), getName(), paramInList.getType(), param.getType());
        throw new ToolException(message);
    }
    if (param.getType() == null && param.getClassName() == null) {
        Message msg = new Message("FAIL_TO_CREATE_JAVA_PARAMETER", LOG, param.name, this.getName());
        throw new ToolException(msg);
    }
    param.setMethod(this);
    parameters.add(param);
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException)

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