wsdl2java generates null pointer exception apache cxf - cxf

stacktrace of the exception
While generating the java client from the wsdl I am getting the above error.
I have used the binding file to solve the duplicate name errors and missing schema declaration errors
gradle task
cxf version is 3.0.0
task wsdl2java3(type: JavaExec) {
ext {
outputDir = file("$jaxbOutputDir")
}
systemProperties = ['javax.xml.accessExternalSchema': 'file' , 'file.encoding':'UTF8']
outputs.upToDateWhen { false }
outputs.dir outputDir
main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
classpath = project.configurations.cxf
args '-d', outputDir
ar`enter code here`gs '-client'
args '-verbose'
args '-mark-generated'
args '-p',"com.niloosoft.directorymanagementservice"
args "https://hunterdirectory.hunterhrms.com/DirectoryManagementService.svc?wsdl"
doLast {
println "----- cxf jaxb2 files generated -----"
}
}
binding file used
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="https://huntercards.hunterhrms.com/HunterCards.svc?xsd=xsd2" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Type" />
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation=" https://huntercards.hunterhrms.com/HunterCards.svc?xsd=xsd13" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Type" />
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation=" https://huntercards.hunterhrms.com/HunterCards.svc?xsd=xsd3" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Type" />
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
<globalBindings>
<xjc:simple />
</globalBindings>
<jaxb:bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</jaxb:bindings>
<jaxb:bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</jaxb:bindings>
<jaxb:bindings scd="~xsd:group">
<class name="GroupType"/>
</jaxb:bindings>
<jaxb:bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</jaxb:bindings>
<jaxb:bindings scd="~xsd:element">
<class name="ElementType"/>
</jaxb:bindings>
<jaxb:bindings scd="~xsd:attribute">
<class name="attributeType"/>
</jaxb:bindings>
</jaxb:bindings>
Thanks for the help

Related

Running parallel Testng tests in Selenium

I have a BaseClass which has #BeforeSuite method that takes browser and other login parameters from xml. I want to run 2 parallel tests with different parameters. Since i am using parameters in #BeforeSuite so it takes values only once and not running any parallel execution. I cannot use parameters in #BeforeTest or #BeforeMethod or #BeforeClass as I need to use these parameters only once for each test and i have multiple test cases in each class.
My xml is as below;
<listeners>
<listener class-name="Utility.Listeners" />
</listeners>
<test name="Tests1" >
<parameter name="Browser" value="chrome" />
<parameter name="username" value="d1" />
<parameter name="password" value="P1" />
<parameter name="Brand" value="TC" />
<groups>
<run>
<include name="NatP" />
</run>
</groups>
<classes >
<class name="Maven.Dashboard"/>
<class name="Maven.TopBottomWidget"/>
<class name="Maven.Dashboard_BE"/>
</classes>
</test>
<parameter name="Browser" value="chrome" />
<parameter name="username" value="d1K" />
<parameter name="password" value="P1K" />
<parameter name="Brand" value="TCK" />
<groups>
<run>
<include name="NatP" />
</run>
</groups>
<classes >
<class name="Maven.Dashboard"/>
<class name="Maven.TopBottomWidget"/>
<class name="Maven.Dashboard_BE"/>
</classes>
</test>
You could try programmatic execution of testng by using the below code. You have to pass the parameters as maven run time arguments like below,
mvn clean install exec:java "-Dexec.mainClass=org.package.Test" "-DskipTests" "-Dexec.classpathScope=test" "-DBrowser=chrome,firefox"
The Test class is present inside src/test/java/, hence the classpathScope is mentioned as test in the above command. Also using the above maven command we are executing the main function of the Test class. This main method will in turn trigger the testng execution. The main method parse the existing testng XML file and add the arguments as parameters to each test. Each test will be run parallel with the thread size equal to the number of arguments you pass.
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.testng.TestNG;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class Test {
public static void main(String[] args) throws Exception {
List<String> browserList = StringUtils.isEmpty(System.
getProperty("Browser")) ? new ArrayList<>() :
Arrays.asList(System.getProperty("Browser").split(","));
TestNG tng = new TestNG();
File initialFile = new File("testng.xml");
InputStream inputStream = FileUtils.openInputStream(initialFile);
Parser p = new Parser(inputStream);
List<XmlSuite> suites = p.parseToList();
List<XmlSuite> modifiedSuites = new ArrayList<>();
for (XmlSuite suite : suites) {
XmlSuite modifiedSuite = new XmlSuite();
modifiedSuite.setParallel(suite.getParallel());
modifiedSuite.setThreadCount(browserList.size());
modifiedSuite.setName(suite.getName());
modifiedSuite.setListeners(suite.getListeners());
List<XmlTest> tests = suite.getTests();
for (XmlTest test : tests) {
for (int i = 0; i < browserList.size(); i++) {
XmlTest modifedtest = new XmlTest(modifiedSuite);
HashMap<String, String> parametersMap = new HashMap<>();
parametersMap.put("browser", browserList.get(i));
modifedtest.setParameters(parametersMap);
modifedtest.setXmlClasses(test.getXmlClasses());
}
}
modifiedSuites.add(modifiedSuite);
}
inputStream.close();
tng.setXmlSuites(modifiedSuites);
tng.run();
}
}

