Search in sources :

Example 26 with ApiException

use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.

the class RestApiAdminService method updateApiFromString.

/**
 * Updates a given API configuration passed in as a string.
 *
 * @param apiName       Name of the API to be updated
 * @param apiData       API configuration to be updated, as a string
 * @return              Status of the execution of updating the given API configuration
 * @throws APIException Is thrown if an anomaly is encountered while updating the given API
 */
public boolean updateApiFromString(String apiName, String apiData) throws APIException {
    final Lock lock = getLock();
    try {
        lock.lock();
        assertNameNotEmpty(log, apiName);
        OMElement apiElement = AXIOMUtil.stringToOM(apiData);
        // Set API name to old value since we do not allow editing the API name.
        OMAttribute nameAttribute = apiElement.getAttribute(new QName("name"));
        if (nameAttribute == null || "".equals(nameAttribute.getAttributeValue().trim())) {
            apiElement.addAttribute("name", apiName, null);
        }
        API api = APIFactory.createAPI(apiElement);
        SynapseConfiguration synapseConfiguration = RestApiAdminUtils.getSynapseConfiguration();
        API oldAPI = synapseConfiguration.getAPI(apiName);
        if (oldAPI != null) {
            oldAPI.destroy();
            api.setFileName(oldAPI.getFileName());
        }
        synapseConfiguration.removeAPI(apiName);
        synapseConfiguration.addAPI(api.getName(), api);
        api.init(RestApiAdminUtils.getSynapseEnvironment());
        if ((oldAPI != null ? oldAPI.getArtifactContainerName() : null) != null) {
            api.setArtifactContainerName(oldAPI.getArtifactContainerName());
            api.setIsEdited(true);
            getApiByName(apiName).setIsEdited(true);
        } else {
            if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode"))) {
                MediationPersistenceManager pm = RestApiAdminUtils.getMediationPersistenceManager();
                String fileName = api.getFileName();
                pm.deleteItem(apiName, fileName, ServiceBusConstants.ITEM_TYPE_REST_API);
                pm.saveItem(apiName, ServiceBusConstants.ITEM_TYPE_REST_API);
            }
        }
        return true;
    } catch (XMLStreamException e) {
        handleException(log, "Could not parse String to OMElement", e);
        return false;
    } finally {
        lock.unlock();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName) MediationPersistenceManager(org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager) OMElement(org.apache.axiom.om.OMElement) API(org.apache.synapse.api.API) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) OMAttribute(org.apache.axiom.om.OMAttribute) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 27 with ApiException

use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-identity-framework by wso2.

the class SelfRegisterApi method validateCodePostCall.

/**
 * This API is used to validate code of self reigstered users
 *
 * @param code Code retried after user self registration and optional property parameters (required)
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public void validateCodePostCall(CodeValidationRequest code) throws ApiException {
    Object localVarPostBody = code;
    // verify the required parameter 'code' is set
    if (code == null) {
        throw new ApiException(400, "Missing the required parameter 'code' when calling validateCodePost(Async)");
    }
    String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = code.getProperties();
    for (Property property : properties) {
        if (StringUtils.isNotEmpty(property.getKey()) && MultitenantConstants.TENANT_DOMAIN.equals(property.getKey())) {
            tenantDomain = property.getValue();
        }
    }
    basePath = IdentityManagementEndpointUtil.getBasePath(tenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.USER_API_RELATIVE_PATH);
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/validate-code".replaceAll("\\{format\\}", "json");
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);
    String[] localVarAuthNames = new String[] {};
    GenericType<String> localVarReturnType = new GenericType<String>() {
    };
    apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
Also used : GenericType(com.sun.jersey.api.client.GenericType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Example 28 with ApiException

use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-identity-framework by wso2.

the class SelfRegisterApi method validateCodeUserPostCall.

/**
 * This API is used to validate code of self reigstered users
 *
 * @param code Code retried after user self registration and optional property parameters (required)
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public User validateCodeUserPostCall(CodeValidationRequest code) throws ApiException {
    Object localVarPostBody = code;
    // verify the required parameter 'code' is set
    if (code == null) {
        throw new ApiException(400, "Missing the required parameter 'code' when calling validateCodePost(Async)");
    }
    String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = code.getProperties();
    for (Property property : properties) {
        if (StringUtils.isNotEmpty(property.getKey()) && MultitenantConstants.TENANT_DOMAIN.equals(property.getKey())) {
            tenantDomain = property.getValue();
        }
    }
    if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
        basePath = IdentityManagementEndpointUtil.getBasePath(tenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.USER_API_RELATIVE_PATH);
    }
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/validate-code".replaceAll("\\{format\\}", "json");
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);
    String[] localVarAuthNames = new String[] {};
    GenericType<User> localVarReturnType = new GenericType<User>() {
    };
    return apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
Also used : GenericType(com.sun.jersey.api.client.GenericType) User(org.wso2.carbon.identity.mgt.endpoint.util.client.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Aggregations

API (org.apache.synapse.api.API)16 Lock (java.util.concurrent.locks.Lock)10 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)10 APIException (org.wso2.carbon.rest.api.APIException)9 APIGenException (org.wso2.carbon.mediation.commons.rest.api.swagger.APIGenException)8 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 ApiException (org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 SocketException (java.net.SocketException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Pair (org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)6 Property (org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property)6 MediationPersistenceManager (org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager)6 GenericType (com.sun.jersey.api.client.GenericType)4 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)4 QName (javax.xml.namespace.QName)3