WSO2 Admin Services Client

From EWIKI
Jump to navigation Jump to search

Relevant admin service APIs exposed by WSO2 AS: WSO2API Manager: Download from WSO2

  • to deploy a webapp, you have to use WebappAdmin API WSDL
  • for AAR service deployment "ServiceUploader" API should be used WSDL

OSGI services in WSO2 ESB

To have a look at the admin services WSDLs, you should customize the repository/conf/carbon.xml and change the value of HideAdminServiceWSDLs. Now you can request the WSDL using e.g. https://Aspire756:8243/services/ProvisioningAdminService?wsdl

Start WOS2ESB with

./wso2server.sh -DosgiConsole

List services

osgi> listAdminServices
1. ProvisioningAdminService, ProvisioningAdminService, https://Aspire756:8243/services/ProvisioningAdminService 
2. SynapseApplicationAdmin, SynapseApplicationAdmin, https://Aspire756:8243/services/SynapseApplicationAdmin 
3. CarbonAppUploader, CarbonAppUploader, https://Aspire756:8243/services/CarbonAppUploader 
4. OperationAdmin, OperationAdmin, https://Aspire756:8243/services/OperationAdmin 
5. SequenceAdminService, SequenceAdminService, https://Aspire756:8243/services/SequenceAdminService 
6. MediationLibraryAdminService, MediationLibraryAdminService, https://Aspire756:8243/services/MediationLibraryAdminService 
7. StatisticsAdmin, StatisticsAdmin, https://Aspire756:8243/services/StatisticsAdmin 
8. LoggedUserInfoAdmin, LoggedUserInfoAdmin, https://Aspire756:8243/services/LoggedUserInfoAdmin 
9. MediationStatisticsAdmin, MediationStatisticsAdmin, https://Aspire756:8243/services/MediationStatisticsAdmin 
10. TopicManagerAdminService, TopicManagerAdminService, https://Aspire756:8243/services/TopicManagerAdminService 
11. MessageProcessorAdminService, MessageProcessorAdminService, https://Aspire756:8243/services/MessageProcessorAdminService 
12. ApplicationAdmin, ApplicationAdmin, https://Aspire756:8243/services/ApplicationAdmin 
13. NDataSourceAdmin, NDataSourceAdmin, https://Aspire756:8243/services/NDataSourceAdmin 
14. ServiceGroupAdmin, ServiceGroupAdmin, https://Aspire756:8243/services/ServiceGroupAdmin 
15. ClassMediatorAdmin, ClassMediatorAdmin, https://Aspire756:8243/services/ClassMediatorAdmin 
16. CustomMeteringService, CustomMeteringService, https://Aspire756:8243/services/CustomMeteringService 
17. BAMMediatorConfigAdmin, BAMMediatorConfigAdmin, https://Aspire756:8243/services/BAMMediatorConfigAdmin 
18. STSAdminService, STSAdminService, https://Aspire756:8243/services/STSAdminService 
19. RegistryAdminService, RegistryAdminService, https://Aspire756:8243/services/RegistryAdminService 
20. FileDownloadService, FileDownloadService, https://Aspire756:8243/services/FileDownloadService 
21. CachingAdminService, CachingAdminService, https://Aspire756:8243/services/CachingAdminService 
22. MessageStoreAdminService, MessageStoreAdminService, https://Aspire756:8243/services/MessageStoreAdminService 
23. RMAdminGlobal, RMAdminGlobal, https://Aspire756:8243/services/RMAdminGlobal 
24. LoginStatisticsAdmin, LoginStatisticsAdmin, https://Aspire756:8243/services/LoginStatisticsAdmin 
25. CustomUIAdminService, CustomUIAdminService, https://Aspire756:8243/services/CustomUIAdminService 
26. ReportingResourcesSupplier, ReportingResourcesSupplier, https://Aspire756:8243/services/ReportingResourcesSupplier 
27. RMAdminService, RMAdminService, https://Aspire756:8243/services/RMAdminService 
28. SearchAdminService, SearchAdminService, https://Aspire756:8243/services/SearchAdminService 
29. JMSTransportAdmin, JMSTransportAdmin, https://Aspire756:8243/services/JMSTransportAdmin 
30. CGAgentAdminService, CGAgentAdminService, https://Aspire756:8243/services/CGAgentAdminService 
31. ThrottleAdminService, ThrottleAdminService, https://Aspire756:8243/services/ThrottleAdminService 
32. TaskAdmin, TaskAdmin, https://Aspire756:8243/services/TaskAdmin 
33. ModuleAdminService, ModuleAdminService, https://Aspire756:8243/services/ModuleAdminService 
34. MediationTracerService, MediationTracerService, https://Aspire756:8243/services/MediationTracerService 
35. RestApiAdmin, RestApiAdmin, https://Aspire756:8243/services/RestApiAdmin 
36. LoggingAdmin, LoggingAdmin, https://Aspire756:8243/services/LoggingAdmin 
37. ExternalTryitService, ExternalTryitService, https://Aspire756:8243/services/ExternalTryitService 
38. SampleDeployer, SampleDeployer, https://Aspire756:8243/services/SampleDeployer 
39. SecurityAdminService, SecurityAdminService, https://Aspire756:8243/services/SecurityAdminService 
40. KeyStoreAdminService, KeyStoreAdminService, https://Aspire756:8243/services/KeyStoreAdminService 
41. JrxmlFileUploader, JrxmlFileUploader, https://Aspire756:8243/services/JrxmlFileUploader 
42. DiscoveryAdmin, DiscoveryAdmin, https://Aspire756:8243/services/DiscoveryAdmin 
43. EndpointAdmin, EndpointAdmin, https://Aspire756:8243/services/EndpointAdmin 
44. ServerRolesManager, ServerRolesManager, https://Aspire756:8243/services/ServerRolesManager 
45. ResourceAdminService, ResourceAdminService, https://Aspire756:8243/services/ResourceAdminService 
46. ThemeMgtService, ThemeMgtService, https://Aspire756:8243/services/ThemeMgtService 
47. MediationStatPublisherAdmin, MediationStatPublisherAdmin, https://Aspire756:8243/services/MediationStatPublisherAdmin 
48. FileUploadService, FileUploadService, https://Aspire756:8243/services/FileUploadService 
49. DataSourceAdmin, DataSourceAdmin, https://Aspire756:8243/services/DataSourceAdmin 
50. MediationLibraryUploader, MediationLibraryUploader, https://Aspire756:8243/services/MediationLibraryUploader 
51. WSDLValidatorService, WSDLValidatorService, https://Aspire756:8243/services/WSDLValidatorService 
52. ConfigServiceAdmin, ConfigServiceAdmin, https://Aspire756:8243/services/ConfigServiceAdmin 
53. CommandMediatorAdmin, CommandMediatorAdmin, https://Aspire756:8243/services/CommandMediatorAdmin 
54. EventBrokerService, EventBrokerService, https://Aspire756:8243/services/EventBrokerService 
55. TracerAdmin, TracerAdmin, https://Aspire756:8243/services/TracerAdmin 
56. TransportAdmin, TransportAdmin, https://Aspire756:8243/services/TransportAdmin 
57. ProxyServiceAdmin, ProxyServiceAdmin, https://Aspire756:8243/services/ProxyServiceAdmin 
58. Java2WSDLService, Java2WSDLService, https://Aspire756:8243/services/Java2WSDLService 
59. InfoAdminService, InfoAdminService, https://Aspire756:8243/services/InfoAdminService 
60. RepositoryAdminService, RepositoryAdminService, https://Aspire756:8243/services/RepositoryAdminService 
61. PriorityMediationAdmin, PriorityMediationAdmin, https://Aspire756:8243/services/PriorityMediationAdmin 
62. TenantMgtAdminService, TenantMgtAdminService, https://Aspire756:8243/services/TenantMgtAdminService 
63. DeploymentSynchronizerAdmin, DeploymentSynchronizerAdmin, https://Aspire756:8243/services/DeploymentSynchronizerAdmin 
64. TemplateAdminService, TemplateAdminService, https://Aspire756:8243/services/TemplateAdminService 
65. RelationAdminService, RelationAdminService, https://Aspire756:8243/services/RelationAdminService 
66. DBReportingService, DBReportingService, https://Aspire756:8243/services/DBReportingService 
67. ServerAdmin, ServerAdmin, https://Aspire756:8243/services/ServerAdmin 
68. ServiceAdmin, ServiceAdmin, https://Aspire756:8243/services/ServiceAdmin 
69. FlowsAdminService, FlowsAdminService, https://Aspire756:8243/services/FlowsAdminService 
70. UserAdmin, UserAdmin, https://Aspire756:8243/services/UserAdmin 
71. PropertiesAdminService, PropertiesAdminService, https://Aspire756:8243/services/PropertiesAdminService 
72. LogViewer, LogViewer, https://Aspire756:8243/services/LogViewer 
73. WSDL2CodeService, WSDL2CodeService, https://Aspire756:8243/services/WSDL2CodeService 
74. TransportStatisticsAdmin, TransportStatisticsAdmin, https://Aspire756:8243/services/TransportStatisticsAdmin 
75. SynapseArtifactUploaderAdmin, SynapseArtifactUploaderAdmin, https://Aspire756:8243/services/SynapseArtifactUploaderAdmin 
76. LocalEntryAdmin, LocalEntryAdmin, https://Aspire756:8243/services/LocalEntryAdmin 
77. EndpointTemplateAdminService, EndpointTemplateAdminService, https://Aspire756:8243/services/EndpointTemplateAdminService

OSGI services in WSO2 AS

Start WOS2AS with

./wso2server.sh -DosgiConsole

List services

osgi> listAdminServices
Admin services deployed on this server:
1. ProvisioningAdminService, ProvisioningAdminService, https://192.168.2.113:9443/services/ProvisioningAdminService/ 
2. CarbonAppUploader, CarbonAppUploader, https://192.168.2.113:9443/services/CarbonAppUploader/ 
3. OperationAdmin, OperationAdmin, https://192.168.2.113:9443/services/OperationAdmin/ 
4. JaggeryAppAdmin, JaggeryAppAdmin, https://192.168.2.113:9443/services/JaggeryAppAdmin/ 
5. JaxwsWebappAdmin, JaxwsWebappAdmin, https://192.168.2.113:9443/services/JaxwsWebappAdmin/ 
6. StatisticsAdmin, StatisticsAdmin, https://192.168.2.113:9443/services/StatisticsAdmin/ 
7. LoggedUserInfoAdmin, LoggedUserInfoAdmin, https://192.168.2.113:9443/services/LoggedUserInfoAdmin/ 
8. WebappAdmin, WebappAdmin, https://192.168.2.113:9443/services/WebappAdmin/
9. TopicManagerAdminService, TopicManagerAdminService, https://192.168.2.113:9443/services/TopicManagerAdminService/ 
10. ApplicationAdmin, ApplicationAdmin, https://192.168.2.113:9443/services/ApplicationAdmin/ 
11. NDataSourceAdmin, NDataSourceAdmin, https://192.168.2.113:9443/services/NDataSourceAdmin/ 
12. ServiceGroupAdmin, ServiceGroupAdmin, https://192.168.2.113:9443/services/ServiceGroupAdmin/ 
13. DataServiceFileUploader, DataServiceFileUploader, https://192.168.2.113:9443/services/DataServiceFileUploader/ 
14. CustomMeteringService, CustomMeteringService, https://192.168.2.113:9443/services/CustomMeteringService/ 
15. STSAdminService, STSAdminService, https://192.168.2.113:9443/services/STSAdminService/ 
16. RegistryAdminService, RegistryAdminService, https://192.168.2.113:9443/services/RegistryAdminService/ 
17. JavaScriptStubGeneratorService, JavaScriptStubGeneratorService, https://192.168.2.113:9443/services/JavaScriptStubGeneratorService/ http://192.168.2.113:9763/services/JavaScriptStubGeneratorService/ local:///services/JavaScriptStubGeneratorService/ 
18. JSServiceUploader, JSServiceUploader, https://192.168.2.113:9443/services/JSServiceUploader/ 
19. FileDownloadService, FileDownloadService, https://192.168.2.113:9443/services/FileDownloadService/ 
20. CachingAdminService, CachingAdminService, https://192.168.2.113:9443/services/CachingAdminService/ 
21. MashupServiceAdmin, MashupServiceAdmin, https://192.168.2.113:9443/services/MashupServiceAdmin/ 
22. JarServiceCreatorAdmin, JarServiceCreatorAdmin, https://192.168.2.113:9443/services/JarServiceCreatorAdmin/ 
23. RMAdminGlobal, RMAdminGlobal, https://192.168.2.113:9443/services/RMAdminGlobal/ 
24. ContentSearchAdminService, ContentSearchAdminService, https://192.168.2.113:9443/services/ContentSearchAdminService/ 
25. LoginStatisticsAdmin, LoginStatisticsAdmin, https://192.168.2.113:9443/services/LoginStatisticsAdmin/ 
26. CustomUIAdminService, CustomUIAdminService, https://192.168.2.113:9443/services/CustomUIAdminService/ 
27. RMAdminService, RMAdminService, https://192.168.2.113:9443/services/RMAdminService/ 
28. SearchAdminService, SearchAdminService, https://192.168.2.113:9443/services/SearchAdminService/ 
29. JMSTransportAdmin, JMSTransportAdmin, https://192.168.2.113:9443/services/JMSTransportAdmin/ 
30. ThrottleAdminService, ThrottleAdminService, https://192.168.2.113:9443/services/ThrottleAdminService/ 
31. ModuleAdminService, ModuleAdminService, https://192.168.2.113:9443/services/ModuleAdminService/ 
32. LoggingAdmin, LoggingAdmin, https://192.168.2.113:9443/services/LoggingAdmin/ 
33. ExternalTryitService, ExternalTryitService, https://192.168.2.113:9443/services/ExternalTryitService/ 
34. SampleDeployer, SampleDeployer, https://192.168.2.113:9443/services/SampleDeployer/ 
35. SecurityAdminService, SecurityAdminService, https://192.168.2.113:9443/services/SecurityAdminService/ 
36. KeyStoreAdminService, KeyStoreAdminService, https://192.168.2.113:9443/services/KeyStoreAdminService/ 
37. WarApplicationAdmin, WarApplicationAdmin, https://192.168.2.113:9443/services/WarApplicationAdmin/ 
38. DiscoveryAdmin, DiscoveryAdmin, https://192.168.2.113:9443/services/DiscoveryAdmin/ 
39. ServerRolesManager, ServerRolesManager, https://192.168.2.113:9443/services/ServerRolesManager/ 
40. IdentityProviderMgtService, IdentityProviderMgtService, https://192.168.2.113:9443/services/IdentityProviderMgtService/ 
41. ServiceDataPublisherAdmin, ServiceDataPublisherAdmin, https://192.168.2.113:9443/services/ServiceDataPublisherAdmin/ 
42. ResourceAdminService, ResourceAdminService, https://192.168.2.113:9443/services/ResourceAdminService/ 
43. DataServiceAdmin, DataServiceAdmin, https://192.168.2.113:9443/services/DataServiceAdmin/ 
44. ThemeMgtService, ThemeMgtService, https://192.168.2.113:9443/services/ThemeMgtService/ 
45. FileUploadService, FileUploadService, https://192.168.2.113:9443/services/FileUploadService/ 
46. WebappStatPublisherAdmin, WebappStatPublisherAdmin, https://192.168.2.113:9443/services/WebappStatPublisherAdmin/ 
47. ServiceUploader, ServiceUploader, https://192.168.2.113:9443/services/ServiceUploader/ 
48. WSDLValidatorService, WSDLValidatorService, https://192.168.2.113:9443/services/WSDLValidatorService/ 
49. EventBrokerService, EventBrokerService, https://192.168.2.113:9443/services/EventBrokerService/ 
50. TracerAdmin, TracerAdmin, https://192.168.2.113:9443/services/TracerAdmin/ 
51. TransportAdmin, TransportAdmin, https://192.168.2.113:9443/services/TransportAdmin/ 
52. MultipleCredentialsUserAdmin, MultipleCredentialsUserAdmin, https://192.168.2.113:9443/services/MultipleCredentialsUserAdmin/ 
53. Java2WSDLService, Java2WSDLService, https://192.168.2.113:9443/services/Java2WSDLService/ 
54. UserStoreConfigAdminService, UserStoreConfigAdminService, https://192.168.2.113:9443/services/UserStoreConfigAdminService/ 
55. RepositoryAdminService, RepositoryAdminService, https://192.168.2.113:9443/services/RepositoryAdminService/ 
56. TenantMgtAdminService, TenantMgtAdminService, https://192.168.2.113:9443/services/TenantMgtAdminService/ 
57. DeploymentSynchronizerAdmin, DeploymentSynchronizerAdmin, https://192.168.2.113:9443/services/DeploymentSynchronizerAdmin/ 
58. ServerAdmin, ServerAdmin, https://192.168.2.113:9443/services/ServerAdmin/ 
59. ServiceAdmin, ServiceAdmin, https://192.168.2.113:9443/services/ServiceAdmin/ 
60. FlowsAdminService, FlowsAdminService, https://192.168.2.113:9443/services/FlowsAdminService/ 
61. UserAdmin, UserAdmin, https://192.168.2.113:9443/services/UserAdmin/ 
62. PropertiesAdminService, PropertiesAdminService, https://192.168.2.113:9443/services/PropertiesAdminService/ 
63. Axis2RepoManager, Axis2RepoManager, https://192.168.2.113:9443/services/Axis2RepoManager/ 
64. LogViewer, LogViewer, https://192.168.2.113:9443/services/LogViewer/ 
65. WSDL2CodeService, WSDL2CodeService, https://192.168.2.113:9443/services/WSDL2CodeService/ 
osgi> 

