I am generating Java classes from the CVENT WSDL file using a maven plugin (see the sample below from my POM file). The code generates successfully.
I then call the code (see below) (the start and end dates passed into the getUpdated call are parameters to my method)
When I run / debug, it connects succesfully, but the getUpdated call fails:
Fault from server: INVALID_CVENT_HEADER_VALUE
In examples online, I can see that I need to set the header on the session - but I don't see any method in V200611Soap that allows me to set it.
Anyone with experience of this, or any sample code?
Thanks in advance.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<configuration>
<wsdlUrls>
<wsdlUrl>https://api.cvent.com/soap/V200611.ASMX?WSDL</wsdlUrl>
</wsdlUrls>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated/src/main/java</sourceDestDir>
</configuration>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
</plugin>
V200611 aV200611 = new V200611();
V200611Soap soap = aV200611.getV200611Soap();
String accountNumber = "xxxxxx";
String userName = "xxxxxx";
String password = "xxxxxx";
LoginResult logingResult = soap.login(accountNumber, userName, password);
CventSessionHeader header = new CventSessionHeader();
header.setCventSessionValue(logingResult.getCventSessionHeader());
GetUpdatedResult getUpdatedResult = soap.getUpdated(CvObjectType.TRAVEL, startDateXMLGregorianCalendar, endDateXmlGregorianCalendar);
I fixed by changing to use the cxf plugin
Then added the wsdlOption
<extendedSoapHeaders>true</extendedSoapHeaders>
Which puts the arguments that are implicit (in the wsdl:binding but not wsdl:port), into the generated API classes.
Related
I generated SOAP client stub with CXF 3.4.2 codegen Maven plugin.
However, when trying to create the service stub created, I get a bunch of errors like that:
There's no ObjectFactory with an #XmlElementDecl for the element {http://tempuri.org/}travelDocumentNumber.
this problem is related to the following location:
at protected javax.xml.bind.JAXBElement org.tempuri.GetActiveVisasForArrival.travelDocumentNumber
at org.tempuri.GetActiveVisasForArrival
However, there is an object factory containing the following code:
#XmlElementDecl(namespace = "http://tempuri.org/", name = "travelDocumentNumber", scope = GetActiveVisasForArrival.class)
public JAXBElement<String> createGetActiveVisasForArrivalTravelDocumentNumber(String value) {
return new JAXBElement<String>(_GetActiveVisasForArrivalTravelDocumentNumber_QNAME, String.class, GetActiveVisasForArrival.class, value);
}
As I can see, such error comes with every parameter of WS interface method (excluding XMLGregorianCalendar) and every returning value.
How can I get rid of those errors?
I generate the code this way:
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>./generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>./src/main/resources/wsdl/evisa.wsdl</wsdl>
<serviceName>BorderManagementSystemService</serviceName>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
How I initialize the service:
service = (IBorderManagementSystemService) new BorderManagementSystemService(new URL(WSDL_LOCATION)).getBasicHttpBindingIBorderManagementSystemService();
The WSDL file was exposed by some C# web service. I used single WSDL option; however, generating from root WSDL causes same errors.
I have added mapping for namespaces to unique Java packages in the plugin parameters and now things work. Probably there was a conflict with other clients generated code.
<extraarg>-p</extraarg>
<extraarg>http://tempuri.org/=rw.gov.dgie.gk.integration.evisa.client</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://schemas.migration.gov.rw/evisa=rw.gov.dgie.gk.integration.evisa</extraarg>
The EU VIES VAT validation from WSDL is not working when running via java code. But the same is working from some soap API testing tools.
Eg, https://wsdlbrowser.com/soapclient?wsdl_url=https%3A%2F%2Fec.europa.eu%2Ftaxation_customs%2Fvies%2FcheckVatService.wsdl and https://app.boomerangapi.com/?ext
Even its not working when I trid to get source code from wsimport. (C:\Program Files\Java\jdk1.8.0_151\bin>wsimport -keep -verbose http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl)
Error is “The element type "BR" must be terminated by the matching end-tag "".” The same error is coming when trying to access SOAP service via java code.
Any suggestions on how to use this EU wsdl for validating VAT nos?
Solved this using 'JAX-WS' Maven plugin to parse a WSDL file to generate java classes.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<execution>
<id>wsimportb-from-jdk</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>
https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
</wsdlUrl>
</wsdlUrls>
<keep>true</keep>
<packageName>com.vies</packageName>
<sourceDestDir>target/generatedclasses</sourceDestDir>
</configuration>
</execution>
Then export your com.vies custom package under maven <Export-Package>
Change protocol http:// to https:// in the WSDL URL
I have a small sample code in which I try to establish a connection to a remote HBase entity. The code runs on a windows machine without HBase installed and I try to connect to a remote Ubuntu Server that has it installed and running. The IP in the below snippet is of course just a placeholder.
The code is as follows:
public static void main(String[] args) {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = null;
String ip = "10.10.10.10";
String port = "2181";
conf.set("hbase.zookeeper.quorum", ip);
conf.set("hbase.zookeeper.property.clientPort", port);
try {
admin = new HBaseAdmin(conf);
boolean bool = admin.tableExists("sensor_data");
System.out.println("Table exists? " + bool);
} catch (IOException e) {
e.printStackTrace();
}
}
But for some reason I get this error:
org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
at org.apache.hadoop.hbase.client.RpcRetryingCaller.translateException(RpcRetryingCaller.java:229)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:202)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:320)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:295)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:160)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:155)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:811)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:303)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:313)
at com.twoBM.Tests.HBaseWriter.main(HBaseWriter.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:596)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:580)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:559)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1185)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1152)
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:153)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:61)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
... 15 more
I am using Gradle to build my project and currently I am only using the two following dependencies:
compile 'org.apache.hive:hive-jdbc:2.1.0'
compile 'org.apache.hbase:hbase:1.1.6'
Does anyone know to fix this problem? I have tried googling this problem, but without any of the found links providing an actual solution.
Best regards
This is definitely Google Guava's dependency conflict. The default constructor of Stopwatch class became private since Guava v.17 and marked deprecated even earlier.
So to HBase Java client works properly you need Guava v.16 or earlier. Check the way you build your application (Maven/Gradle/Classpath) and find the dependency which uses Guava v.17+. After that, you can resolve the conflict.
I received the same error and had to spend for 5 days to know the issue.
I added following dependency and its gone.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
You can use maven shade plugin to solve this issue. That a look at this blog post. Here is an example (actually a snippet from my working pom.)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!--<finalName>PROJECT_NAME-${project.version}-shaded</finalName>-->
<relocations>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>shaded.com.google.common</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>shaded.com.google.protobuf</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
I want dynamically exchange the webserive targetnamescpace (host) in the cade generated by Apache CXF.
Why? Each customer has its own wsdl file.
The current situation is that there is one project, that depends on wsdl X that is hosted on serverX. That means for each Customer an extra build with he specific wsdl URL.
The wsdl files are always identically, just the server changes.
A fat jar (jar-with-dependencies) will be build and uploaded to our nexus server.
We use Java 7 and Maven 3 to build our projects.
The problem is when deploying to nexus you cannot change the change the name of the artifact that gets deployed. application-1.0-CUSTOMER.jar would be a nice pattern but i didn't found a way to solve that and also the whole process dosen't seem very clean.
The webservice-.java files gets generated by the cxf-codegen-plugin plugin. I am using this configuration:
<!-- CXF wsdl2Java Generation -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/cxf/</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>
http://trunk. ....
</wsdl>
<serviceName>ServiceName</serviceName>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
<!-- override the namespace to have always identical package names -->
<extraarg>-p</extraarg>
<extraarg>de.packagename.wsdl</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
Here one of the generated java files:
/**
* This class was generated by Apache CXF 2.7.0
* 2013-11-13T14:35:21.046+01:00
* Generated source version: 2.7.0
*
*/
#WebService(targetNamespace = "http://trunk...", name = "SomeName")
#XmlSeeAlso({ObjectFactory.class})
public interface SomeName {
...
}
My idea was to cut out the whole webservice-client implementation out of that application and put it in another project (one project one customer) -- but how to call the webservice from the original project? Currently one Interface is used by the original project as well as one model class.
I know that there is a hack around the deployment problem by using a artifact version with a variable, but it is highly discouraged, at least in maven 3.
I resolved it.
Its similar to this one: How to create a CXF webservice client with dynamic endpoint? but only after a half day debugging i found my solution.
final QName qname = new QName(Settings.MAIN_SCAN_SERVICE_SOAP_URL.get().toString(), "PortName");
final String wsdlUrl = Settings.MAIN_SCAN_SERVICE_WSDL_URL.get().toString();
final JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
jaxWsProxyFactoryBean.setAddress(Settings.MAIN_SCAN_SERVICE_SOAP_URL.get().toString());
jaxWsProxyFactoryBean.setEndpointName(qname);
jaxWsProxyFactoryBean.setServiceName(new QName(wsdlUrl, "PortName"));
jaxWsProxyFactoryBean.setWsdlLocation(wsdlUrl);
jaxWsProxyFactoryBean.setServiceClass(PortImpl.class);
this.portImpl = (PortImpl) jaxWsProxyFactoryBean.create();
Our project uses XJC to generate Java classes from an XSD. I'm using JAVA EE 6.
When all the XSDs we have are re-generated, the generated classes include this comment at the top of the file:
// Generated on: 2011.02.23 at 02:17:06 PM GMT
Is it possible to suppress this comment? The reason is that we use SVN for version control, and every time we regenerate our classes, every single file shows as being changed in SVN, even though the only thing that differs is this comment. So I'd like to remove the comment altogether if possible.
There is a -no-header directive, but I don't want to remove the entire header, so that future generations know that it's a file generated from a tool, and that modifications will be overwritten. I only want to remove the timestamp. (Or alternatively, I'd remove the inbuilt header and then insert my own header somehow.)
I am using this Maven plugin which replaces the // Generated on: 2011.02.23 at 02:17:06 PM GMT line:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.3.8</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>src/main/java/jaxb/*.java</include>
</includes>
<token>^// Generated on.*$</token>
<value>// Generated on: [TEXT REMOVED by maven-replacer-plugin]</value>
<regexFlags>
<regexFlag>MULTILINE</regexFlag>
</regexFlags>
</configuration>
</plugin>
I'm late to the party, but since version 2.0 of the jaxb2-maven-plugin, there's a noGeneratedHeaderComments configuration option. (see the JAXB-2 Maven Plugin Docs)
You can use it like this:
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<target>2.1</target>
<sources>
<source>FirstXSD.xsd</source>
<source>SecondXSD.xsd</source>
</sources>
<xjbSources>
<xjbSource>OptionalBindings.xjb</xjbSource>
</xjbSources>
<noGeneratedHeaderComments>true</noGeneratedHeaderComments>
</configuration>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
...
So no need for another plugin or script to run.
If you want to keep a disclaimer, you can use one of the techniques already mentioned to inject it where wanted.
If you use ant, the following snippet may be useful for replacing the comments:
<replaceregexp
match="^// Generated on:.*$"
replace="// Generated on: [date removed]"
byline="true">
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
I know this is 2 years after the fact, but because the classes are generated they aren't necessarily needed in SVN. What needs to be in SVN is the schema or whatever file you use for source to generate the classes. As long as you have the source and the tools to generate the classes, the classes in SVN are redundant and as you saw, problematic in SVN or any SCCS. So put the schema file in SVN and avoid the issue altogether.
If it's not possible using an option you can post-process the generated files yourself.
For a very specific use-case we had to do it that way on our project...
We use Maven and we execute a specific script after the Java classes have been generated and before we compile and package them to a distriuable JAR.
To build on cata's answer (upvoted) the maven-replacer-plugin is the way to go. I've come up with the following that strips out the entire comment (not just the timestamp) which you can replace with your file comment (license etc.).
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- assumes your xjc is putting source code here -->
<includes>
<include>src/main/java/**/*.java</include>
</includes>
<regex>true</regex>
<regexFlags>
<regexFlag>MULTILINE</regexFlag>
</regexFlags>
<replacements>
<replacement>
<token>(^//.*\u000a|^\u000a)*^package</token>
<value>// your new comment
package</value>
</replacement>
</replacements>
</configuration>
</plugin>
The one gotcha to watch out for is that the <value> element treats the text literally. So if you want a line break in your replacement text you need to put a line break in your pom.xml file (as I've demonstrated above).
What you should you :
Generate your classes in target :
${project.build.directory}/generated-sources
If you add target to ignore list (svn), that's all.
I also want to have text header with warning about classes was auto-generated and should not be modified manually, but because I place such files into git I do not want there always changed date of generation.
That header generated in com.sun.tools.xjc.Options#getPrologComment method. So essentially it call:
return Messages.format(
Messages.FILE_PROLOG_COMMENT,
dateFormat.format(new Date()));
Messages.FILE_PROLOG_COMMENT defined as Driver.FilePrologComment. With futher debugging I found it use standard Java localization bundles.
So, to change header format we just may provide our properties override for their values from MessageBundle.properties.
We can do it in two way:
Just copy that file (from repo by link, or just from jar of appropriate version what you are using) into src/main/resources/com/sun/tools/xjc/MessageBundle.properties in your project and change key Driver.FilePrologComment as you wish.
But first case have some drawbacks - first you copy-paste many code which you do not change, second you should update it when you update XJC dependency. So better I recommend place it as src/main/resources/com/sun/tools/xjc/MessageBundle_en.properties (note _en suffix in filename) file and place there only properties you really want to change. Something like:
# We want header, but do NOT willing there `Generated on: {0}` part because want commit them into git!
Driver.FilePrologComment = \
This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.4.0-b180830.0438 \n\
See https://javaee.github.io/jaxb-v2/ \n\
Any modifications to this file will be lost upon recompilation of the source schema. \n
Ensure that file in compiler classpath, especially if you call it from some plugins.
That is common mechanism for translation. See related answer: JAXB english comments in generated file
If you are using maven-jaxb2-plugin there is an tag noFileHeader set it to true. It will prevent jaxb to generate the header that includes that date line on it.
<noFileHeader>true</noFileHeader>