Example Application
This example shows a complete application from creating the instance, to logging in, to performing the transaction on the Lawson system, and to logging out, including error handling.
Additional details about methods and parameters used here are in the sections that follow.
package com.lawson.security.authen.httpclient;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class LawsonHCExample
{
public static void main(String[] args)
{
try
{
LawsonHttpClient lhc = new LawsonHTTPClient();
// Assume url, username, and pwd strings are passed as args
// such as url = http://yourserver:port/someServlet
// username = johnd
// password = 5T@u88s9
String url = args[0];
String username = args[1];
String pwd = args[2];
lhc.login(url, username, pwd);
// sample get call
ResponseObject response = null;
String getData = "http://yourserver/servlet/Router/Data/Erp?PROD=APPS901&FILE=EMPLOYEE&SELECT=LastName%3DSmith&out=xml";
response = lhc.executeGetMethod(getData);
// Do something with response if you want
// sample post call with InputStream
String postData = "<?xml version=\"1.0\"?><XCU01.1><CU01.1><_OUT>XML</_OUT><_CACHE>TRUE</_CACHE><_PDL>APPS901</_PDL><_TKN>CU01.1</_TKN>
<_DATEFMT>ALL</_DATEFMT><_f0>CU01.1</_f0><_f5>2</_f5><_f8>Multiple Entry</_f8><_f1>N</_f1><_f2></_f2><_f3></_f3><_f4></_f4>
<_f6></_f6><_f7></_f7></CU01.1></XCU01.1>";
InputStream post = new ByteArrayInputStream(postData.getBytes());
ResponseObject response2 = null;
String contentType = "text/xml";
response2 = lhc.executePostMethod(url,postData,contentType);
// Do something with response2 if you want
// Call logout()
boolean logoutSuccessful;
try
{
logoutSuccessful = lhc.logout();
if (logoutSuccessful)
{
System.out.println("SSO logout successful.");
}
else
{
System.out.println("SSO logout failed.");
}
}
catch (LawsonHttpClientException e)
{
e.printStackTrace();
return;
}
}
catch (LawsonHttpClientException e)
{
e.printStackTrace();
return;
}
}
}