Search in sources :

Example 6 with ServerConfiguration

use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method validateEndpoint.

@Override
public Response validateEndpoint(String endpointUrl, String apiId, MessageContext messageContext) {
    ApiEndpointValidationResponseDTO apiEndpointValidationResponseDTO = new ApiEndpointValidationResponseDTO();
    apiEndpointValidationResponseDTO.setError("");
    try {
        URL url = new URL(endpointUrl);
        if (url.getProtocol().matches("https")) {
            ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
            String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
            String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
            System.setProperty("javax.net.ssl.trustStore", trustStorePath);
            System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
            String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
            String keyStoreType = serverConfig.getFirstProperty("Security.KeyStore.Type");
            String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
            System.setProperty("javax.net.ssl.keyStoreType", keyStoreType);
            System.setProperty("javax.net.ssl.keyStore", keyStore);
            System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
            /* apiId can be used to get the related API's uriTemplates. These uriTemplates can be used to extract
                the API operations and append those operations separately to the API endpoint url. This edited url can
                 be used to test the endpoint, in case their is no valid url for the sole endpoint url provided. */
            apiEndpointValidationResponseDTO = sendHttpHEADRequest(endpointUrl);
            return Response.status(Response.Status.OK).entity(apiEndpointValidationResponseDTO).build();
        } else if (url.getProtocol().matches("http")) {
            apiEndpointValidationResponseDTO = sendHttpHEADRequest(endpointUrl);
            return Response.status(Response.Status.OK).entity(apiEndpointValidationResponseDTO).build();
        }
    } catch (MalformedURLException e) {
        log.error("Malformed Url error occurred while sending the HEAD request to the given endpoint url:", e);
        apiEndpointValidationResponseDTO.setError(e.getMessage());
    } catch (Exception e) {
        RestApiUtil.handleInternalServerError("Error while testing the validity of API endpoint url " + "existence", e, log);
    }
    return Response.status(Response.Status.OK).entity(apiEndpointValidationResponseDTO).build();
}
Also used : MalformedURLException(java.net.MalformedURLException) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) ApiEndpointValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApiEndpointValidationResponseDTO) URL(java.net.URL) JSONException(org.json.JSONException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SdkClientException(com.amazonaws.SdkClientException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) URISyntaxException(java.net.URISyntaxException) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException) CryptoException(org.wso2.carbon.core.util.CryptoException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException)

Example 7 with ServerConfiguration

use of org.wso2.carbon.base.ServerConfiguration in project carbon-business-process by wso2.

the class RemovableTaskCleanupJob method execute.

/**
 * The task clean up execution logic.
 */
public void execute() {
    HumanTaskServerConfiguration serverConfiguration = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getServerConfig();
    final SimpleQueryCriteria queryCriteria = createQueryCriteria(serverConfiguration);
    log.info("Running the task cleanup service.....");
    try {
        HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                HumanTaskDAOConnection daoConnection = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection();
                daoConnection.removeTasks(queryCriteria);
                return null;
            }
        });
    } catch (Exception ex) {
        String errMsg = "Task Cleanup operation failed! :";
        log.error(errMsg, ex);
        throw new HumanTaskRuntimeException(errMsg, ex);
    }
}
Also used : HumanTaskServerConfiguration(org.wso2.carbon.humantask.core.configuration.HumanTaskServerConfiguration) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) SimpleQueryCriteria(org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)

Example 8 with ServerConfiguration

use of org.wso2.carbon.base.ServerConfiguration in project carbon-business-process by wso2.

the class RemovableTaskCleanupJob method createQueryCriteria.

/**
 * Create task removal query criteria.
 *
 * @param serverConfiguration : The server config.
 * @return : The SimpleQueryCriteria.
 */
private SimpleQueryCriteria createQueryCriteria(HumanTaskServerConfiguration serverConfiguration) {
    SimpleQueryCriteria queryCriteria = new SimpleQueryCriteria();
    queryCriteria.setSimpleQueryType(SimpleQueryCriteria.QueryType.REMOVE_TASKS);
    queryCriteria.setStatuses(serverConfiguration.getRemovableTaskStatuses());
    return queryCriteria;
}
Also used : SimpleQueryCriteria(org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)

