Using Java Client
- Create a Maven project
- Add the related admin service Stub to the pom.xml
<dependency>
<groupId>org.wso2.carbon.commons</groupId>
<artifactId>org.wso2.carbon.application.mgt.stub</artifactId>
<version>4.4.7</version>
</dependency>
- Then add the below java class and run it
import java.io.File;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.activation.DataHandler;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator;
import org.apache.commons.io.FileUtils;
import org.wso2.carbon.application.mgt.stub.upload.CarbonAppUploaderStub;
import org.wso2.carbon.application.mgt.stub.upload.types.carbon.UploadedFileItem;
public class CarbonAppUploaderClient {
private CarbonAppUploaderStub st;
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore",
"/home/rukshan/apim_home/repository/resources/security/wso2carbon.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
String path = "/home/rukshan/apim/capp/WSO2-APIM_DAS_Analytics_CApp/API_Manager_Analytics.car";
CarbonAppUploaderClient client = new CarbonAppUploaderClient();
client.init();
client.deploy(path);
}
private void init() {
// TODO Auto-generated method stub
try {
st = new CarbonAppUploaderStub(
"https://localhost:9445/services/CarbonAppUploader");
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
ServiceClient client = st._getServiceClient();
Options client_options = client.getOptions();
Authenticator authenticator = new Authenticator();
authenticator.setUsername("admin");
authenticator.setPassword("admin");
authenticator.setPreemptiveAuthentication(true);
client_options.setProperty(
org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
authenticator);
client.setOptions(client_options);
}
private void deploy(String path) {
// TODO Auto-generated method stub
File file = new File(path);
byte[] byteArray;
try {
byteArray = FileUtils.readFileToByteArray(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
DataHandler dataHandler = new javax.activation.DataHandler(byteArray,
"application/octet-stream");
UploadedFileItem i = new UploadedFileItem();
i.setDataHandler(dataHandler);
i.setFileName("API_Manager_Analytics.car");
i.setFileType("jar");
UploadedFileItem[] ii = new UploadedFileItem[1];
ii[0] = i;
try {
st.uploadApp(ii);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
}
}
- Check whether the operation is successful
Add Comment
Comments (0)