How to show grouping of Test methods in Extent reports based on TEST groups

Please refer to the sample testng.xml file below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Main Test Suite" verbose="2">
<test name="Sample registration tests">
<classes>
<class name="com.Practice.PracticeTest1" />
</classes>
</test>
<test name="Sample login tests">
<classes>
<class name="com.Practice.PracticeTest2" />
</classes>
</test>
</suite>
The file contains 2 Test Groups named Sample registration tests and Sample login tests and under that 1 test class in each group. Now I have configured Extent reports for my project and when running the reports are coming fine. But all the test methods in the 2 classes are coming sequentially.
Report screenshot
I want to show the test methods grouped under the Test groups. Like
all the methods of PracticeTest1 test class will come under Sample registration tests Test group and like that.
Actually You're not grouping tests by the meanings of TestNG in your .xml, You're just naming them. To group tests add argument 'groups' under #Test annotation, like this:
public class Test1 {
#Test(groups = { "functest", "checkintest" })
public void testMethod1() {
}
#Test(groups = {"functest", "checkintest"} )
public void testMethod2() {
}
#Test(groups = { "functest" })
public void testMethod3() {
}
}
And then in .xml configure your test run:
<test name="Test1">
<groups>
<run>
<include name="functest"/>
</run>
</groups>
<classes>
<class name="example1.Test1"/>
</classes>
</test>
For more info about grouping Your tests visit
http://testng.org/doc/documentation-main.html

Apache camel how to insert map value to data base using sql component

