Skip to content

Instantly share code, notes, and snippets.

@lahirue
Created October 21, 2015 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahirue/54d0af566fe2fca34897 to your computer and use it in GitHub Desktop.
Save lahirue/54d0af566fe2fca34897 to your computer and use it in GitHub Desktop.
WSO2 Carbon Component UI Service Client
package org.wso2.carbon.testService.ui;
import java.rmi.RemoteException;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.wso2.carbon.testService.ui.types.data.User;
public class UserClient {
MyTestServiceStub stub;
public UserClient(ConfigurationContext configCtx, String backendServerURL, String cookie) throws Exception {
String serviceURL = backendServerURL + "MyTestService";
stub = new MyTestServiceStub(configCtx, serviceURL);
ServiceClient client = stub._getServiceClient();
Options options = client.getOptions();
options.setManageSession(true);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
public User addUser(String anUser, int anAge) throws Exception {
try {
return stub.addUser(anUser, anAge);
} catch (RemoteException e) {
e.printStackTrace();
String msg = "Cannot add the User" + " . Backend service may be unvailable";
throw new Exception(msg, e);
}
}
public User[] displayUsers() throws Exception {
try {
return stub.displayUsers();
} catch (RemoteException e) {
e.printStackTrace();
String msg = "Cannot display the Users" + " . Backend service may be unvailable";
throw new Exception(msg, e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment