Thursday, October 10, 2019

[JAVA-SOAP] Customize date type to string in client code


  1. Create a binding file with name common-binding.xjb or whatever with the content bellow
  2. <?xml version='1.0' encoding='UTF-8'?>
      <jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
      jaxb:extensionBindingPrefixes="xjc">
          <jaxb:globalBindings>
              <jaxb:serializable uid="1" />
              <jaxb:javaType name="String" xmlType="xsd:dateTime" />
              <jaxb:javaType name="String" xmlType="xsd:date" />
              <jaxb:javaType name="String" xmlType="xsd:time" />
          </jaxb:globalBindings>
      </jaxb:bindings>
  3. In the pom.xml file, adding a plugin like:
  4.  <plugin>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-codegen-plugin</artifactId>
          <version>${cxf.version}</version>
          <executions>
              <execution>
                  <id>generate-sources</id>
                  <phase>generate-sources</phase>
                  <configuration>
                      <sourceRoot>${basedir}/src/main/java</sourceRoot>
                      <wsdlOptions>
                          <wsdlOption>
                              <wsdl>${basedir}/src/main/resources/wsdl/DynamicsGP.wsdl</wsdl>
                              <wsdlLocation>classpath:wsdl/DynamicsGP.wsdl</wsdlLocation>
                          </wsdlOption>
                      </wsdlOptions>
                      <defaultOptions>
                          <bindingFiles>
                              <bindingFile>${basedir}/src/main/resources/wsdl/common-binding.xjb</bindingFile>
                          </bindingFiles>
                      </defaultOptions>
                  </configuration>
                  <goals>
                      <goal>wsdl2java</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>

[JAVA-SOAP] How to build a client for Microsoft SOAP web service

Microsoft build the SOAP-based web service usually support two types of authentication:

  • NTLM - support both http and https
  • Basic - support https only
So before the web service is published(use https) we have to use NTLM(Windows Kerberos and NT LAN Manager), and this is not supported by any JAVA related SOAP service by default, to do so you have to customize, the below is the code snippet: