Hi Awanthika,

That was the one of the issues I was facing. I was able to resolve the
issues with help. Instead of using the maven assembly plugin to unpack the
dependencies of the component and include them in the jar that I am
running, I used the maven jar plugin and created the jar (I have given the
classpath prefix and mainClass).

I included the maven dependency plugin which copies the dependencies in to
the folder indicated by the classpath prefix.

I included the maven resources plugin which copies the resources in to the
folder indicated by output directory.

I copied the folder named "lib" which includes the dependency jars and the
folder named "config" which includes the resources such as the policy file
in to the folder containing the jar and ran command "java -jar (NAME).jar".

I have indicated the modifications below.

The plugins are as follows.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
            <source>${JDK_VERSION}</source>
            <target>${JDK_VERSION}</target>
            <excludes>

            </excludes>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>

<mainClass>org.wso2.dashboard.marketing.publish.data.Application</mainClass>
                    <classpathPrefix>lib/</classpathPrefix>
                </manifest>
            </archive>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.5.1</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>false</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>

<outputDirectory>${project.build.directory}/lib/</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>copy-resources-1</id>
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/target/config</outputDirectory>
                    <resources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <filtering>false</filtering>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

</plugins>

The code was changed as follows where the resources were referred.

System.setProperty("javax.net.ssl.trustStore", (new
File("./config/wso2carbon.jks")).getAbsolutePath());

options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy("./config/wso2MDPolicy.xml"));

Thanks for all the help.

Regards.


On Sat, Mar 21, 2015 at 4:43 PM, Awanthika Senarath <awanth...@wso2.com>
wrote:

