Showing posts with label CXF. Show all posts
Showing posts with label CXF. Show all posts

Sunday, 15 January 2012

Changing CXF WebService address

In the Apache CXF we do not have a constructor to create web service with local wsdl file or address to the web service which would override the default one. But we can do it on the constructed object. Here is an example:
WebServicesSoap port = service.getWebServicesSoap();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, webServiceAddress); 

Thursday, 10 November 2011

CXF - maven plug-in

I was implementing a Webservice client. I used Apache CXF (http://cxf.apache.org/) an open source services framework. It is a natural successor of Axis library.

After some time spent with CFX I can say that it uses Collections over Arrays (that is a big plus). On the other hand it hasn't got as good documentation as I expected. I tried to use maven task for generating java classes from WSDL definition files. When I got an error I had to use wsdl2java from command line to get detailed error message. Also I couldn't find syntax for wsdl2java task. I wished to use more parameters. I spent some time on finding how to do it. Underneath you can see an example to define configuration in pom.xml for wsdl2java operation. You can use more wsdlOption tags for generating classes from more then one WSDL file.

<build>
  <plugins>
   <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>${project.build.directory}/generated/cxf</sourceRoot>
       <wsdlOptions>
        <wsdlOption>
         <wsdl>${basedir}/src/main/wsdl/authentication-service.wsdl</wsdl>
         <extraargs>
          <extraarg>-client</extraarg>
          <extraarg>-p</extraarg>
          <extraarg>http://www.alfresco.org/ws/service/authentication/1.0=org.alfresco.ws.service.authentication</extraarg>
         </extraargs>
        </wsdlOption>
       </wsdlOptions>
      </configuration>
      <goals>
       <goal>wsdl2java</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>