org.activiti.engine.impl.util.ReflectUtil Java Examples

The following examples show how to use org.activiti.engine.impl.util.ReflectUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebServiceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void createItemDefinitions(BpmnModel bpmnModel) {
  
  for (org.activiti.bpmn.model.ItemDefinition itemDefinitionElement : bpmnModel.getItemDefinitions().values()) {
  
    if (itemDefinitionMap.containsKey(itemDefinitionElement.getId()) == false) {
      StructureDefinition structure = null;
  
      try {
        // it is a class
        Class<?> classStructure = ReflectUtil.loadClass(itemDefinitionElement.getStructureRef());
        structure = new ClassStructureDefinition(classStructure);
      } catch (ActivitiException e) {
        // it is a reference to a different structure
        structure = structureDefinitionMap.get(itemDefinitionElement.getStructureRef());
      }
  
      ItemDefinition itemDefinition = new ItemDefinition(itemDefinitionElement.getId(), structure);
      if (StringUtils.isNotEmpty(itemDefinitionElement.getItemKind())) {
        itemDefinition.setItemKind(ItemKind.valueOf(itemDefinitionElement.getItemKind()));
      }
      
      itemDefinitionMap.put(itemDefinition.getId(), itemDefinition);
    }
  }
}
 
Example #2
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testImportInheritedElement() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti5/engine/impl/webservice/inherited-elements-in-types.wsdl");
  assertNotNull(url);
  importer.importFrom(url.toString());

  List<StructureDefinition> structures = sortStructures();
  assertEquals(1, structures.size());
      final Object structureTypeInst = ReflectUtil.instantiate("org.activiti.webservice.counter.StructureType");
  final Class structureType = structureTypeInst.getClass();
  this.assertStructure(structures.get(0), "inheritedRequest", new String[] { "rootElt", "inheritedElt", "newSimpleElt", 
      "newStructuredElt" }, new Class<?>[] { Short.class, Integer.class, String.class, structureType });
  assertEquals(2, structureType.getDeclaredFields().length);
  assertNotNull(structureType.getDeclaredField("booleanElt"));
  assertNotNull(structureType.getDeclaredField("dateElt"));
  assertEquals(1, structureType.getSuperclass().getDeclaredFields().length);
  assertNotNull(structureType.getSuperclass().getDeclaredField("rootElt"));
}
 
Example #3
Source File: CxfWSDLImporter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected static void _importFields(final JDefinedClass theClass, final AtomicInteger index, final SimpleStructureDefinition structure) {
    
  final JClass parentClass = theClass._extends();
  if (parentClass != null && parentClass instanceof JDefinedClass) {
    _importFields((JDefinedClass)parentClass, index, structure);
  }
  for (Entry<String, JFieldVar> entry : theClass.fields().entrySet()) {
    Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().erasure().fullName());

    String fieldName = entry.getKey();
    if (fieldName.startsWith("_")) {
      if (!JJavaName.isJavaIdentifier(fieldName.substring(1))) {
        fieldName = fieldName.substring(1); //it was prefixed with '_' so we should use the original name.
      }
    }

    structure.setFieldName(index.getAndIncrement(), fieldName, fieldClass);
  }
}
 
Example #4
Source File: DynamicBeanPropertyELResolver.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
  if (base == null || this.getCommonPropertyType(context, base) == null) {
    return null;
  }

  String propertyName = property.toString();

  try {
    Object value = ReflectUtil.invoke(base, this.readMethodName, new Object[] { propertyName });
    context.setPropertyResolved(true);
    return value;
  } catch (Exception e) {
    throw new ELException(e);
  }
}
 