I've found this:

Java CXF Client for WSO2 Admin API

CXF's wsdl2java

Steps of client creation:

export CXF_HOME=/java/apache-cxf-3.0.0-milestone1
/java/apache-cxf-3.0.0-milestone1/bin/wsdl2java -ant -client -d webappadmin  WebappAdmin.wsdl 

Copy the sources where you need them to be and the WSDL into the project root.

Preparing the Java KeyStore

Download the certificate from https://localhost:9443 and add it to the local keystore (~/.keystore).

keytool -import -trustcacerts -alias wso2as-key -file localhost-wso2as.cert

Custom Java Client Coding

There are default clients created, e.g. org/wso2/carbon/webapp/mgt/WebappAdminPortType_WebappAdminHttpsEndpoint_Client.java. Comment out all write ops for testing!! You can build them using the generated ant file. An other option is to use Maven (better for all dependencies): WebappAdminTstClient.java

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.wso2.carbon.webapp.mgt.WebappAdminPortType;
import org.wso2.carbon.webapp.mgt.xsd.WebappMetadata;

/**
 * Simple WSO2 WebappAdmin SOAP client
 * @author mh
 */
public final class WebappAdminTstClient {

    public static void main(String args[]) throws java.lang.Exception {
    	
        System.out.println( "Set up SOAP client..." );
        JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean(); 
        clientFactory.setAddress( "https://localhost:9443/services/WebappAdmin.WebappAdminHttpsEndpoint/" );
	clientFactory.setServiceClass( WebappAdminPortType.class );
	clientFactory.setUsername("admin");
	clientFactory.setPassword("admin");
	WebappAdminPortType adminSvc = (WebappAdminPortType)clientFactory.create();

        System.out.println( "Invoking getStartedWebapp..." );
        WebappMetadata startedWebapps = adminSvc.getStartedWebapp( "example.war" );
        
        System.out.println( "getStartedWebapp.result=" + startedWebapps.getDisplayName().getValue() );
   }
}