Example 9 with ServerConfiguration

use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.

the class APIUtilTest method testCreateDocArtifactContent.

@Test
public void testCreateDocArtifactContent() throws GovernanceException, APIManagementException {
    API api = getUniqueAPI();
    PowerMockito.mockStatic(CarbonUtils.class);
    ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class);
    Mockito.when(serverConfiguration.getFirstProperty("WebContextRoot")).thenReturn("/abc").thenReturn("/");
    PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration);
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    Documentation documentation = new Documentation(DocumentationType.HOWTO, "this is a doc");
    documentation.setSourceType(Documentation.DocumentSourceType.FILE);
    documentation.setCreatedDate(new Date(System.currentTimeMillis()));
    documentation.setSummary("abcde");
    documentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL);
    documentation.setSourceUrl("/abcd/def");
    documentation.setOtherTypeName("aa");
    APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation);
    documentation.setSourceType(Documentation.DocumentSourceType.INLINE);
    APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation);
    documentation.setSourceType(Documentation.DocumentSourceType.URL);
    APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation);
    try {
        documentation.setSourceType(Documentation.DocumentSourceType.URL);
        Mockito.doThrow(GovernanceException.class).when(genericArtifact).setAttribute(APIConstants.DOC_SOURCE_URL, documentation.getSourceUrl());
        APIUtil.createDocArtifactContent(genericArtifact, api.getId(), documentation);
        Assert.fail();
    } catch (APIManagementException ex) {
        Assert.assertTrue(ex.getMessage().contains("Failed to create doc artifact content from :"));
    }
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) API(org.wso2.carbon.apimgt.api.model.API) Date(java.util.Date) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ServerConfiguration

use of org.wso2.carbon.base.ServerConfiguration in project carbon-apimgt by wso2.

the class APIUtilTest method testGetDocumentationByDocCreator.

@Test
public void testGetDocumentationByDocCreator() throws Exception {
    PowerMockito.mockStatic(CarbonUtils.class);
    ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class);
    Mockito.when(serverConfiguration.getFirstProperty("WebContextRoot")).thenReturn("/abc").thenReturn("/");
    PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration);
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_TYPE)).thenReturn(DocumentationType.HOWTO.getType()).thenReturn(DocumentationType.PUBLIC_FORUM.getType()).thenReturn(DocumentationType.SUPPORT_FORUM.getType()).thenReturn(DocumentationType.API_MESSAGE_FORMAT.getType()).thenReturn(DocumentationType.SAMPLES.getType()).thenReturn(DocumentationType.OTHER.getType());
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_NAME)).thenReturn("Docname");
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_VISIBILITY)).thenReturn(null).thenReturn(Documentation.DocumentVisibility.API_LEVEL.name()).thenReturn(Documentation.DocumentVisibility.PRIVATE.name()).thenReturn(Documentation.DocumentVisibility.OWNER_ONLY.name());
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_SOURCE_TYPE)).thenReturn(Documentation.DocumentSourceType.URL.name()).thenReturn(Documentation.DocumentSourceType.FILE.name());
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_SOURCE_URL)).thenReturn("https://localhost");
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_FILE_PATH)).thenReturn("file://abc");
    Mockito.when(genericArtifact.getAttribute(APIConstants.DOC_OTHER_TYPE_NAME)).thenReturn("abc");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin");
    APIUtil.getDocumentation(genericArtifact, "admin@wso2.com");
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ServerConfiguration (org.wso2.carbon.base.ServerConfiguration)13 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 Before (org.junit.Before)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)3 APIManagerConfigurationServiceImpl (org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl)3 IOException (java.io.IOException)2 Cache (javax.cache.Cache)2 SimpleQueryCriteria (org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)2 SdkClientException (com.amazonaws.SdkClientException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1