Search in sources :

Example 6 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class WSDLToJavaScriptTest method testGeneration.

// just run with a minimum of fuss.
@Test
public void testGeneration() throws Exception {
    JavaScriptContainer container = new JavaScriptContainer(null);
    ToolContext context = new ToolContext();
    context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world.wsdl"));
    context.put(ToolConstants.CFG_OUTPUTDIR, output.toString());
    String[] prefixes = new String[1];
    prefixes[0] = "http://apache.org/hello_world_soap_http=murble";
    context.put(ToolConstants.CFG_JSPACKAGEPREFIX, prefixes);
    container.setContext(context);
    container.execute();
    // now we really want to check some results.
    Path path = FileSystems.getDefault().getPath(output.getPath(), "SOAPService_Test1.js");
    assertTrue(Files.isReadable(path));
    String javascript = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
    assertTrue(javascript.contains("xmlns:murble='http://apache.org/hello_world_soap_http'"));
    assertEquals("Number of '{' does not match number of '}' in generated JavaScript.", countChar(javascript, '{'), countChar(javascript, '}'));
}
Also used : Path(java.nio.file.Path) ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 7 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JavaToProcessorTest method testGetWSDLVersion.

@Test
public void testGetWSDLVersion() {
    processor.setEnvironment(new ToolContext());
    assertEquals(WSDLConstants.WSDLVersion.WSDL11, processor.getWSDLVersion());
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 8 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JaxwsServiceBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    JAXBContextCache.clearCaches();
    builder = new JaxwsServiceBuilder();
    builder.setBus(BusFactory.getDefaultBus());
    generator.setBus(builder.getBus());
    generator.setToolContext(new ToolContext());
    Bus b = builder.getBus();
    assertNotNull(b.getExtension(DestinationFactoryManager.class).getDestinationFactory("http://schemas.xmlsoap.org/soap/http"));
}
Also used : Bus(org.apache.cxf.Bus) ToolContext(org.apache.cxf.tools.common.ToolContext) JaxwsServiceBuilder(org.apache.cxf.jaxws.JaxwsServiceBuilder) Before(org.junit.Before)

Example 9 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class WADLToJava method main.

public static void main(String[] pargs) {
    System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
    CommandInterfaceUtils.commandCommonMain();
    WADLToJava w2j = new WADLToJava(pargs);
    try {
        w2j.run(new ToolContext());
    } catch (ToolException ex) {
        System.err.println();
        System.err.println("WADLToJava Error: " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    } catch (Exception ex) {
        System.err.println("WADLToJava Error: " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    }
    if (w2j.isExitOnFinish()) {
        System.exit(0);
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 10 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class WrapperStyleNameCollisionValidator method isValidOperation.

private boolean isValidOperation(OperationInfo operation) {
    ToolContext context = service.getProperty(ToolContext.class.getName(), ToolContext.class);
    boolean c = context.optionSet(ToolConstants.CFG_AUTORESOLVE);
    boolean valid = false;
    if (operation.getUnwrappedOperation() == null) {
        valid = true;
    }
    String operationName = operation.getName().getLocalPart();
    operationName = ProcessorUtil.mangleNameToVariableName(operationName);
    JAXWSBinding binding = operation.getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    binding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
    if (binding != null) {
        if (!binding.isEnableWrapperStyle()) {
            valid = true;
        } else if (binding.getMethodName() != null) {
            operationName = binding.getMethodName();
        }
    }
    valid |= checkBare(context, operationName);
    if (valid) {
        return true;
    }
    MessagePartInfo input = null;
    MessagePartInfo output = null;
    if (operation.getInput() != null && operation.getInput().getMessagePartsNumber() == 1) {
        input = operation.getInput().getFirstMessagePart();
    }
    if (operation.getOutput() != null && operation.getOutput().getMessagePartsNumber() == 1) {
        output = operation.getOutput().getFirstMessagePart();
    }
    if (!c) {
        Map<String, QName> names = new HashMap<>();
        if (input != null) {
            for (WrapperElement element : ProcessorUtil.getWrappedElement(context, input.getElementQName())) {
                String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getInput(), element);
                if (names.containsKey(mappedName) && (names.get(mappedName) == element.getSchemaTypeName() || names.get(mappedName).equals(element.getSchemaTypeName()))) {
                    handleErrors(names.get(mappedName), element);
                    return false;
                }
                names.put(mappedName, element.getSchemaTypeName());
            }
        }
        if (output != null) {
            List<WrapperElement> els = ProcessorUtil.getWrappedElement(context, output.getElementQName());
            if (els.size() > 1) {
                for (WrapperElement element : els) {
                    String mappedName = mapElementName(operation, operation.getUnwrappedOperation().getOutput(), element);
                    QName mn = names.get(mappedName);
                    if (names.containsKey(mappedName) && !(mn == element.getSchemaTypeName() || (mn != null && mn.equals(element.getSchemaTypeName())))) {
                        handleErrors(names.get(mappedName), element);
                        return false;
                    }
                    names.put(mappedName, element.getSchemaTypeName());
                }
            }
        }
    }
    return true;
}
Also used : WrapperElement(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.WrapperElement) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ToolContext(org.apache.cxf.tools.common.ToolContext) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

ToolContext (org.apache.cxf.tools.common.ToolContext)69 Test (org.junit.Test)45 URISyntaxException (java.net.URISyntaxException)35 File (java.io.File)23 ToolException (org.apache.cxf.tools.common.ToolException)13 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)7 WADLToJava (org.apache.cxf.tools.wadlto.WADLToJava)5 BufferedReader (java.io.BufferedReader)4 Method (java.lang.reflect.Method)4 URLClassLoader (java.net.URLClassLoader)4 QName (javax.xml.namespace.QName)4 Before (org.junit.Before)4 FileReader (java.io.FileReader)3 URI (java.net.URI)3 LinkedHashSet (java.util.LinkedHashSet)3 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 IOException (java.io.IOException)2 Writer (java.io.Writer)2