Example #5
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testImportInheritedElement() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti/engine/impl/webservice/inherited-elements-in-types.wsdl");
  assertNotNull(url);
  importer.importFrom(url.toString());

  List<StructureDefinition> structures = sortStructures();
  assertEquals(1, structures.size());
      final Object structureTypeInst = ReflectUtil.instantiate("org.activiti.webservice.counter.StructureType");
  final Class<? extends Object> structureType = structureTypeInst.getClass();
  this.assertStructure(structures.get(0), "inheritedRequest", new String[] { "rootElt", "inheritedElt", "newSimpleElt", 
      "newStructuredElt" }, new Class<?>[] { Short.class, Integer.class, String.class, structureType });
  assertEquals(2, structureType.getDeclaredFields().length);
  assertNotNull(structureType.getDeclaredField("booleanElt"));
  assertNotNull(structureType.getDeclaredField("dateElt"));
  assertEquals(1, structureType.getSuperclass().getDeclaredFields().length);
  assertNotNull(structureType.getSuperclass().getDeclaredField("rootElt"));
}
 
Example #6
Source File: JuelScriptEngine.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
    Class<?> clazz = null;
    if (obj instanceof Class) {
        clazz = (Class<?>) obj;
    } else if (obj instanceof String) {
        try {
            clazz = ReflectUtil.loadClass((String) obj);
        } catch (ActivitiException ae) {
            throw new ELException(ae);
        }
    } else {
        throw new ELException("Class or class name is missing");
    }
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        int mod = m.getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
            String name = namespace + ":" + m.getName();
            ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
        }
    }
}
 
Example #7
Source File: DbSqlSession.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void executeSchemaResource(String operation, String component, String resourceName, boolean isOptional) {
  InputStream inputStream = null;
  try {
    inputStream = ReflectUtil.getResourceAsStream(resourceName);
    if (inputStream == null) {
      if (isOptional) {
        log.info("no schema resource {} for {}", resourceName, operation);
      } else {
        throw new ActivitiException("resource '" + resourceName + "' is not available");
      }
    } else {
      executeSchemaResource(operation, component, resourceName, inputStream);
    }

  } finally {
    IoUtil.closeSilently(inputStream);
  }
}
 
Example #8
Source File: JuelScriptEngine.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
  Class<?> clazz = null;
  if (obj instanceof Class) {
    clazz = (Class<?>) obj;
  } else if (obj instanceof String) {
    try {
      clazz = ReflectUtil.loadClass((String) obj);
    } catch (ActivitiException ae) {
      throw new ELException(ae);
    }
  } else {
    throw new ELException("Class or class name is missing");
  }
  Method[] methods = clazz.getMethods();
  for (Method m : methods) {
    int mod = m.getModifiers();
    if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
      String name = namespace + ":" + m.getName();
      ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
    }
  }
}
 
Example #9
Source File: JPAEntityMappings.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public Object getJPAEntity(String className, String idString) {
    Class<?> entityClass = null;
    entityClass = ReflectUtil.loadClass(className);

    EntityMetaData metaData = getEntityMetaData(entityClass);
    if (metaData == null) {
        throw new ActivitiIllegalArgumentException("Class is not a JPA-entity: " + className);
    }

    // Create primary key of right type
    Object primaryKey = createId(metaData, idString);
    return findEntity(entityClass, primaryKey);
}
 
Example #10
Source File: ProcessEngines.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static void initProcessEngineFromSpringResource(URL resource) {
  try {
    Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.activiti.spring.SpringConfigurationHelper");
    Method method = springConfigurationHelperClass.getDeclaredMethod("buildProcessEngine", new Class<?>[] { URL.class });
    ProcessEngine processEngine = (ProcessEngine) method.invoke(null, new Object[] { resource });

    String processEngineName = processEngine.getName();
    ProcessEngineInfo processEngineInfo = new ProcessEngineInfoImpl(processEngineName, resource.toString(), null);
    processEngineInfosByName.put(processEngineName, processEngineInfo);
    processEngineInfosByResourceUrl.put(resource.toString(), processEngineInfo);

  } catch (Exception e) {
    throw new ActivitiException("couldn't initialize process engine from spring configuration resource " + resource.toString() + ": " + e.getMessage(), e);
  }
}
 