pom.xml

<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>
  <groupId>mh</groupId>
  <artifactId>admin</artifactId>
  <version>0.1.1-SNAPSHOT</version>
  <name>WSO2 Admin</name>
 
	<properties>
		<CApp.type>webapp/jaxws</CApp.type>
		<java-version>1.6</java-version>
		<org.springframework-version>3.0.6.RELEASE</org.springframework-version>
		<org.aspectj-version>1.6.9</org.aspectj-version>
		<org.slf4j-version>1.5.10</org.slf4j-version>
	</properties>
  
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	
	<repositories>
		<repository>
			<releases>
				<updatePolicy>daily</updatePolicy>
				<checksumPolicy>ignore</checksumPolicy>
			</releases>
			<id>wso2-nexus</id>
			<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
		</repository>
	</repositories>
	
	<pluginRepositories>
		<pluginRepository>
			<releases>
				<updatePolicy>daily</updatePolicy>
				<checksumPolicy>ignore</checksumPolicy>
			</releases>
			<id>wso2-nexus</id>
			<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
		</pluginRepository>
	</pluginRepositories>
	
	<dependencies>
                <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-frontend-jaxws</artifactId>
                    <version>3.0.0-milestone1</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-transports-http</artifactId>
                    <version>3.0.0-milestone1</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
		    <version>${org.springframework-version}</version>
                </dependency>
        </dependencies>  
</project>

Call test via:

mvn exec:java -Dexec.mainClass="WebappAdminTstClient" -Djavax.net.ssl.trustStore=~/.keystore -Djavax.net.ssl.trustStorePassword=changeit -e

Fully working WAR remote deployment

In addition to the java sample above, now we have to prepare an input structure for calling the web service containing the WAR.

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBElement;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.wso2.carbon.webapp.mgt.WebappAdminPortType;
import org.wso2.carbon.webapp.mgt.xsd.WebappUploadData;

/** 
 * Deploy test for WSO2 Application Server 5.2
 *  
 *  Call via:
 *  	mvn exec:java -Dexec.mainClass="Wso2AsDeploy" -Djavax.net.ssl.trustStore=/home/youruser/.keystore -Djavax.net.ssl.trustStorePassword=changeit
 *  
 *  @author mh 
 */
public class Wso2AsDeploy {
	
    /** the admin web service proxy */
    public static WebappAdminPortType adminSvc;

    /** Upload the WAR file via WSO2 SOAP admin web service to the WSO2 AS (tested with 5.2.0) */
    public static void main(String args[]) throws java.lang.Exception {
    	String warName = "example.war";
    	
    	createAdminService();

        WebappUploadData warUpload = getUploadData( warName, "uploadsample.war", "1.0" );
        List<WebappUploadData> webappUploadDataList = new ArrayList<WebappUploadData>();
        webappUploadDataList.add( warUpload );
        
        System.out.println( "Invoking uploadWebapp for "+warName+" ...");
        Boolean uplResult = adminSvc.uploadWebapp( webappUploadDataList  );
        
        System.out.println( "Upload "+warName+" result: "+uplResult );
        
        System.exit(0);
    }