Apache camel how to insert map value to data base using SQL component
My Class file:
public class PolluxDataController {
List<PolluxData> stationsMasterList=new ArrayList<PolluxData>();
List<PolluxData> stationProccessedList=new ArrayList<PolluxData>();
Map<String,Object> stationMap=new HashMap<String,Object>();
#SuppressWarnings("unchecked")
public Map<String, Object> processPolluxData(Exchange exchange) throws Exception {
stationsMasterList= (List<PolluxData>) exchange.getIn().getBody();
for (PolluxData value:stationsMasterList){
System.out.println(value.getStationCode() +","+value.getStationShortDescription());
stationMap.put("id",value.getStationCode());
stationMap.put("ltr", value.getStationShortDescription());
}
return stationMap;
}
sql.properties file is:
sql.insertNewRecord=INSERT INTO GSI_DEVL.POLLUX_DATA(STID,CLLTR) VALUES(:#id,#ltr)
Context.xml is
<!-- configure the Camel SQL component to use the JDBC data source -->
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="polluxDataController" id="polluxDataController" class="com.nielsen.polluxloadspring.controller.PolluxDataController" />
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
<!-- use Camel property placeholder loaded from the given file -->
<propertyPlaceholder id="placeholder" location="classpath:sql.properties" />
<camel:route id="bindy-csv-marhalling-unmarshalling-exmaple" autoStartup="true">
<camel:from uri="file://D://cameltest//input?noop=true&delay=10" />
<camel:log message="CAMEL BINDY CSV MARSHALLING UNMARSHALLING EXAMPLE" loggingLevel="WARN"/>
<camel:unmarshal ref="bindyDataformat" >
<camel:bindy type="Csv" classType="com.nielsen.polluxloadspring.model.PolluxData" />
</camel:unmarshal>
<camel:log message="Station Details are ${body}" loggingLevel="WARN" />
<camel:bean ref="polluxDataController" method="processPolluxData" />
<camel:log message="Station Details after bean process ${body}" loggingLevel="WARN" />
<to uri="sqlComponent:{{sql.insertNewRecord}}" />
<log message="Inserted new NewTopic ${body[id]}" />
<log message="Inserted new NewTopic ${body[ltr]}" />
<camel:log message="COMPLETED BINDY SIMPLE CSV EXAMPLE" loggingLevel="WARN" />
</camel:route>
</camelContext>
Problem is this will insert only one row to database, but the file contains 2000 rows how can I acheive this
Change the Bean method as below
public class PolluxDataController {
List<PolluxData> stationsMasterList=new ArrayList<PolluxData>();
Map<String,Object> stationMap=null;
List<Map<String,Object>> stationProccessedList=new ArrayList<Map<String,Object>>();
#SuppressWarnings("unchecked")
public List<Map<String,Object>> processPolluxData(Exchange exchange) throws Exception {
stationsMasterList= (List<PolluxData>) exchange.getIn().getBody();
for (PolluxData value:stationsMasterList){
System.out.println(value.getStationCode() +","+value.getStationShortDescription());
stationMap=new HashMap<String,Object>();
stationMap.put("id",value.getStationCode());
stationMap.put("ltr", value.getStationShortDescription());
stationProccessedList.add(stationMap);
}
return stationProccessedList;
}
}
change the sql.properties by adding a parameter batch=true , by default this will insert everything in your list to the db not once record. If you want to select and insert only two records at a time then your business logic is wrong.
You map stationMap will contains only two entries. In for (PolluxData value:stationsMasterList) you always reset this two entries for each PolluxData. Only one map with two enties within - only one insert, not 2000. Something wrong in business logic (with algorithm of filling the map stationMap, maybe), I think.

Parameter 'browserType' is required by #Configuration on method before but has not been defined in src\test\resources\testng.xml

When running Selenium case, I want firefox and chrome at the same build. My testng.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Browser Compatibility Test Cases--firefox" thread-count="1" preserve-order="false">
<parameter name="browserType" value="firefox" />
<classes>
<class name="com.yeetrack.selenium.test.ParameterTest" />
</classes>
</test>
<test name="Browser Compatibility Test Cases--chrome" thread-count="1" preserve-order="false">
<parameter name="browserType" value="chrome" />
<classes>
<class name="com.yeetrack.selenium.test.ParameterTest" />
</classes>
</test>
</suite>
And my test case:
public class ParameterTest {
#Parameters("browserType")
#BeforeMethod
public void before(String browser)
{
System.out.println(browser);
}
#Test(dataProvider = "KeywordDataProvider", dataProviderClass = KeywordData.class)
public void test(String keyword)
{
System.out.println(keyword);
}
}
But I got an error:
before(com.yeetrack.selenium.test.ParameterTest) Time elapsed: 0.222 sec <<< FAILURE!
org.testng.TestNGException:
Parameter 'browserType' is required by #Configuration on method before
but has not been defined in src\test\resources\testng.xml
at org.testng.internal.Parameters.createParameters(Parameters.java:109)
at org.testng.internal.Parameters.createParameters(Parameters.java:264)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:69)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:135)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:427)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:607)
When running, browserType=firefox, it passed. But when browserType=chrome, it failed. I can't use #Parameters and DataProvider at the same time? When I change my case to :
#Test //no DataProvider
public void test()
{
System.out.println("Hello world"));
}
It passed! Why? thx.
Here is the OP's comment solution as an answer, to make it clearer for future visitors.
In the pom.xml, the original poster added testng instead of surefire:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
This is instead of surefire-testng:
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.14.1</version>
</dependency>

Problems getting an external JAXB/JAXWS binding file to work. XPath evaluation of <valid xpath> results in empty target node

I'm at my wits' end and am hoping someone can help. I'm trying to generate
a WSClient using Gradle 1.6, CXF 2.7.5, Oracle JDK 1.6.0_33 and and
WSDLToJava
The WSDL I am consuming results in static nested Java classes which I can't
figure out how to populate when building request objects, to alleviate this
I have created a custom class which I want to have bound in place of the
static nested classes. My custom class is designed to be a replacement to
the <ControlData> element in the WSDL below, pertaining to the 'ExportVocabulary70' operation.
This is the error I'm seeing when I run WSDL2Java:
XPath evaluation of
"wsdl:definitions/wsdl:types/s:schema/s:element[#name='ExportVocabulary70']/s:complexType[#name='ControlData']"
results in empty target node
I have pasted the WSDL, Binding File, Custom Class, Gradle build task and
console output below. Apologies for the verbosity, I have snipped away as
much as I can.
I have tried so many variations of jaxb:binding and jaxws:binding that I
have lost count, I have now googled myself out of ideas so am most grateful
for any wisdom from people here.
Cheers,
Edd
WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://synaptica.factiva.com/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://synaptica.factiva.com/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="
http://synaptica.factiva.com/">
<s:element name="ExportVocabulary70">
<s:complexType name="ControlData">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ControlData">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
<s:element minOccurs="0" maxOccurs="1" name="ReportParameters">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ExportVocabulary70Response">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1"
name="ExportVocabulary70Result">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="ExportVocabulary70SoapIn">
<wsdl:part name="parameters" element="tns:ExportVocabulary70"/>
</wsdl:message>
<wsdl:message name="ExportVocabulary70SoapOut">
<wsdl:part name="parameters" element="tns:ExportVocabulary70Response"/>
</wsdl:message>
<wsdl:portType name="ServiceSoap">
<wsdl:operation name="ExportVocabulary70">
<wsdl:input message="tns:ExportVocabulary70SoapIn"/>
<wsdl:output message="tns:ExportVocabulary70SoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ExportVocabulary70">
<soap12:operation soapAction="
http://synaptica.factiva.com/ExportVocabulary70" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
<soap12:address location="
http://tm04syn2201-infra/webservices/service.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Binding File:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="Synaptica.wsdl"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<bindings
node="wsdl:definitions/wsdl:types/s:schema/s:element[#name='ExportVocabulary70']/s:complexType[#name='ControlData']">
<class name="ControlBobData"/>
</bindings>
</bindings>
Custom Class:
package com.eddgrant.synaptica.api
import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlElement
import javax.xml.bind.annotation.XmlRootElement
//
http://stackoverflow.com/questions/1161147/how-do-i-get-groovy-and-jaxb-to-play-nice-together
#XmlAccessorType(XmlAccessType.NONE)
#XmlRootElement
class ControlData {
#XmlElement
Auth auth
}
#XmlRootElement
class Auth {
#XmlElement
String userId
#XmlElement
String password
}
build.gradle excerpt (Gradle task and dependencies:)
configurations {
cxf
}
dependencies {
cxf 'org.apache.cxf:apache-cxf:2.7.5'
compile "org.codehaus.groovy:groovy-all:1.8.6"
}
task(genClientSource, type: JavaExec) {
dependsOn(compileGroovy)
description "Generates Java source files from the Synaptica WSDL"
main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
classpath = configurations.cxf
args '-p', "com.eddgrant.synaptica.api",
'-wsdlLocation', "/Synaptica.wsdl",
'-d', project.generatedSourcePath,
'-b', 'src/main/resources/ControlData.xjb',
'-verbose',
//'-sn', 'MyNewServiceLaLaLa',
project.synapticaWsdlPath
}
Console output (containing the error):
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding source
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding domsource
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding staxsource
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding saxsource
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default frontend jaxws
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default frontend jaxws21
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding jaxb
25-Jul-2013 16:48:58 org.apache.cxf.tools.wsdlto.core.PluginLoader
loadPlugin
INFO: Replaced default databinding xmlbeans
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -p uk.co.bbc.fabric.synaptica.api -wsdlLocation /Synaptica.wsdl
-d build/generated/src/main/java -b src/main/resources/ControlData.xjb
-verbose src/main/resources/Synaptica.wsdl
wsdl2java - Apache CXF 2.7.5
WSDLToJava Error:
file:/Data/Programming/bbc-dmi-sts-workspace/em3-parent-trunk/Synaptica/SynapticaWSClient/src/main/resources/ControlData.xjb
[12,132]: XPath evaluation of
"wsdl:definitions/wsdl:types/s:schema/s:element[#name='ExportVocabulary70']/s:complexType[#name='ControlData']"
results in empty target node
org.apache.cxf.tools.common.ToolException:
file:/Data/Programming/bbc-dmi-sts-workspace/em3-parent-trunk/Synaptica/SynapticaWSClient/src/main/resources/ControlData.xjb
[12,132]: XPath evaluation of
"wsdl:definitions/wsdl:types/s:schema/s:element[#name='ExportVocabulary70']/s:complexType[#name='ControlData']"
results in empty target node
Try an xpath of just "//s:schema/s:element[#name='ExportVocabulary70']/s:complexType[#name='ControlData']"
and see if that helps.
Please see--> http://cxf.apache.org/docs/wsdl-to-java.html.
Please navigate to external binding.Probably,error would not be related to xpath.

Resources