Search in sources :

Example 96 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-business-process by wso2.

the class AxisServiceUtils method invokeService.

public static void invokeService(BPELMessageContext partnerInvocationContext, ConfigurationContext configContext) throws AxisFault {
    MessageContext mctx = partnerInvocationContext.getInMessageContext();
    OperationClient opClient = getOperationClient(partnerInvocationContext, configContext);
    mctx.getOptions().setParent(opClient.getOptions());
    /*
        Else we assume that the epr is not changed by the process.
        In this case there's a limitation we cannot invoke the epr in the wsdl
        (by assingning that epr by partnerlink assign) if there is a endpoint
        configuration available for that particular service
        */
    addCustomHeadersToMessageContext(mctx);
    opClient.addMessageContext(mctx);
    Options operationOptions = opClient.getOptions();
    if (partnerInvocationContext.getUep().isAddressingEnabled()) {
        // Currently we set the action manually, but this should be handled by
        // addressing module it-self?
        String action = getAction(partnerInvocationContext);
        if (log.isDebugEnabled()) {
            log.debug("Soap action: " + action);
        }
        operationOptions.setAction(action);
    // TODO set replyto as well
    // operationOptions.setReplyTo(mctx.getReplyTo());
    }
    if (partnerInvocationContext.getUep().getAddress() == null) {
        partnerInvocationContext.getUep().setAddress(getEPRfromWSDL(partnerInvocationContext.getBpelServiceWSDLDefinition(), partnerInvocationContext.getService(), partnerInvocationContext.getPort()));
    }
    operationOptions.setTo(partnerInvocationContext.getUep());
    opClient.execute(true);
    if (partnerInvocationContext.isTwoWay()) {
        partnerInvocationContext.setOutMessageContext(opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
        partnerInvocationContext.setFaultMessageContext(opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE));
    }
}
Also used : OperationClient(org.apache.axis2.client.OperationClient) Options(org.apache.axis2.client.Options) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) MessageContext(org.apache.axis2.context.MessageContext)

Example 97 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-business-process by wso2.

the class BPELServerImpl method initProcessStore.

/**
 * Initialize process store/
 *
 * @param eprContext Endpoint reference context
 * @throws Exception if process store initialization failed
 */
private void initProcessStore(EndpointReferenceContext eprContext) throws Exception {
    processStore = new ProcessStoreImpl(eprContext, db.getDataSource(), odeConfigurationProperties);
    processStore.setLocalBPELDeploymentUnitRepo(new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "bpel"));
    processStore.registerListener(new ProcessStoreListenerImpl());
}
Also used : TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl) ProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.ProcessStoreImpl) File(java.io.File)

Example 98 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-business-process by wso2.

the class ProcessConfigurationImpl method readPackageConfiguration.

private void readPackageConfiguration() {
    File depDir = du.getDeployDir();
    /*
        Read Endpoint Config for invokes
         */
    List<TDeployment.Process> processList = du.getDeploymentDescriptor().getDeploy().getProcessList();
    for (TDeployment.Process process : processList) {
        List<TInvoke> tInvokeList = process.getInvokeList();
        for (TInvoke tInvoke : tInvokeList) {
            OMElement serviceEle;
            if (tInvoke.getService() == null) {
                String errMsg = "Service element missing for the invoke element in deploy.xml";
                log.error(errMsg);
                throw new BPELDeploymentException(errMsg);
            }
            try {
                serviceEle = AXIOMUtil.stringToOM(tInvoke.getService().toString());
                OMElement endpointEle = serviceEle.getFirstElement();
                if (endpointEle == null || !endpointEle.getQName().equals(new QName(BusinessProcessConstants.BPEL_PKG_ENDPOINT_CONFIG_NS, BusinessProcessConstants.ENDPOINT))) {
                    continue;
                }
                EndpointConfiguration epConf = EndpointConfigBuilder.buildEndpointConfiguration(endpointEle, depDir.getAbsolutePath());
                epConf.setServiceName(tInvoke.getService().getName().getLocalPart());
                epConf.setServiceNS(tInvoke.getService().getName().getNamespaceURI());
                epConf.setServicePort(tInvoke.getService().getPort());
                bpelPackageConfiguration.addEndpoint(epConf);
            } catch (XMLStreamException e) {
                log.warn("Error occurred while reading endpoint configuration. " + "Endpoint config will not be applied to: " + tInvoke.getService());
            }
        }
        List<TProvide> tProvideList = process.getProvideList();
        for (TProvide tProvide : tProvideList) {
            OMElement serviceEle;
            if (tProvide.getService() == null) {
                String errMsg = "Service element missing for the provide element in deploy.xml";
                log.error(errMsg);
                throw new BPELDeploymentException(errMsg);
            }
            try {
                serviceEle = AXIOMUtil.stringToOM(tProvide.getService().toString());
                OMElement endpointEle = serviceEle.getFirstElement();
                if (endpointEle == null || !endpointEle.getQName().equals(new QName(BusinessProcessConstants.BPEL_PKG_ENDPOINT_CONFIG_NS, BusinessProcessConstants.ENDPOINT))) {
                    continue;
                }
                EndpointConfiguration epConf = EndpointConfigBuilder.buildEndpointConfiguration(endpointEle, depDir.getAbsolutePath());
                epConf.setServiceName(tProvide.getService().getName().getLocalPart());
                epConf.setServiceNS(tProvide.getService().getName().getNamespaceURI());
                epConf.setServicePort(tProvide.getService().getPort());
                bpelPackageConfiguration.addEndpoint(epConf);
            } catch (XMLStreamException e) {
                log.warn("Error occured while reading endpoint configuration. " + "Endpoint config will not be applied to: " + tProvide.getService());
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) TDeployment(org.apache.ode.bpel.dd.TDeployment) TInvoke(org.apache.ode.bpel.dd.TInvoke) XMLStreamException(javax.xml.stream.XMLStreamException) EndpointConfiguration(org.wso2.carbon.bpel.common.config.EndpointConfiguration) TProvide(org.apache.ode.bpel.dd.TProvide) File(java.io.File)

Example 99 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-business-process by wso2.

the class ProcessManagementServiceSkeleton method fillPartnerLinks.

// private java.lang.String[] getServiceLocationForProcess(QName processId)
// throws ProcessManagementException {
// AxisConfiguration axisConf = getConfigContext().getAxisConfiguration();
// Map<String, AxisService> services = axisConf.getServices();
// ArrayList<String> serviceEPRs = new ArrayList<String>();
// 
// for (AxisService service : services.values()) {
// Parameter pIdParam = service.getParameter(BPELConstants.PROCESS_ID);
// if (pIdParam != null) {
// if (pIdParam.getValue().equals(processId)) {
// serviceEPRs.addAll(Arrays.asList(service.getEPRs()));
// }
// }
// }
// 
// if (serviceEPRs.size() > 0) {
// return serviceEPRs.toArray(new String[serviceEPRs.size()]);
// }
// 
// String errMsg = "Cannot find service for process: " + processId;
// log.error(errMsg);
// throw new ProcessManagementException(errMsg);
// }
private void fillPartnerLinks(ProcessInfoType pInfo, TDeployment.Process processInfo) throws ProcessManagementException {
    if (processInfo.getProvideList() != null) {
        EndpointReferencesType eprsType = new EndpointReferencesType();
        for (TProvide provide : processInfo.getProvideList()) {
            String plinkName = provide.getPartnerLink();
            TService service = provide.getService();
            /* NOTE:Service cannot be null for provider partner link*/
            if (service == null) {
                String errorMsg = "Error in <provide> element for process " + processInfo.getName() + " partnerlink" + plinkName + " did not identify an endpoint";
                log.error(errorMsg);
                throw new ProcessManagementException(errorMsg);
            }
            if (log.isDebugEnabled()) {
                log.debug("Processing <provide> element for process " + processInfo.getName() + ": partnerlink " + plinkName + " --> " + service.getName() + " : " + service.getPort());
            }
            QName serviceName = service.getName();
            EndpointRef_type0 eprType = new EndpointRef_type0();
            eprType.setPartnerLink(plinkName);
            eprType.setService(serviceName);
            ServiceLocation sLocation = new ServiceLocation();
            try {
                String url = Utils.getTryitURL(serviceName.getLocalPart(), getConfigContext());
                sLocation.addServiceLocation(url);
                String[] wsdls = Utils.getWsdlInformation(serviceName.getLocalPart(), getConfigContext().getAxisConfiguration());
                if (wsdls.length == 2) {
                    if (wsdls[0].endsWith("?wsdl")) {
                        sLocation.addServiceLocation(wsdls[0]);
                    } else {
                        sLocation.addServiceLocation(wsdls[1]);
                    }
                }
            } catch (AxisFault axisFault) {
                String errMsg = "Error while getting try-it url for the service: " + serviceName;
                log.error(errMsg, axisFault);
                throw new ProcessManagementException(errMsg, axisFault);
            }
            eprType.setServiceLocations(sLocation);
            eprsType.addEndpointRef(eprType);
        }
        pInfo.setEndpoints(eprsType);
    }
// if (processInfo.getInvokeList() != null) {
// for (TInvoke invoke : processInfo.getInvokeList()) {
// String plinkName = invoke.getPartnerLink();
// TService service = invoke.getService();
// /* NOTE:Service can be null for partner links*/
// if (service == null) {
// continue;
// }
// if (log.isDebugEnabled()) {
// log.debug("Processing <invoke> element for process " + processInfo.getName() + ": partnerlink" +
// plinkName + " -->" + service);
// }
// 
// QName serviceName = service.getName();
// }
// }
}
Also used : AxisFault(org.apache.axis2.AxisFault) QName(javax.xml.namespace.QName) ServiceLocation(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ServiceLocation) EndpointReferencesType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EndpointReferencesType) EndpointRef_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EndpointRef_type0) TProvide(org.apache.ode.bpel.dd.TProvide) TService(org.apache.ode.bpel.dd.TService) ProcessManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException)

