cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke activiti-rest with CXF WebClient

yangenxiong
Champ in-the-making
Champ in-the-making
Hi,
     when I use CXF WebClient to invoke the http://localhost:8080/activiti-rest/service/process-definition/test:1:401 REST WebService, The CXF WebClient change The URI: http://localhost:8080/activiti-rest/service/process-definition/test%3A1%3A401, the activiti-rest module could not find the processDefinition, because id is "test%3A1%3A401", but not test:1:401
    I print the WebClient URI, here is the code:

         WebClient client = WebClient.create(
               "http://localhost:8080/activiti-rest/service/process-definition/myTest:1:401" ,
               userName, passwd, null);
         System.out.println(client.getBaseURI());
         System.out.println(client.getCurrentURI());

    Call WebClient getBaseURI method, result is http://localhost:8080/activiti-rest/service/process-definition/test:1:401.
    Call getCurrentURI method, result is http://localhost:8080/activiti-rest/service/process-definition/test%3A1%3A401.
    The WebClient work with CurrentURI in fact, how to resolve this?  thanks a lot.
6 REPLIES 6

frederikherema1
Star Contributor
Star Contributor
That's strange, all URL-parameters from the rest are decoded before being used:

/**
   * Get a request attribute value, decoded.
   */
  protected String getAttribute(String name) {
    return decode((String) getRequest().getAttributes().get(name));
  }

protected String decode(String string) {
    if(string != null) {
      try {
        return URLDecoder.decode(string, "UTF-8");
      } catch (UnsupportedEncodingException uee) {
        throw new IllegalStateException("JVM does not support UTF-8 encoding.", uee);
      }
    }
    return null;
  }

I tried running our test-suite with a forced encoded URL and it still works:


/**
  * Test getting a single process definition.
  * GET repository/process-definitions/{processDefinitionResource}
  */
  @Deployment(resources={"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testGetProcessDefinition() throws Exception {

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
   
    ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, encode(processDefinition.getId())));
    Representation response = client.get();
   
    // Check "OK" status
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

What is the actual error-desciption in the JSON-response?

frederikherema1
Star Contributor
Star Contributor
By the way, I see your URL is "process-definition/id" and not "process-definitions/id"…

yangenxiong
Champ in-the-making
Champ in-the-making
Thanks frederikheremans, I request this URL: /process-definition/{processDefinitionId}/form, and it will "Returns a process definition's form"

I deploy the activiti-rest.war to tomcat server, and I got this exception message:
<java>
org.activiti.engine.ActivitiException: no deployed process definition found with id 'formTest%3A1%3A403'
at org.activiti.engine.impl.persistence.deploy.DeploymentCache.findDeployedProcessDefinitionById(DeploymentCache.java:51)
at org.activiti.engine.impl.cmd.GetStartFormCmd.execute(GetStartFormCmd.java:40)
at org.activiti.engine.impl.cmd.GetStartFormCmd.execute(GetStartFormCmd.java:30)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
</java>

I see the activiti-rest module source code, there is some code in org.activiti.rest.api.process.ProcessDefinitionFormResource.java:
<java>
    if(authenticate() == false) return null;   
    String processDefinitionId = (String) getRequest().getAttributes().get("processDefinitionId");     
    Object form = ActivitiUtil.getFormService().getRenderedStartForm(processDefinitionId);
</java>

The problem is WebClient use URLEncoder.encode, but activiti-rest module no use URLDecoder.decode.
Thanks.

yangenxiong
Champ in-the-making
Champ in-the-making
BTW, I use activiti version is 5.10, and CXF version is 2.2.6. 

frederikherema1
Star Contributor
Star Contributor
Okay, that clears up a lot… I was referring to the new API-impelementation, which has the "decoding" built in. Seems like the old API doesn't have this feature built in. You can:

1) Upgrade to 5.13
2) patch that specific resource with "decode" functionality before using the attribute-value
3) Try convincing Restlet to de decoding of the URL. I saw some articles on slashdot/google that go into this, so I'm guessing maybe there is a generic "fix" you can do by configuring rest let

yangenxiong
Champ in-the-making
Champ in-the-making
Thank you very much, frederikheremans!  Smiley Happy
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.