Example #11
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testGetBpmnXmlFileThroughService() {
  String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
  List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId);

  // verify bpmn file name
  assertEquals(1, deploymentResources.size());
  String bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml";
  assertEquals(bpmnResourceName, deploymentResources.get(0));

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  assertEquals(bpmnResourceName, processDefinition.getResourceName());
  assertNull(processDefinition.getDiagramResourceName());
  assertFalse(processDefinition.hasStartFormKey());

  ProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
  assertNull(readOnlyProcessDefinition.getDiagramResourceName());

  // verify content
  InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName);
  String contentFromDeployment = readInputStreamToString(deploymentInputStream);
  assertTrue(contentFromDeployment.length() > 0);
  assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\""));

  InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml");
  String contentFromFile = readInputStreamToString(fileInputStream);
  assertEquals(contentFromFile, contentFromDeployment);
}
 
Example #12
Source File: DeploymentResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test deploying an invalid file. POST repository/deployments
 */
public void testPostNewDeploymentInvalidFile() throws Exception {
  // Upload a valid BPMN-file using multipart-data
  HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
  httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("oneTaskProcess.invalidfile", "application/xml",
      ReflectUtil.getResourceAsStream("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"), null));
  closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
}
 
Example #13
Source File: TestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * get a resource location by convention based on a class (type) and a
 * relative resource name. The return value will be the full classpath
 * location of the type, plus a suffix built from the name parameter:
 * <code>BpmnDeployer.BPMN_RESOURCE_SUFFIXES</code>. 
 * The first resource matching a suffix will be returned.
 */
public static String getBpmnProcessDefinitionResource(Class< ? > type, String name) {
  for (String suffix : ResourceNameUtil.BPMN_RESOURCE_SUFFIXES) {
    String resource = type.getName().replace('.', '/') + "." + name + "." + suffix;
    InputStream inputStream = ReflectUtil.getResourceAsStream(resource);
    if (inputStream == null) {
      continue;
    } else {
      return resource;
    }
  }
  return type.getName().replace('.', '/') + "." + name + "." + ResourceNameUtil.BPMN_RESOURCE_SUFFIXES[0];
}
 
Example #14
Source File: BpmnDeploymentTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testGetBpmnXmlFileThroughService() {
    String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
    List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId);

    // verify bpmn file name
    assertEquals(1, deploymentResources.size());
    String bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml";
    assertEquals(bpmnResourceName, deploymentResources.get(0));

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertEquals(bpmnResourceName, processDefinition.getResourceName());
    assertNull(processDefinition.getDiagramResourceName());
    assertFalse(processDefinition.hasStartFormKey());

    org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler()
            .getRawProcessConfiguration();
    ReadOnlyProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl) activiti5ProcessEngineConfig.getRepositoryService()).getDeployedProcessDefinition(processDefinition.getId());
    assertNull(readOnlyProcessDefinition.getDiagramResourceName());

    // verify content
    InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName);
    String contentFromDeployment = readInputStreamToString(deploymentInputStream);
    assertTrue(contentFromDeployment.length() > 0);
    assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\""));

    InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml");
    String contentFromFile = readInputStreamToString(fileInputStream);
    assertEquals(contentFromFile, contentFromDeployment);
}
 
Example #15
Source File: SerializableType.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException {
    return new ObjectInputStream(is) {
        @Override
        protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
            return ReflectUtil.loadClass(desc.getName());
        }
    };
}
 
Example #16
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportCounterWithImport() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti5/engine/impl/webservice/counterWithImport.wsdl");
  importer.importFrom(url.toString());

  List<WSService> services = new ArrayList<WSService>(importer.getServices().values());
  assertEquals(1, services.size());
  WSService service = services.get(0);

  assertEquals("Counter", service.getName());
  assertEquals("http://localhost:63081/counter", service.getLocation());

  List<StructureDefinition> structures = sortStructures();
  List<WSOperation> operations = sortOperations();

  assertEquals(5, operations.size());
  this.assertOperation(operations.get(0), "getCount", service);
  this.assertOperation(operations.get(1), "inc", service);
  this.assertOperation(operations.get(2), "prettyPrintCount", service);
  this.assertOperation(operations.get(3), "reset", service);
  this.assertOperation(operations.get(4), "setTo", service);

  assertEquals(10, structures.size());
  this.assertStructure(structures.get(0), "getCount", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(1), "getCountResponse", new String[] { "count" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(2), "inc", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(3), "incResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(4), "prettyPrintCount", new String[] { "prefix", "suffix" }, new Class<?>[] { String.class, String.class });
  this.assertStructure(structures.get(5), "prettyPrintCountResponse", new String[] { "prettyPrint" }, new Class<?>[] { String.class });
  this.assertStructure(structures.get(6), "reset", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(7), "resetResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(8), "setTo", new String[] { "value" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(9), "setToResponse", new String[] {}, new Class<?>[] {});
}
 
Example #17
Source File: DeploymentBuilderImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public DeploymentBuilder addClasspathResource(String resource) {
    InputStream inputStream = ReflectUtil.getResourceAsStream(resource);
    if (inputStream == null) {
        throw new ActivitiIllegalArgumentException("resource '" + resource + "' not found");
    }
    return addInputStream(resource, inputStream);
}
 
Example #18
Source File: WSService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
SyncWebServiceClient getClient() {
    if (this.client == null) {
        // TODO refactor to use configuration
        SyncWebServiceClientFactory factory = (SyncWebServiceClientFactory) ReflectUtil.instantiate(ProcessEngineConfigurationImpl.DEFAULT_WS_SYNC_FACTORY);
        this.client = factory.create(this.wsdlLocation);
    }
    return this.client;
}
 
Example #19
Source File: ResourceStreamSource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream getInputStream() {
    InputStream inputStream = null;
    if (classLoader == null) {
        inputStream = ReflectUtil.getResourceAsStream(resource);
    } else {
        inputStream = classLoader.getResourceAsStream(resource);
    }
    if (inputStream == null) {
        throw new ActivitiIllegalArgumentException("resource '" + resource + "' doesn't exist");
    }
    return new BufferedInputStream(inputStream);
}
 
Example #20
Source File: DelegateActivitiEventListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected FlowableEventListener getDelegateInstance() {
    if (delegateInstance == null) {
        Object instance = ReflectUtil.instantiate(className);
        if (instance instanceof FlowableEventListener) {
            delegateInstance = (FlowableEventListener) instance;
        } else {
            // Force failing of the listener invocation, since the delegate cannot be created
            failOnException = true;
            throw new ActivitiIllegalArgumentException("Class " + className
                    + " does not implement " + FlowableEventListener.class.getName());
        }
    }
    return delegateInstance;
}
 
Example #21
Source File: ProcessEngines.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void initProcessEngineFromSpringResource(URL resource) {
    try {
        Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.activiti.spring.SpringConfigurationHelper");
        Method method = springConfigurationHelperClass.getDeclaredMethod("buildProcessEngine", new Class<?>[]{URL.class});
        ProcessEngine processEngine = (ProcessEngine) method.invoke(null, new Object[]{resource});

        String processEngineName = processEngine.getName();
        ProcessEngineInfo processEngineInfo = new ProcessEngineInfoImpl(processEngineName, resource.toString(), null);
        processEngineInfosByName.put(processEngineName, processEngineInfo);
        processEngineInfosByResourceUrl.put(resource.toString(), processEngineInfo);

    } catch (Exception e) {
        throw new ActivitiException("couldn't initialize process engine from spring configuration resource " + resource + ": " + e.getMessage(), e);
    }
}
 
Example #22
Source File: JPAEntityMappings.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object getJPAEntity(String className, String idString) {
  Class<?> entityClass = null;
  entityClass = ReflectUtil.loadClass(className);

  EntityMetaData metaData = getEntityMetaData(entityClass);

  // Create primary key of right type
  Object primaryKey = createId(metaData, idString);
  return findEntity(entityClass, primaryKey);
}
 
Example #23
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportCounter() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti5/engine/impl/webservice/counter.wsdl");
  importer.importFrom(url.toString());

  List<WSService> services = new ArrayList<WSService>(importer.getServices().values());
  assertEquals(1, services.size());
  WSService service = services.get(0);

  assertEquals("Counter", service.getName());
  assertEquals("http://localhost:63081/counter", service.getLocation());

  List<StructureDefinition> structures = sortStructures();
  List<WSOperation> operations = sortOperations();

  assertEquals(5, operations.size());
  this.assertOperation(operations.get(0), "getCount", service);
  this.assertOperation(operations.get(1), "inc", service);
  this.assertOperation(operations.get(2), "prettyPrintCount", service);
  this.assertOperation(operations.get(3), "reset", service);
  this.assertOperation(operations.get(4), "setTo", service);

  assertEquals(10, structures.size());
  this.assertStructure(structures.get(0), "getCount", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(1), "getCountResponse", new String[] { "count" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(2), "inc", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(3), "incResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(4), "prettyPrintCount", new String[] { "prefix", "suffix" }, new Class<?>[] { String.class, String.class });
  this.assertStructure(structures.get(5), "prettyPrintCountResponse", new String[] { "prettyPrint" }, new Class<?>[] { String.class });
  this.assertStructure(structures.get(6), "reset", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(7), "resetResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(8), "setTo", new String[] { "value" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(9), "setToResponse", new String[] {}, new Class<?>[] {});
}
 
Example #24
Source File: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void importStructure(Mapping mapping) {
  QName qname = mapping.getElement();
  JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass();
  SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart());

  Map<String, JFieldVar> fields = theClass.fields();
  int index = 0;
  for (Entry<String, JFieldVar> entry : fields.entrySet()) {
    Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().fullName());
    structure.setFieldName(index, entry.getKey(), fieldClass);
    index++;
  }
}
 
Example #25
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportCounter() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti/engine/impl/webservice/counter.wsdl");
  importer.importFrom(url.toString());
  
  List<WSService> services = new ArrayList<WSService>(importer.getServices().values());
  assertEquals(1, services.size());
  WSService service = services.get(0);
  
  assertEquals("Counter", service.getName());
  assertEquals("http://localhost:63081/webservicemock", service.getLocation());
  
  List<StructureDefinition> structures = sortStructures();
  List<WSOperation> operations = sortOperations();

  assertEquals(7, operations.size());
  this.assertOperation(operations.get(0), "getCount", service);
  this.assertOperation(operations.get(1), "inc", service);
  this.assertOperation(operations.get(2), "noNameResult", service);
  this.assertOperation(operations.get(3), "prettyPrintCount", service);
  this.assertOperation(operations.get(4), "reservedWordAsName", service);
  this.assertOperation(operations.get(5), "reset", service);
  this.assertOperation(operations.get(6), "setTo", service);
  
  assertEquals(14, structures.size());
  this.assertStructure(structures.get(0), "getCount", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(1), "getCountResponse", new String[] { "count" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(2), "inc", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(3), "incResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(4), "noNameResult", new String[] {"prefix", "suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(5), "noNameResultResponse", new String[] {"return"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(6), "prettyPrintCount", new String[] {"prefix", "suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(7), "prettyPrintCountResponse", new String[] {"prettyPrint"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(8), "reservedWordAsName", new String[] {"prefix","suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(9), "reservedWordAsNameResponse", new String[] {"static"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(10), "reset", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(11), "resetResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(12), "setTo", new String[] {"value"}, new Class<?>[] {Integer.class});
  this.assertStructure(structures.get(13), "setToResponse", new String[] {}, new Class<?>[] {});
}
 
Example #26
Source File: WSDLImporterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportCounterWithImport() throws Exception {
  URL url = ReflectUtil.getResource("org/activiti/engine/impl/webservice/counterWithImport.wsdl");
  importer.importFrom(url.toString());
  
  List<WSService> services = new ArrayList<WSService>(importer.getServices().values());
  assertEquals(1, services.size());
  WSService service = services.get(0);
  
  assertEquals("Counter", service.getName());
  assertEquals("http://localhost:63081/webservicemock", service.getLocation());
  
  List<StructureDefinition> structures = sortStructures();
  List<WSOperation> operations = sortOperations();

  assertEquals(7, operations.size());
  this.assertOperation(operations.get(0), "getCount", service);
  this.assertOperation(operations.get(1), "inc", service);
  this.assertOperation(operations.get(2), "noNameResult", service);
  this.assertOperation(operations.get(3), "prettyPrintCount", service);
  this.assertOperation(operations.get(4), "reservedWordAsName", service);
  this.assertOperation(operations.get(5), "reset", service);
  this.assertOperation(operations.get(6), "setTo", service);
  
  assertEquals(14, structures.size());
  this.assertStructure(structures.get(0), "getCount", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(1), "getCountResponse", new String[] { "count" }, new Class<?>[] { Integer.class });
  this.assertStructure(structures.get(2), "inc", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(3), "incResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(4), "noNameResult", new String[] {"prefix", "suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(5), "noNameResultResponse", new String[] {"return"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(6), "prettyPrintCount", new String[] {"prefix", "suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(7), "prettyPrintCountResponse", new String[] {"prettyPrint"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(8), "reservedWordAsName", new String[] {"prefix", "suffix"}, new Class<?>[] {String.class, String.class});
  this.assertStructure(structures.get(9), "reservedWordAsNameResponse", new String[] {"static"}, new Class<?>[] {String.class});
  this.assertStructure(structures.get(10), "reset", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(11), "resetResponse", new String[] {}, new Class<?>[] {});
  this.assertStructure(structures.get(12), "setTo", new String[] {"value"}, new Class<?>[] {Integer.class});
  this.assertStructure(structures.get(13), "setToResponse", new String[] {}, new Class<?>[] {});
}
 
Example #27
Source File: SerializableType.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException {
  return new ObjectInputStream(is) {
    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
      return ReflectUtil.loadClass(desc.getName());
    }
  };
}
 
Example #28
Source File: ErrorPropagation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static String findMatchingExceptionMapping(Exception e, List<MapExceptionEntry> exceptionMap) {
  String defaultExceptionMapping = null;

  for (MapExceptionEntry me : exceptionMap) {
    String exceptionClass = me.getClassName();
    String errorCode = me.getErrorCode();

    // save the first mapping with no exception class as default map
    if (StringUtils.isNotEmpty(errorCode) && StringUtils.isEmpty(exceptionClass) && defaultExceptionMapping == null) {
      defaultExceptionMapping = errorCode;
      continue;
    }

    // ignore if error code or class are not defined
    if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(exceptionClass)) {
      continue;
    }

    if (e.getClass().getName().equals(exceptionClass)) {
      return errorCode;
    }
    if (me.isAndChildren()) {
      Class<?> exceptionClassClass = ReflectUtil.loadClass(exceptionClass);
      if (exceptionClassClass.isAssignableFrom(e.getClass())) {
        return errorCode;
      }
    }
  }

  return defaultExceptionMapping;
}
 
Example #29
Source File: DeploymentBuilderImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public DeploymentBuilder addClasspathResource(String resource) {
  InputStream inputStream = ReflectUtil.getResourceAsStream(resource);
  if (inputStream == null) {
    throw new ActivitiIllegalArgumentException("resource '" + resource + "' not found");
  }
  return addInputStream(resource, inputStream);
}
 
Example #30
Source File: WSService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
SyncWebServiceClient getClient() {
  if (this.client == null) {
    // TODO refactor to use configuration
    SyncWebServiceClientFactory factory = (SyncWebServiceClientFactory) ReflectUtil.instantiate(ProcessEngineConfigurationImpl.DEFAULT_WS_SYNC_FACTORY);
    this.client = factory.create(this.wsdlLocation);
  }
  return this.client;
}