Skip to content

Instantly share code, notes, and snippets.

@aruld
Created April 17, 2012 19:46
Show Gist options
  • Select an option

  • Save aruld/2408560 to your computer and use it in GitHub Desktop.

Select an option

Save aruld/2408560 to your computer and use it in GitHub Desktop.
Invoking Flux Web Service Trigger using Jersey Java API
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
public class InvokeWebServiceTrigger {
private static final String HTTP_ENDPOINT = "http://localhost:7186/cluster";
private static final String PUT_WITH_VARIABLES_URI = "flowCharts/startTemplateWithVariables";
private static final String username = "admin";
private static final String password = "admin";
public static void main(String[] args) {
Client client = Client.create();
client.addFilter(new LoggingFilter());
client.addFilter(new HTTPBasicAuthFilter(username, password));
WebResource resource = client.resource(HTTP_ENDPOINT);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("template", "/Media Processing Template");//Required parameter: "template" points to the workflow template in the repository
variables.put("category", "sample clips");//Optional parameter: Adds a variable "category" to the workflow instance
variables.put("rate", 1000);//Optional parameter: Adds a variable "rate" to the workflow instance
variables.put("namespace", "/Media Processing Template Instance");//Optional parameter: Specifies the name of the workflow instance
ClientResponse response = resource.path(PUT_WITH_VARIABLES_URI).type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, addVariables(variables));
String name = response.getEntity(String.class);
System.out.println("Scheduled job via HTTP request = " + name);
}
private static FormDataMultiPart addVariables(Map<String, Object> variables) {
FormDataMultiPart multipart = new FormDataMultiPart();
for (Map.Entry<String, Object> entry : variables.entrySet()) {
FormDataBodyPart templateName = new FormDataBodyPart(entry.getKey(), entry.getValue(), MediaType.TEXT_PLAIN_TYPE);
multipart.bodyPart(templateName);
}
return multipart;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment