Search in sources :

Example 1 with OAuthAdminServiceStub

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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) MalformedURLException(java.net.MalformedURLException) OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub) ServiceClient(org.apache.axis2.client.ServiceClient) PCRException(com.wso2telco.core.pcrservice.exception.PCRException) URL(java.net.URL)

Example 2 with OAuthAdminServiceStub

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();
    }
}
Also used : OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub)

Example 3 with OAuthAdminServiceStub

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;
}
Also used : OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub) ServiceContext(org.apache.axis2.context.ServiceContext) PCRException(com.wso2telco.core.pcrservice.exception.PCRException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) PCRException(com.wso2telco.core.pcrservice.exception.PCRException)

Aggregations

OAuthAdminServiceStub (org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub)3 PCRException (com.wso2telco.core.pcrservice.exception.PCRException)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AxisFault (org.apache.axis2.AxisFault)1 Options (org.apache.axis2.client.Options)1 ServiceClient (org.apache.axis2.client.ServiceClient)1 ServiceContext (org.apache.axis2.context.ServiceContext)1 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)1 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)1