    /** prepare input data for war upload web service */ 
    private static WebappUploadData getUploadData(String warFilename, String name, String version) throws Exception {
        WebappUploadData data = new WebappUploadData();
        System.out.println( "Prepare uploadWebapp for "+warFilename+" ...");
        
        File file = new File( warFilename );
        FileInputStream fin = new FileInputStream( file );
        byte fileContent[] = new byte[ (int)file.length() ];
        int cnt = fin.read( fileContent );
        System.out.println( warFilename+" "+cnt+" bytes" );
        fin.close();
        
        org.wso2.carbon.webapp.mgt.xsd.ObjectFactory webappAdmObjFactory = new org.wso2.carbon.webapp.mgt.xsd.ObjectFactory();
        JAXBElement<String> fn = webappAdmObjFactory.createWebappUploadDataFileName( name );
        JAXBElement<String> ve = webappAdmObjFactory.createWebappUploadDataVersion( version );
        JAXBElement<byte[]> dh = webappAdmObjFactory.createWebappUploadDataDataHandler( fileContent );
        
        data.setFileName( fn );
        data.setVersion( ve);
        data.setDataHandler( dh );

        return data;
    }
    
    /** prepare a admin web service proxy */
    public static void createAdminService() {
        System.out.println("Set up SOAP admin client...");   	
        JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean(); 
        clientFactory.setAddress( "https://localhost:9443/services/WebappAdmin.WebappAdminHttpsEndpoint/" );
	clientFactory.setServiceClass( WebappAdminPortType.class );
	clientFactory.setUsername("admin");
	clientFactory.setPassword("admin");
		
	adminSvc =	(WebappAdminPortType)clientFactory.create();
    }
    
}

