HTTP Client
Generated Objects
@Property(name = "myHttpResource") public HTTPClientDriverFactory myHttpResource; private HttpClient myHttpResourceHttpClient;
myHttpResourceHttpClient is an instance of org.apache.commons.httpclient.HttpClient.
Business Logic Example
class ReadHttpActivityExecutor implements Runnable {
private final AsyncActivityCompletionNotifier notifier;
/**
* <!-- begin-custom-doc -->
*
* <!-- end-custom-doc -->
* @generated
*/
@Override
public void run() {
if(getActivityLogger().isDebugEnabled()) {
activityLogger.debug(RuntimeMessageBundle.DEBUG_PLUGIN_ACTIVITY_METHOD_CALLED
,new Object[] { "Executor run()"
,activityContext.getActivityName()
,activityContext.getProcessName()
,activityContext.getDeploymentUnitName()
,activityContext.getDeploymentUnitVersion() });
String serializedNode = XMLUtils.serializeNode(inputData, processContext.getXMLProcessingContext());
activityLogger.debug(RuntimeMessageBundle.DEBUG_PLUGIN_ACTIVITY_INPUT, new Object[] {activityContext.getActivityName(), serializedNode});
}
try {
// begin-custom-code
// add your own business code here
GetMethod getMethod = new GetMethod("http://jsonplaceholder.typicode.com/posts/1");
try {
// myHttpResourceHttpClient is created by PDK for the myHttpResource field
myHttpResourceHttpClient.executeMethod(getMethod);
} catch (IOException e) {
e.printStackTrace();
throw new ActivityFault(activityContext, new LocalizedMessage(
RuntimeMessageBundle.ERROR_OCCURED_RETRIEVE_RESULT, new Object[] {activityContext.getActivityName(), e.toString()}));
}
String responseBodyAsString = getMethod.getResponseBodyAsString();
System.out.println("Response body: \n" + responseBodyAsString);
// end-custom-code
N output = null;
SerializableXMLDocument<N> wrapper = new SerializableXMLDocument<N>(processContext.getXMLProcessingContext(), output);
notifier.setReady(wrapper);
} catch (Exception e) {
e.printStackTrace();
notifier.setReady(e);
}
}
}
Copyright © Cloud Software Group, Inc. All rights reserved.