> Hi Sabra,
>
> How are you running the jar?
>
> probably the issue is that your classpath is not set to get the security
> policy.
>
> Try setting the appropriate classpath parameters. if you are running the
> jar from the terminal you can refer to [1] as to how to set the classpath
> parameters
>
>
> [1]
> http://stackoverflow.com/questions/18413014/run-jar-from-command-line-and-specify-classpath
>
> regards
> Awanthika
>
>
>
> On Sat, Mar 21, 2015 at 10:19 AM, Sabra Ossen <sa...@wso2.com> wrote:
>
>> Hi,
>>
>> I have created a jar with dependencies using the maven assembly plugin in
>> order to push data to secure web service in WSO2 DSS.
>>
>> The code works fine when run in intelliJ idea, but when the jar is run I
>> get the following exception.
>>
>> java.lang.RuntimeException: Undefined 'Security policy namespace cannot
>> be null.' resource property
>> at
>> org.apache.rampart.RampartException.getMessage(RampartException.java:81)
>> at org.apache.rampart.RampartException.<init>(RampartException.java:41)
>> at org.apache.rampart.RampartException.<init>(RampartException.java:57)
>> at
>> org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:422)
>> at
>> org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:263)
>> at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
>> at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
>> at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
>> at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
>> at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
>> at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:427)
>> at
>> org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:278)
>> at
>> org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
>> at
>> org.wso2.dashboard.marketing.client.WSO2MarketingDashboardDataServiceStub.insertWebsiteVisitorsPerWeek(WSO2MarketingDashboardDataServiceStub.java:610)
>> at
>> org.wso2.dashboard.marketing.publish.data.DataPublisher.insertToWebsiteVisitorsWeeklyDB(DataPublisher.java:358)
>> at
>> org.wso2.dashboard.marketing.publish.data.DataPublisher.publishData(DataPublisher.java:46)
>> at
>> org.wso2.dashboard.marketing.publish.data.Application.main(Application.java:8)
>>
>> The pom is as follows.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <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>
>>
>>     <properties>
>>         <JDK_VERSION>1.6</JDK_VERSION>
>>         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>>         <axis2.version>1.6.1-wso2v9</axis2.version>
>>         <rampart.version>1.6.1-wso2v12</rampart.version>
>>     </properties>
>>
>>     <groupId>org.wso2.dashboard.marketing</groupId>
>>     <artifactId>DataAccess</artifactId>
>>     <version>1.0-SNAPSHOT</version>
>>     <packaging>jar</packaging>
>>
>>     <repositories>
>>         <repository>
>>             <id>codehaus</id>
>>             <url>http://repository.codehaus.org/org/codehaus</url>
>>         </repository>
>>
>>         <repository>
>>             <id>wso2.releases</id>
>>             <name>WSO2 Releases Repository</name>
>>             
>> <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
>>             <releases>
>>                 <enabled>true</enabled>
>>                 <updatePolicy>daily</updatePolicy>
>>                 <checksumPolicy>ignore</checksumPolicy>
>>             </releases>
>>         </repository>
>>
>>         <!-- WSO2 Snapshot artifact repository -->
>>         <repository>
>>             <id>wso2.snapshots</id>
>>             <name>WSO2 Snapshot Repository</name>
>>             
>> <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
>>             <snapshots>
>>                 <enabled>true</enabled>
>>                 <updatePolicy>daily</updatePolicy>
>>             </snapshots>
>>             <releases>
>>                 <enabled>false</enabled>
>>             </releases>
>>         </repository>
>>
>>         <repository>
>>             <id>wso2-nexus</id>
>>             <name>WSO2 internal Repository</name>
>>             
>> <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
>>             <releases>
>>                 <enabled>true</enabled>
>>                 <updatePolicy>daily</updatePolicy>
>>                 <checksumPolicy>ignore</checksumPolicy>
>>             </releases>
>>         </repository>
>>     </repositories>
>>
>>     <dependencies>
>>         <!--Google Analytics-->
>>         <dependency>
>>             <groupId>com.google.apis</groupId>
>>             <artifactId>google-api-services-analytics</artifactId>
>>             <version>v3-rev98-1.19.0</version>
>>         </dependency>
>>         <dependency>
>>             <groupId>com.google.oauth-client</groupId>
>>             <artifactId>google-oauth-client-jetty</artifactId>
>>             <version>1.19.0</version>
>>         </dependency>
>>
>>         <!--Sales Force-->
>>         <dependency>
>>             <groupId>com.force.api</groupId>
>>             <artifactId>force-wsc</artifactId>
>>             <version>33.0.1</version>
>>         </dependency>
>>
>>         <!--Jackson for JSON-->
>>         <dependency>
>>             <groupId>org.codehaus.jackson</groupId>
>>             <artifactId>jackson-mapper-asl</artifactId>
>>             <version>1.9.13</version>
>>         </dependency>
>>
>>         <dependency>
>>             <groupId>org.wso2.carbon</groupId>
>>             <artifactId>org.wso2.carbon.authenticator.stub</artifactId>
>>             <version>3.2.0</version>
>>         </dependency>
>>
>>         <!--Axis2 Dependencies-->
>>         <dependency>
>>             <groupId>org.apache.axis2</groupId>
>>             <artifactId>axis2</artifactId>
>>             <version>${axis2.version}</version>
>>         </dependency>
>>         <dependency>
>>             <groupId>org.apache.axis2</groupId>
>>             <artifactId>axis2-transport-local</artifactId>
>>             <version>${axis2.version}</version>
>>         </dependency>
>>         <dependency>
>>             <groupId>org.apache.axis2</groupId>
>>             <artifactId>axis2-transport-http</artifactId>
>>             <version>${axis2.version}</version>
>>         </dependency>
>>
>>         <!-- Apache Rampart-->
>>         <dependency>
>>             <groupId>org.apache.rampart</groupId>
>>             <artifactId>rampart-core</artifactId>
>>             <version>${rampart.version}</version>
>>             <exclusions>
>>                 <exclusion>
>>                     <groupId>org.apache.axis2</groupId>
>>                     <artifactId>addressing</artifactId>
>>                 </exclusion>
>>             </exclusions>
>>         </dependency>
>>
>>         <!--Rampart Dependencies-->
>>         <dependency>
>>             <groupId>org.apache.neethi</groupId>
>>             <artifactId>neethi</artifactId>
>>             <version>2.0.5</version>
>>         </dependency>
>>
>>         <!--SalesForce-->
>>         <dependency>
>>             <groupId>org.wso2.dashboard.marketing</groupId>
>>             <artifactId>SalesforceEnterprise</artifactId>
>>             <version>1.0</version>
>>         </dependency>
>>
>>         <!--Service Client-->
>>         <dependency>
>>             <groupId>org.wso2.dashboard.marketing</groupId>
>>             <artifactId>WebserviceClient</artifactId>
>>             <version>1.0</version>
>>         </dependency>
>>     </dependencies>
>>
>>     <build>
>>         <plugins>
>>             <plugin>
>>                 <groupId>org.apache.maven.plugins</groupId>
>>                 <artifactId>maven-compiler-plugin</artifactId>
>>                 <version>2.5.1</version>
>>                 <configuration>
>>                     <source>${JDK_VERSION}</source>
>>                     <target>${JDK_VERSION}</target>
>>                     <excludes>
>>                     </excludes>
>>                 </configuration>
>>             </plugin>
>>
>>             <plugin>
>>                 <artifactId>maven-assembly-plugin</artifactId>
>>                 <configuration>
>>                     <descriptorRefs>
>>                         <descriptorRef>jar-with-dependencies</descriptorRef>
>>                     </descriptorRefs>
>>                     <archive>
>>                         <manifest>
>>                             
>> <mainClass>org.wso2.dashboard.marketing.publish.data.Application</mainClass>
>>                         </manifest>
>>                     </archive>
>>                 </configuration>
>>             </plugin>
>>
>>         </plugins>
>>     </build>
>>
>> </project>
>>
>> The policy xml file is as follows.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"; 
>> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
>>  wsu:Id="UTOverTransport">
>>     <wsp:ExactlyOne>
>>         <wsp:All>
>>             <sp:TransportBinding 
>> xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
>>                 <wsp:Policy>
>>                     <sp:TransportToken>
>>                         <wsp:Policy>
>>                             <sp:HttpsToken RequireClientCertificate="false"/>
>>                         </wsp:Policy>
>>                     </sp:TransportToken>
>>                     <sp:AlgorithmSuite>
>>                         <wsp:Policy>
>>                             <sp:Basic256/>
>>                         </wsp:Policy>
>>                     </sp:AlgorithmSuite>
>>                     <sp:Layout>
>>                         <wsp:Policy>
>>                             <sp:Lax/>
>>                         </wsp:Policy>
>>                     </sp:Layout>
>>                     <sp:IncludeTimestamp/>
>>                 </wsp:Policy>
>>             </sp:TransportBinding>
>>             <sp:SignedSupportingTokens 
>> xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
>>                 <wsp:Policy>
>>                     <sp:UsernameToken 
>> sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"/>
>>                 </wsp:Policy>
>>             </sp:SignedSupportingTokens>
>>         </wsp:All>
>>     </wsp:ExactlyOne>
>> </wsp:Policy>
>>
>> This is the code used to connect to the web service.
>>
>> String epr = 
>> "https://10.224.144.179:9443/services/WSO2MarketingDashboardDataService";;
>> System.setProperty("javax.net.ssl.trustStore", (new 
>> File("./wso2carbon.jks")).getAbsolutePath());
>> System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
>>
>> ConfigurationContext ctx = ConfigurationContextFactory
>>       .createConfigurationContextFromFileSystem("/home/sabra/repository", 
>> null);
>> WSO2MarketingDashboardDataServiceStub stub = new 
>> WSO2MarketingDashboardDataServiceStub(ctx,epr);
>> ServiceClient client = stub._getServiceClient();
>> Options options = client.getOptions();
>> client.engageModule("rampart");
>> options.setUserName("admin");
>> options.setPassword("admin");
>>
>> options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, 
>> loadPolicy("./wso2MDPolicy.xml"));
>>
>> where loadPolicy is as follows.
>>
>> private static Policy loadPolicy(String path) throws Exception {
>>    InputStream resource = new FileInputStream(path);
>>    StAXOMBuilder builder = new StAXOMBuilder(resource);
>>    return PolicyEngine.getPolicy(builder.getDocumentElement());
>> }
>>
>> Any help on resolving or understanding this issue is highly appreciated.
>>
>> Thank you.
>> --
>> Sabra Ossen
>> *Software Engineering Intern*
>> Mobile : +94 (0) 775 837 356
>> sa...@wso2.com
>>
>> _______________________________________________
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Awanthika Senarath
> Software Engineer, WSO2 Inc.
> Mobile: +94717681791
>
>
>


-- 
Sabra Ossen
*Software Engineering Intern*
Mobile : +94 (0) 775 837 356
sa...@wso2.com
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to