Search in sources :

Example 56 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class HTCoordinationContextHandler method invoke.

@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
    if (serverConfig == null || !serverConfig.isTaskRegistrationEnabled()) {
        return InvocationResponse.CONTINUE;
    }
    SOAPHeader soapHeader;
    try {
        soapHeader = messageContext.getEnvelope().getHeader();
    } catch (OMException ex) {
        throw new AxisFault("Error while extracting SOAP header", ex);
    }
    if (soapHeader == null) {
        if (log.isDebugEnabled()) {
            log.debug("No SOAP Header received. Continuing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    Iterator headers = soapHeader.getChildElements();
    SOAPHeaderBlock coordinationHeaderBlock = null;
    // Searching for WS-Coor Coordination Context
    while (headers.hasNext()) {
        SOAPHeaderBlock hb = (SOAPHeaderBlock) headers.next();
        if (hb.getLocalName().equals(Constants.WS_COOR_COORDINATION_CONTEXT) && hb.getNamespace().getNamespaceURI().equals(Constants.WS_COOR_NAMESPACE)) {
            coordinationHeaderBlock = hb;
            break;
        }
    }
    if (coordinationHeaderBlock == null) {
        if (log.isDebugEnabled()) {
            log.debug("No coordination context received. Processing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    // We have received a ws-coordination context. Now validate it for HT coordination type
    String coordinationType = SOAPUtils.getCoordinationType(coordinationHeaderBlock);
    if (!Constants.WS_HT_COORDINATION_TYPE.equals(coordinationType)) {
        // Found wrong coordination Type. We Only support http://docs.oasis-open.org/ns/bpel4people/ws-humantask/protocol/200803.
        // So we cannot allow message to go forward.
        String errorMsg = "Message aborted ! Invalid coordination type" + coordinationType + " . Support only " + Constants.WS_HT_COORDINATION_TYPE;
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    if (log.isDebugEnabled()) {
        log.debug("HT coordination context received.");
    }
    String identifier = SOAPUtils.getCoordinationIdentifier(coordinationHeaderBlock);
    String registrationService = SOAPUtils.getRegistrationService(coordinationHeaderBlock);
    // validating values. These values cannot be empty
    if (identifier == null || identifier.isEmpty() || registrationService == null || registrationService.isEmpty()) {
        String errorMsg = "Message aborted ! Invalid coordination context parameters.";
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    // Service URL of the HumanTask Coordination Protocol Handler AdminService
    String humanTaskProtocolHandlerServiceURL;
    try {
        humanTaskProtocolHandlerServiceURL = ServiceUtils.getTaskProtocolHandlerURL(messageContext.getConfigurationContext());
    } catch (HumanTaskCoordinationException e) {
        String errorMsg = "Error while generating HumanTask engine's protocol Handler Service URL.";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    // We are OK to invokeRegistrationService Registration service
    try {
        OMElement response = invokeRegistrationServiceUsingServiceClient(identifier, humanTaskProtocolHandlerServiceURL, registrationService);
        // But we are validating it for successful completion.
        if (!SOAPUtils.validateResponse(response, identifier)) {
            String errorMsg = "Message aborted ! registration response validation failed.";
            log.error(errorMsg);
            return InvocationResponse.ABORT;
        }
        // successful coordination
        if (log.isDebugEnabled()) {
            log.debug("RegistrationResponse received. Task is successfully coordinated with Task parent.");
        }
    } catch (AxisFault e) {
        String errorMsg = "Error while invoking registration service";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    return InvocationResponse.CONTINUE;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Iterator(java.util.Iterator) HumanTaskCoordinationException(org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 57 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class BPMNUploader method uploadService.

public void uploadService(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writing the artifacts to the proper location
    String bpmnDirectory = repo + File.separator + BPMNConstants.BPMN_REPO_NAME;
    String bpmnTemp = CarbonUtils.getCarbonHome() + BPMNConstants.BPMN_PACKAGE_TEMP_DIRECTORY;
    File bpmnTempDir = new File(bpmnTemp);
    if (!bpmnTempDir.exists() && !bpmnTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnTempDir.getAbsolutePath());
    }
    File bpmnDir = new File(bpmnDirectory);
    if (!bpmnDir.exists() && !bpmnDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (uploadedFile.getFileType().equals(BPMNConstants.BPMN_PACKAGE_EXTENSION)) {
            try {
                writeResource(uploadedFile.getDataHandler(), bpmnTemp, fileName, bpmnDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + BPMNConstants.BPMN_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.bpmn.core.mgt.model.UploadedFileItem) IOException(java.io.IOException) File(java.io.File)

Example 58 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class HumanTaskDeployer method createHumanTaskRepository.

private void createHumanTaskRepository(ConfigurationContext configCtx) throws DeploymentException {
    String axisRepoPath = configCtx.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        throw new DeploymentException("URL Repositories are not supported: " + axisRepoPath);
    }
    File tenantsRepository = new File(axisRepoPath);
    File humanTaskRepo = new File(tenantsRepository, HumanTaskConstants.HUMANTASK_REPO_DIRECTORY);
    if (!humanTaskRepo.exists()) {
        boolean status = humanTaskRepo.mkdir();
        if (!status) {
            throw new DeploymentException("Failed to create HumanTask repository directory " + humanTaskRepo.getAbsolutePath() + ".");
        }
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 59 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class GlobalThrottleEngineClient method deleteExecutionPlan.

/**
 * This method will be used to delete single execution plan.
 * @param name execution plan name to be deleted.
 */
public void deleteExecutionPlan(String name) {
    ServiceClient serviceClient;
    Options options;
    String sessionID = null;
    try {
        sessionID = login();
    } catch (RemoteException e) {
        log.error("Error while connecting to login central policy management server" + e.getMessage());
    } catch (LoginAuthenticationExceptionException e) {
        log.error("Error while connecting to login central policy management server, " + "Check user name and password" + e.getMessage());
    } catch (MalformedURLException e) {
        log.error("Error while connecting to login central policy management server, check URL" + e.getMessage());
    }
    EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null;
    try {
        eventProcessorAdminServiceStub = getEventProcessorAdminServiceStub();
        serviceClient = eventProcessorAdminServiceStub._getServiceClient();
        options = serviceClient.getOptions();
        options.setManageSession(true);
        options.setProperty(HTTPConstants.COOKIE_STRING, sessionID);
        eventProcessorAdminServiceStub.undeployActiveExecutionPlan(name);
    } catch (AxisFault axisFault) {
        log.error("Error while connecting to login central policy management server to delete " + "execution plan." + axisFault);
    } catch (RemoteException e) {
        log.error("Error while connecting to login central policy management server to delete " + "execution plan." + e.getMessage());
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) MalformedURLException(java.net.MalformedURLException) ServiceClient(org.apache.axis2.client.ServiceClient) EventProcessorAdminServiceStub(org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub) RemoteException(java.rmi.RemoteException) LoginAuthenticationExceptionException(org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException)

Example 60 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class TenantServiceCreatorTestCase method testCreatedConfigurationContext.

@Test
public void testCreatedConfigurationContext() throws Exception {
    TenantServiceCreator tenantServiceCreator = new TenantServiceCreator();
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    // Failed to create Tenant's synapse sequences Error
    PowerMockito.mockStatic(Cache.class);
    Cache cache = Mockito.mock(Cache.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(APIManagerConfigurationService.class);
    PowerMockito.mockStatic(CacheProvider.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    final APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    CacheProvider cacheProvider = Mockito.mock(CacheProvider.class);
    PowerMockito.when(cacheProvider.getDefaultCacheTimeout()).thenReturn((long) 900);
    Mockito.when(CacheProvider.getGatewayKeyCache()).thenReturn(cache);
    Mockito.when(CacheProvider.getResourceCache()).thenReturn(cache);
    Mockito.when(CacheProvider.getGatewayTokenCache()).thenReturn(cache);
    Mockito.when(CacheProvider.getInvalidTokenCache()).thenReturn(cache);
    tenantServiceCreator.createdConfigurationContext(configurationContext);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(FileUtils.class);
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("abc.com");
    AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
    Mockito.when(configurationContext.getAxisConfiguration()).thenReturn(axisConfiguration);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    URL url = new URL("http", "localhost", 5000, "/fle/");
    Mockito.when(axisConfiguration.getRepository()).thenReturn(url);
    File tenantAxis2Repo = Mockito.mock(File.class);
    File synapseConfigsDir = Mockito.mock(File.class);
    // Couldn't create the synapse-config root on the file system error is logged.
    tenantServiceCreator.createdConfigurationContext(configurationContext);
    PowerMockito.whenNew(File.class).withArguments("/file/").thenReturn(tenantAxis2Repo);
    PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(synapseConfigsDir);
    Mockito.when(synapseConfigsDir.mkdir()).thenReturn(true);
    String synapseConfigsDirLocation = "/file/synapse-confgs";
    Mockito.when(synapseConfigsDir.getAbsolutePath()).thenReturn(synapseConfigsDirLocation);
    Mockito.doNothing().when(axisConfiguration).addParameter(SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);
    UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
    ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class);
    Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_CONFIGURATION)).thenReturn(userRegistry);
    PowerMockito.whenNew(ConfigurationManager.class).withArguments(userRegistry, configurationContext).thenReturn(configurationManager);
    ConfigurationTracker tracker = Mockito.mock(ConfigurationTracker.class);
    Mockito.when(configurationManager.getTracker()).thenReturn(tracker);
    Mockito.when(tracker.getCurrentConfigurationName()).thenReturn("config-name");
    Mockito.when(synapseConfigsDir.exists()).thenReturn(false, false, false, true);
    copyFile("/repository/resources/apim-synapse-config/main.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "main.xml");
    copyFile("/repository/resources/apim-synapse-config/fault.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "falut.xml");
    copyFile("/repository/resources/apim-synapse-config/_auth_failure_handler_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_auth_failure_handler_.xml");
    copyFile("/repository/resources/apim-synapse-config/_resource_mismatch_handler_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_resource_mismatch_handler_.xml");
    copyFile("/repository/resources/apim-synapse-config/_throttle_out_handler_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_throttle_out_handler_.xml");
    copyFile("/repository/resources/apim-synapse-config/_sandbox_key_error_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_sandbox_key_error_.xml");
    copyFile("/repository/resources/apim-synapse-config/_production_key_error_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_production_key_error_.xml");
    copyFile("/repository/resources/apim-synapse-config/_cors_request_handler_.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_cors_request_handler_.xml");
    copyFile("/repository/resources/apim-synapse-config/_threat_fault.xml", "/file/synapse-confgs" + File.separator + "sequences" + File.separator + "_threat_fault.xml");
    // test IOException Error while copying API manager specific synapse sequences
    tenantServiceCreator.createdConfigurationContext(configurationContext);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ConfigurationTracker(org.wso2.carbon.mediation.initializer.configurations.ConfigurationTracker) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) CacheProvider(org.wso2.carbon.apimgt.impl.caching.CacheProvider) URL(java.net.URL) File(java.io.File) ConfigurationManager(org.wso2.carbon.mediation.initializer.configurations.ConfigurationManager) Cache(javax.cache.Cache) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)31 EndpointReference (org.apache.axis2.addressing.EndpointReference)29 AxisFault (org.apache.axis2.AxisFault)27 URL (java.net.URL)21 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)19 URL (org.apache.axis2.util.URL)19 HttpClient (org.apache.http.client.HttpClient)19 Options (org.apache.axis2.client.Options)18 MalformedURLException (java.net.MalformedURLException)17 OMElement (org.apache.axiom.om.OMElement)17 MessageContext (org.apache.axis2.context.MessageContext)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 ServiceClient (org.apache.axis2.client.ServiceClient)13 SynapseException (org.apache.synapse.SynapseException)13 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)12 AxisService (org.apache.axis2.description.AxisService)10 StringEntity (org.apache.http.entity.StringEntity)9 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)9 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7