use of org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub in project core-util by WSO2Telco.
the class OAuthApplicationDataStubFactory method generateStub.
/**
* This is used to create a stub which will be triggered through object pool factory, which will create an
* instance of it.
*
* @return OAuth2TokenValidationServiceStub stub that is used to call an external service.
* @throws PCRException will be thrown when initialization failed.
*/
private OAuthAdminServiceStub generateStub() throws PCRException {
OAuthAdminServiceStub stub;
try {
URL hostURL = new URL(config.getHostUrl());
// ConfigurationContext myConfigContext =
// ConfigurationContextFactory.createConfigurationContextFromFileSystem(
// "repo", CarbonUtils.getCarbonConfigDirPath() + File.separator + "axis2" + File.separator +
// "axis2.xml");
stub = new OAuthAdminServiceStub(null, hostURL.toString());
ServiceClient client = stub._getServiceClient();
client.getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setPreemptiveAuthentication(true);
String username = config.getUsername();
String password = config.getPassword();
auth.setUsername(username);
auth.setPassword(password);
Options options = client.getOptions();
options.setProperty(HTTPConstants.AUTHENTICATE, auth);
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
client.setOptions(options);
} catch (AxisFault axisFault) {
log.error("Error occurred while creating the OAuth2TokenValidationServiceStub.");
throw new PCRException("Error occurred while creating the OAuth2TokenValidationServiceStub.", axisFault);
} catch (MalformedURLException e) {
log.error("Malformed URL error");
throw new PCRException("Malformed URL error", e);
}
return stub;
}
use of org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub in project core-util by WSO2Telco.
the class OAuthApplicationDataStubFactory method passivateObject.
/**
* This is used to clean up the OAuth validation stub and releases to the object pool.
*
* @param o object that needs to be released.
* @throws Exception throws when failed to release to the pool
*/
@Override
public void passivateObject(Object o) throws Exception {
if (o instanceof OAuthAdminServiceStub) {
OAuthAdminServiceStub stub = (OAuthAdminServiceStub) o;
stub._getServiceClient().cleanupTransport();
}
}
use of org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub in project core-util by WSO2Telco.
the class OAuthApplicationData method getApplicationData.
public OAuthConsumerAppDTO getApplicationData(String appId) throws PCRException {
OAuthConsumerAppDTO apps = null;
OAuthAdminServiceStub oAuthAdminServiceStub;
try {
if (DEBUG)
log.debug("initializing the o Auth Admin Service stub");
Object stub = this.stubs.borrowObject();
if (stub != null) {
oAuthAdminServiceStub = (OAuthAdminServiceStub) stub;
if (cookie != null) {
oAuthAdminServiceStub._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie);
}
apps = oAuthAdminServiceStub.getOAuthApplicationData(appId);
// apps = oAuthAdminServiceStub.getAllOAuthApplicationData();
ServiceContext serviceContext = oAuthAdminServiceStub._getServiceClient().getLastOperationContext().getServiceContext();
cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
} else {
log.warn("Stub initialization failed.");
}
} catch (Exception e) {
log.error("error initializing the stub", e);
throw new PCRException("error initializing the stub");
}
return apps;
}
Aggregations