Example 100 with Endpoint

use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-business-process by wso2.

the class RegistrationService method registerOperation.

@Override
public RegisterResponseType registerOperation(URI uri, EndpointReferenceType endpointReferenceType, OMElement[] omElements) {
    if (!CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
        log.warn("Registration request is discarded. Registration service is disabled in this server");
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("Registration request received.");
    }
    URI htIdentifierURI = null;
    try {
        htIdentifierURI = new URI(HT_COORDINATION_PROTOCOL);
    } catch (URI.MalformedURIException e) {
        log.error(e);
    }
    if (!htIdentifierURI.equals(uri)) {
        String errorMsg = "Received an invalid Protocol identifier: " + uri.toString();
        log.error(errorMsg);
        return null;
    }
    String participantProtocolService = "";
    if (endpointReferenceType != null && endpointReferenceType.getAddress() != null) {
        participantProtocolService = endpointReferenceType.getAddress().toString();
    } else {
        String errorMsg = "Received an invalid Participant Protocol Service";
        log.error(errorMsg);
    }
    String messageID = "";
    boolean foundB4PMessageID = false;
    if (omElements.length > 0) {
        for (OMElement omElement : omElements) {
            if (B4P_NAMESPACE.equals(omElement.getNamespace().getNamespaceURI()) && B4P_IDENTIFIER.equals(omElement.getLocalName())) {
                messageID = omElement.getText();
                foundB4PMessageID = true;
                break;
            }
        }
    }
    if (!foundB4PMessageID) {
        String errorMsg = "no B4P messageID received";
        log.error(errorMsg);
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("Adding message ID: " + messageID + "-> " + participantProtocolService);
    }
    // Persisting data.
    try {
        persistData(messageID, participantProtocolService);
    } catch (Exception e) {
        log.error("Error occurred during persisting data", e);
        return null;
    }
    // Sending Dummy Response.
    RegisterResponseType responseType = new RegisterResponseType();
    EndpointReferenceType epr = new EndpointReferenceType();
    AttributedURI attributedURI = new AttributedURI();
    URI b4pProtocolHandlerURI;
    try {
        // Setting Dummy Address here.
        b4pProtocolHandlerURI = new URI(getB4PProtocolHandlerURI());
        attributedURI.setAnyURI(b4pProtocolHandlerURI);
    } catch (URI.MalformedURIException e) {
        log.error("Error occurred while generating b4p protocol handler uri", e);
        return null;
    }
    epr.setAddress(attributedURI);
    OMFactory omFactory = OMAbstractFactory.getOMFactory();
    OMNamespace b4pOMNamespace = omFactory.createOMNamespace(B4P_NAMESPACE, B4P_PREFIX);
    // Dummy Endpoint
    responseType.setCoordinatorProtocolService(epr);
    OMElement identifierElement = omFactory.createOMElement(B4P_IDENTIFIER, b4pOMNamespace);
    identifierElement.addChild(omFactory.createOMText(identifierElement, messageID));
    responseType.addExtraElement(identifierElement);
    return responseType;
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) AttributedURI(org.wso2.carbon.bpel.skeleton.b4p.coordination.addressing.AttributedURI) OMNamespace(org.apache.axiom.om.OMNamespace) RegisterResponseType(org.wso2.carbon.bpel.skeleton.b4p.coordination.RegisterResponseType) EndpointReferenceType(org.wso2.carbon.bpel.skeleton.b4p.coordination.addressing.EndpointReferenceType) OMElement(org.apache.axiom.om.OMElement) AttributedURI(org.wso2.carbon.bpel.skeleton.b4p.coordination.addressing.AttributedURI) URI(org.apache.axis2.databinding.types.URI)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)118 Test (org.testng.annotations.Test)68 API (org.wso2.carbon.apimgt.core.models.API)58 HashMap (java.util.HashMap)55 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)50 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)46 ArrayList (java.util.ArrayList)38 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)30 Test (org.junit.Test)28 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)27 HashSet (java.util.HashSet)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)24 Map (java.util.Map)23 Response (javax.ws.rs.core.Response)22 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)21 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)19 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)17