1

using wsdl2java and cxf-codegen-plugin in eclipse i generated the client code for the WSDL file. but i cant run the client due to SecurityException: Prohibited package name: java.util.xsd.

any way to solve this?

the Exception was like this.

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.util.xsd at java.lang.ClassLoader.preDefineClass(ClassLoader.java:649) at java.lang.ClassLoader.defineClass(ClassLoader.java:785) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:266) at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:390) at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:371) at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480) at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306) at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88) at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70) at java.lang.Class.initAnnotationsIfNecessary(Class.java:3098) at java.lang.Class.getAnnotation(Class.java:3057) at com.sun.xml.internal.ws.model.RuntimeModeler$1.run(RuntimeModeler.java:156) at com.sun.xml.internal.ws.model.RuntimeModeler$1.run(RuntimeModeler.java:154) at java.security.AccessController.doPrivileged(Native Method) at com.sun.xml.internal.ws.model.RuntimeModeler.getPrivClassAnnotation(RuntimeModeler.java:154) at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:190) at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:672) at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:660) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:329) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:312) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:294) at javax.xml.ws.Service.getPort(Service.java:119) at org.wso2.carbon.statistics.services.StatisticsAdmin.getStatisticsAdminHttpsSoap11Endpoint(StatisticsAdmin.java:101) at test1.StatisticsAdminLibrary.(StatisticsAdminLibrary.java:41) at test1.StatisticsAdminLibrary.main(StatisticsAdminLibrary.java:204)

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test1</groupId>
    <artifactId>test1</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cxf.version>2.2.3</cxf.version>
    </properties>   

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>1.2.13</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-impl</artifactId>
            <version>1.2.13</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.neethi</groupId>
            <artifactId>neethi</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-transport-local</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-transport-http</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.schema</groupId>
            <artifactId>XmlSchema</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>ST4</artifactId>
            <version>4.0.7</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>2.7.7</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>                         
                            <wsdlRoot>${basedir}/src/main/resources</wsdlRoot>
                            <includes>
                                <include>*.wsdl</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.googlecode.robotframework-maven-plugin</groupId>
                <artifactId>robotframework-maven-plugin</artifactId>
                <version>1.1.2</version>

                <configuration>
                    <extraPathDirectories>                      
                    </extraPathDirectories>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

wsdl file

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • 1
    Welcome to StackOverflow. Please edit your question with more information. For example, you definitely want to include the code that you already have. So that I, and others, can run the code and get the same error on the same line as you got. – old-ufo May 23 '14 at 06:09
  • Attach your WSDL file. How do you generate code? Attach pom.xml fragment if you use Maven or command if you generate with wsdl2java. Maybe your WSDL contains strange namespaces and this translates into forbidden package names. – bary May 23 '14 at 09:54
  • thanks for the guide lines. This exception occur only some wsdl only. – user1541368 May 23 '14 at 10:23
  • How many WSDL files do you have in ${basedir}/src/main/resources? Only the one that you linked form this github? Not related question - why do you use at the same time both axis2 and cxf? – bary May 23 '14 at 10:56
  • no. currently i had 6 wsdl. but without this wsdl it is ok. when i put this wsdl to the directory then it getting that exception. – user1541368 May 23 '14 at 13:09

2 Answers2

1

The same happened to me. Probably, on the wsdl that is causing you trouble, you have a reference to one or more namespaces whose name start with the string "java:..." These namespaces are producing the packages whose name start with java....

In order to fix it, you have to put one element like this in the execution/configuration/extraargs element of your pom.xml file, for each namespace that starts with "java:... "

<extraarg>-p</extraarg>                                        
<extraarg>java:...=yourpackagename</extraarg> 
Andres
  • 10,561
  • 4
  • 45
  • 63
  • In my case, a WSDL had a reference to the "http://util.java" namespace, which caused this problem. The argument on the left hand side has to equal the namespace exactly in order for this mapping to work! – Logan Pickup Aug 03 '16 at 23:22
0

I thought I would share my solution for a gradle.build:

buildscript {
ext {
    springBootVersion = '1.5.1.RELEASE'
}
repositories {
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    classpath("no.nils:wsdl2java:0.10")
  }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: "no.nils.wsdl2java"

// Prevents the boot packager from requiring a main class
bootRepackage {
    bootRepackage.enabled = false
}

jar {
    baseName = 'JAR-NAME'
    version = '1.0.0-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

// Generate sources off ccds wsdls
wsdl2java {
    generatedWsdlDir = file("$projectDir/src/generated/java")
    wsdlDir = file("$projectDir/src/main/resources/wsdl")
    stabilizeAndMergeObjectFactory = true
    wsdlsToGenerate = [
        // These foo wsdl files make a reference to util.java and generated classes with package java.util.xsd
        // The first argument to each renames that package to avoid security exceptions

        // foo version
        ['-xjc','-p', 'http://util.java/xsd=com.foo.java.util.xsd','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/foo/wsdl-catalog.wsdl")],
        ['-xjc','-p', 'http://util.java/xsd=com.foo.java.util.xsd','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/foo/wsdl-inventory.wsdl")],
        ['-xjc','-p', 'http://util.java/xsd=com.foo.java.util.xsd','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/foo/wsdl-customer.wsdl")],
        ['-xjc','-p', 'http://util.java/xsd=com.foo.java.util.xsd','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/foo/wsdl-entity.wsdl")],

        // Does not require renaming
        ['-xjc','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/foo/wsdl-workflow.wsdl")],

        // bar version
        ['-xjc','-b', file("$wsdlDir/binding.xml"), file("$wsdlDir/bar/wsdl-billing.wsdl")]
    ]
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
}
Bret Hodgson
  • 113
  • 1
  • 7