If you run it, you should get an output as follows:

mh@Aspire756:~/waruploader$ mvn exec:java -Dexec.mainClass="Wso2AsDeploy" -Djavax.net.ssl.trustStore=.keystore -Djavax.net.ssl.trustStorePassword=changeit 
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - WSO2adm:waruploader:jar:0.0.1-SNAPSHOT
[INFO]    task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:java {execution: default-cli}]
Set up SOAP admin client...
org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://mgt.webapp.carbon.wso2.org}WebappAdminPortTypeService from class org.wso2.carbon.webapp.mgt.WebappAdminPortType
Prepare uploadWebapp for example.war ...
example.war 3065 bytes
Invoking uploadWebapp for example.war ...
Upload example.war result: true

The WSO2 Application Server logs should be:

INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [...]
INFO {org.wso2.carbon.webapp.mgt.TomcatGenericWebappsDeployer} -  Deployed webapp: StandardEngine[Catalina].StandardHost[localhost].StandardContext
   [/uploadsample/1.0].File[/opt/wso2as-5.2.0/repository/deployment/server/webapps/uploadsample#1.0.war]

Jenkins Integration

Just started working on [1]

It starts easy:

mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
mvn -DdownloadSources=true -DdownloadJavadocs=true -DoutputDirectory=target/eclipse-classes eclipse:eclipse

Then import the project to eclipse to start coding.

First result: Jenkins-WSO2AS-Deployer

Maven Intgration

A maven plug-in may be more lightweight and flexible than the Jenkins plug-in, so the next plan is to reuse the code to encapsulate the artifact uploads for the use within maven.

First reading: Maven Plugin Development Guide -- better: Maven Reference: Chapter 11 - Writing Plugins

Additionally the maven plugin

  1. should deal with all three artifact upload services: AAR, WAR and CAR (detecting on the file extension).
  2. should allow multiple uploads within one build (required in a more complex environment set up)
  3. must handle build parameters

The POM may be Cargo style

<wso2-deployment>
 <wso2-servers>
   <wso2-server>
       <server-id>as01</server-id>
       <url>https://carbon.mycluster:9443/services/</url>
       <admin-user>admin</admin-user>
       <admin-password>secret</admin-password>
   </wso2-server>
 </wso2-servers>
 <deployables>
   <deployable>
       <server-id>as01</server-id>
       <groupId>war group id</groupId>
       <artifactId>war artifact id</artifactId>
       <type>war</type>
   </deployable>
   <deployable>
     ...
   </deployable>
   ...
 </deployables>
</wso2-deployment>

A challenge: Maven and I are not friends -- nothing works at the first try. The example in the docu does not work - don't know why :-(

Links