Search in sources :

Example 36 with ResourcePath

use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-business-process by wso2.

the class DeploymentService method getDeploymentResourceForDifferentUrl.

@GET
@Path("/{deploymentId}/resources/{resourcePath:.*}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDeploymentResourceForDifferentUrl(@PathParam("deploymentId") String deploymentId, @PathParam("resourcePath") String resourcePath) {
    if (log.isDebugEnabled()) {
        log.debug("deploymentId:" + deploymentId + " resourcePath:" + resourcePath);
    }
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    // Check if deployment exists
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
    }
    List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
    if (resourceList.contains(resourcePath)) {
        // Build resource representation
        DeploymentResourceResponse deploymentResourceResponse = new RestResponseFactory().createDeploymentResourceResponse(deploymentId, resourcePath, Utils.resolveContentType(resourcePath), uriInfo.getBaseUri().toString());
        return Response.ok().entity(deploymentResourceResponse).build();
    } else {
        // Resource not found in deployment
        throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourcePath + "' in deployment '" + deploymentId + "'.", Deployment.class);
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) Deployment(org.activiti.engine.repository.Deployment) DeploymentResourceResponse(org.wso2.carbon.bpmn.rest.model.repository.DeploymentResourceResponse) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with ResourcePath

use of org.wso2.carbon.apimgt.api.model.ResourcePath in project identity-test-integration by wso2-incubator.

the class SampleContextEventListener method contextInitialized.

public void contextInitialized(ServletContextEvent servletContextEvent) {
    properties = new Properties();
    try {
        if (servletContextEvent.getServletContext().getContextPath().contains("travelocity.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/travelocity.properties"));
        } else if (servletContextEvent.getServletContext().getContextPath().contains("avis.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/avis.properties"));
        } else {
            String resourcePath = "/WEB-INF/classes" + servletContextEvent.getServletContext().getContextPath() + ".properties";
            InputStream resourceStream = servletContextEvent.getServletContext().getResourceAsStream(resourcePath);
            if (resourceStream != null) {
                properties.load(servletContextEvent.getServletContext().getResourceAsStream(resourcePath));
            }
        }
        InputStream keyStoreInputStream = servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/wso2carbon.jks");
        SSOAgentX509Credential credential = new SSOAgentX509KeyStoreCredential(keyStoreInputStream, properties.getProperty("KeyStorePassword").toCharArray(), properties.getProperty("IdPPublicCertAlias"), properties.getProperty("PrivateKeyAlias"), properties.getProperty("PrivateKeyPassword").toCharArray());
        SSOAgentConfig config = new SSOAgentConfig();
        config.initConfig(properties);
        config.getSAML2().setSSOAgentX509Credential(credential);
        config.getOpenId().setAttributesRequestor(new SampleAttributesRequestor());
        servletContextEvent.getServletContext().setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SSOAgentException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}
Also used : SSOAgentConfig(org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig) InputStream(java.io.InputStream) SSOAgentX509Credential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509Credential) SSOAgentException(org.wso2.carbon.identity.sso.agent.SSOAgentException) IOException(java.io.IOException) Properties(java.util.Properties) SSOAgentX509KeyStoreCredential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509KeyStoreCredential)

Example 38 with ResourcePath

use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.

the class AbstractAPIManager method getApiSpecificMediationResourceFromUuid.

/**
 * Returns Registry resource matching given mediation policy identifier
 *
 * @param identifier   API identifier
 * @param uuid         mediation policy identifier
 * @param resourcePath registry path to the API resource
 * @return Registry resource matches given identifier or null
 * @throws APIManagementException If fails to get the resource matching given identifier
 */
@Override
public Resource getApiSpecificMediationResourceFromUuid(Identifier identifier, String uuid, String resourcePath) throws APIManagementException {
    try {
        Resource resource = registry.get(resourcePath);
        if (resource instanceof Collection) {
            Collection typeCollection = (Collection) resource;
            String[] typeArray = typeCollection.getChildren();
            for (String type : typeArray) {
                // Check for mediation policy resource
                if ((type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN)) || (type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT)) || (type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT))) {
                    Resource sequenceType = registry.get(type);
                    // sequenceType eg: in / out /fault
                    if (sequenceType instanceof Collection) {
                        String[] mediationPolicyArr = ((Collection) sequenceType).getChildren();
                        for (String mediationPolicy : mediationPolicyArr) {
                            Resource mediationResource = registry.get(mediationPolicy);
                            String resourceId = mediationResource.getUUID();
                            if (resourceId.equalsIgnoreCase(uuid)) {
                                return mediationResource;
                            }
                        }
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while obtaining registry objects";
        throw new APIManagementException(msg, e);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 39 with ResourcePath

use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.

the class AbstractAPIManager method getWsdlResourceFromUuid.

/**
 * Returns the wsdl registry resource correspond to the given identifier
 *
 * @param wsdlId uuid of the wsdl resource
 * @return Registry resource of given identifier or null
 * @throws APIManagementException If failed to get the registry resource of given uuid
 */
@Override
public Resource getWsdlResourceFromUuid(String wsdlId) throws APIManagementException {
    String resourcePath = APIConstants.API_WSDL_RESOURCE;
    try {
        if (registry.resourceExists(resourcePath)) {
            Resource resource = registry.get(resourcePath);
            if (resource instanceof Collection) {
                Collection wsdlCollection = (Collection) resource;
                String[] wsdlArray = wsdlCollection.getChildren();
                for (String wsdl : wsdlArray) {
                    Resource wsdlResource = registry.get(wsdl);
                    String resourceId = wsdlResource.getUUID();
                    if (resourceId.equals(wsdlId)) {
                        return wsdlResource;
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while accessing registry objects";
        throw new APIManagementException(msg, e);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 40 with ResourcePath

use of org.wso2.carbon.apimgt.api.model.ResourcePath in project carbon-apimgt by wso2.

the class AbstractAPIManager method addResourceFile.

public String addResourceFile(Identifier identifier, String resourcePath, ResourceFile resourceFile) throws APIManagementException {
    try {
        Resource thumb = registry.newResource();
        thumb.setContentStream(resourceFile.getContent());
        thumb.setMediaType(resourceFile.getContentType());
        registry.put(resourcePath, thumb);
        if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) {
            return RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath;
        } else {
            return "/t/" + tenantDomain + RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath;
        }
    } catch (RegistryException e) {
        String msg = "Error while adding the resource to the registry";
        throw new APIManagementException(msg, e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

Resource (org.wso2.carbon.registry.core.Resource)51 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)48 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)44 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)28 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)25 IOException (java.io.IOException)18 Registry (org.wso2.carbon.registry.core.Registry)16 Collection (org.wso2.carbon.registry.core.Collection)15 UserStoreException (org.wso2.carbon.user.api.UserStoreException)14 Test (org.junit.Test)13 Resource (org.wso2.carbon.registry.api.Resource)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 ArrayList (java.util.ArrayList)11 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)11 RegistryException (org.wso2.carbon.registry.api.RegistryException)11 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)11 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)11 JSONParser (org.json.simple.parser.JSONParser)10 ParseException (org.json.simple.parser.ParseException)10 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)10