Search in sources :

Example 46 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getHttpBindingOperations.

/**
 * Retrieves all the operations defined in the provided WSDL definition.
 *
 * @param definition WSDL Definition
 * @return a set of {@link WSDLOperation} defined in the provided WSDL definition
 */
private Set<WSDLOperation> getHttpBindingOperations(Definition definition) {
    Set<WSDLOperation> allOperations = new HashSet<>();
    for (Object bindingObj : definition.getAllBindings().values()) {
        if (bindingObj instanceof Binding) {
            Binding binding = (Binding) bindingObj;
            Set<WSDLOperation> operations = getHttpBindingOperations(binding);
            allOperations.addAll(operations);
        }
    }
    return allOperations;
}
Also used : HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) HashSet(java.util.HashSet)

Example 47 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getParameters.

/**
 * Returns parameters, given http binding operation, verb and content type
 *
 * @param bindingOperation {@link BindingOperation} object
 * @param verb             HTTP verb
 * @param contentType      Content type
 * @return parameters, given http binding operation, verb and content type
 */
private List<WSDLOperationParam> getParameters(BindingOperation bindingOperation, String verb, String contentType) {
    List<WSDLOperationParam> params = new ArrayList<>();
    Operation operation = bindingOperation.getOperation();
    // or content type is not provided
    if (APIMWSDLUtils.canContainBody(verb) && !APIMWSDLUtils.hasFormDataParams(contentType)) {
        WSDLOperationParam param = new WSDLOperationParam();
        param.setName("Payload");
        param.setParamType(WSDLOperationParam.ParamTypeEnum.BODY);
        params.add(param);
        if (log.isDebugEnabled()) {
            log.debug("Adding default Param for operation:" + operation.getName() + ", contentType: " + contentType);
        }
        return params;
    }
    if (operation != null) {
        Input input = operation.getInput();
        if (input != null) {
            Message message = input.getMessage();
            if (message != null) {
                Map map = message.getParts();
                map.forEach((name, partObj) -> {
                    WSDLOperationParam param = new WSDLOperationParam();
                    param.setName(name.toString());
                    if (log.isDebugEnabled()) {
                        log.debug("Identified param for operation: " + operation.getName() + " param: " + name);
                    }
                    if (APIMWSDLUtils.canContainBody(verb)) {
                        if (log.isDebugEnabled()) {
                            log.debug("Operation " + operation.getName() + " can contain a body.");
                        }
                        // In POST, PUT operations, parameters always in body according to HTTP Binding spec
                        if (APIMWSDLUtils.hasFormDataParams(contentType)) {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.FORM_DATA);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to formData.");
                            }
                        }
                    // no else block since if content type is not form-data related, there can be only one
                    // parameter which is payload body. This is handled in the first if block which is
                    // if (canContainBody(verb) && !hasFormDataParams(contentType)) { .. }
                    } else {
                        // In GET operations, parameters always query or path as per HTTP Binding spec
                        if (isUrlReplacement(bindingOperation)) {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.PATH);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to Path.");
                            }
                        } else {
                            param.setParamType(WSDLOperationParam.ParamTypeEnum.QUERY);
                            if (log.isDebugEnabled()) {
                                log.debug("Param " + name + " type was set to Query.");
                            }
                        }
                    }
                    Part part = (Part) partObj;
                    param.setDataType(part.getTypeName().getLocalPart());
                    if (log.isDebugEnabled()) {
                        log.debug("Param " + name + " data type was set to " + param.getDataType());
                    }
                    params.add(param);
                });
            }
        }
    }
    return params;
}
Also used : WSDLOperationParam(org.wso2.carbon.apimgt.core.models.WSDLOperationParam) Input(javax.wsdl.Input) BindingInput(javax.wsdl.BindingInput) Message(javax.wsdl.Message) Part(javax.wsdl.Part) ArrayList(java.util.ArrayList) Operation(javax.wsdl.Operation) HTTPOperation(javax.wsdl.extensions.http.HTTPOperation) BindingOperation(javax.wsdl.BindingOperation) WSDLOperation(org.wso2.carbon.apimgt.core.models.WSDLOperation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 48 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class APIFileUtils method extractUploadedArchive.

/**
 * Extracts the APIs to the file system by reading the incoming {@link InputStream} object
 * uploadedApiArchiveInputStream
 *
 * @param uploadedApiArchiveInputStream Incoming {@link InputStream}
 * @param importedDirectoryName         directory to extract the archive
 * @param apiArchiveLocation            full path of the archive location
 * @param extractLocation               full path to the location to which the archive will be written
 * @return location to which APIs were extracted
 * @throws APIMgtDAOException if an error occurs while extracting the archive
 */
public static String extractUploadedArchive(InputStream uploadedApiArchiveInputStream, String importedDirectoryName, String apiArchiveLocation, String extractLocation) throws APIMgtDAOException {
    String archiveExtractLocation;
    try {
        // create api import directory structure
        APIFileUtils.createDirectory(extractLocation);
        // create archive
        createArchiveFromInputStream(uploadedApiArchiveInputStream, apiArchiveLocation);
        // extract the archive
        archiveExtractLocation = extractLocation + File.separator + importedDirectoryName;
        extractArchive(apiArchiveLocation, archiveExtractLocation);
    } catch (APIMgtDAOException e) {
        APIFileUtils.deleteDirectory(extractLocation);
        String errorMsg = "Error in accessing uploaded API archive";
        log.error(errorMsg, e);
        throw new APIMgtDAOException(errorMsg, e);
    }
    return archiveExtractLocation;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 49 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ETagUtils method getHash.

/**
 * If some other hashing algorithm is needed use this method.
 *
 * @param updatedTime, the updated/created time of the resource in UNIX time
 * @param algorithm            the algorithm used for hashing
 * @return String
 * @throws NoSuchAlgorithmException if the given algorithm is invalid or not found in {@link MessageDigest}
 * @throws ETagGenerationException if hash generation failed.
 */
private static String getHash(String updatedTime, String algorithm) throws ETagGenerationException, NoSuchAlgorithmException {
    MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
    try {
        messageDigest.update(updatedTime.getBytes("UTF-8"));
        byte[] digest = messageDigest.digest();
        // conversion to hexadecimal
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }
        String generatedHash = sb.toString();
        if (log.isDebugEnabled()) {
            log.debug("ETag generated in HEX '" + generatedHash + "' for '" + updatedTime + "'");
        }
        return sb.toString();
    } catch (UnsupportedEncodingException e) {
        String errorMessage = "Error while converting timestamp to String :" + updatedTime;
        log.error(errorMessage, e);
        throw new ETagGenerationException(errorMessage, e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) MessageDigest(java.security.MessageDigest) ETagGenerationException(org.wso2.carbon.apimgt.core.exception.ETagGenerationException)

Example 50 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class MappingUtil method toAPIInfo.

/**
 * Converts {@link API} List to an {@link APIInfoDTO} List.
 *
 * @param apiSummaryList
 * @return
 */
private static List<APIInfoDTO> toAPIInfo(List<API> apiSummaryList) {
    List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
    for (API apiSummary : apiSummaryList) {
        APIInfoDTO apiInfo = new APIInfoDTO();
        apiInfo.setId(apiSummary.getId());
        apiInfo.setContext(apiSummary.getContext());
        apiInfo.setDescription(apiSummary.getDescription());
        apiInfo.setName(apiSummary.getName());
        apiInfo.setProvider(apiSummary.getProvider());
        apiInfo.setLifeCycleStatus(apiSummary.getLifeCycleStatus());
        apiInfo.setVersion(apiSummary.getVersion());
        apiInfo.setWorkflowStatus(apiSummary.getWorkflowStatus());
        apiInfo.setSecurityScheme(mapSecuritySchemeIntToList(apiSummary.getSecurityScheme()));
        apiInfoList.add(apiInfo);
    }
    return apiInfoList;
}
Also used : ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIInfoDTO)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10