Hi Waruna,
Thanks for the reply.
No, I didn't use time delay. I have attached the class.
On Thu, Oct 8, 2015 at 4:53 PM, Waruna Perera <[email protected]> wrote:
> Hi,
>
> Do you use in time delay in between get all logs? Please provide the full
> code block. Some times in our test cases we use time out delays to get
> logs.
>
> Thanks,
>
> Waruna
>
> On Thu, Oct 8, 2015 at 3:08 PM, Abimaran Kugathasan <[email protected]>
> wrote:
>
>> Any updates on this?
>>
>> On Thu, Oct 8, 2015 at 12:51 PM, Abimaran Kugathasan <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> I want to get a log from a perticular class. I have
>>> used LogViewerClient. Please check my below code snaps.
>>>
>>> I need to get the below log.
>>>
>>> [2015-10-08 12:35:38,966] WARN - TimeoutHandler Expiring message ID :
>>>> urn:uuid:354104e6-eea7-41fd-88c7-de19d0b5a27f; dropping message after
>>>> timeout of : 10 seconds
>>>
>>>
>>>
>>> // Initialized the client
>>>
>>> LogViewerClient logViewerClient = new
>>> LogViewerClient(amServer.getBackEndUrl(), amServer.getSessionCookie());
>>>
>>> // Calling it with parameters
>>>
>>> LogEvent[] timeoutLogs = logViewerClient.getLogs("WARN", "TimeoutHandler",
>>> "", "AM");
>>>
>>> This returns empty array.
>>>
>>>
>>> I could get the system logs through below method.
>>>
>>> LogEvent[] logEvents = logViewerClient.getAllSystemLogs();
>>>
>>>
>>> How can I get above mention log?
>>>
>>>
>>> --
>>>
>>> Thanks
>>> Abimaran Kugathasan
>>>
>>> Software Engineer | WSO2 Inc
>>> Data & APIs Technologies Team
>>> Mobile : +94 773922820
>>>
>>> <http://stackoverflow.com/users/515034>
>>> <http://lk.linkedin.com/in/abimaran>
>>> <http://www.lkabimaran.blogspot.com/> <https://github.com/abimarank>
>>> <https://twitter.com/abimaran>
>>>
>>>
>>
>>
>> --
>> Thanks
>> Abimaran Kugathasan
>>
>> Software Engineer | WSO2 Inc
>> Data & APIs Technologies Team
>> Mobile : +94 773922820
>>
>> <http://stackoverflow.com/users/515034>
>> <http://lk.linkedin.com/in/abimaran>
>> <http://www.lkabimaran.blogspot.com/> <https://github.com/abimarank>
>> <https://twitter.com/abimaran>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Waruna Perera
> Senior Software Engineer - Test Automation
> Mobile: +94 77 3867037
> WSO2, Inc.; http://wso2.com/
> lean . enterprise . middlewear.
>
--
Thanks
Abimaran Kugathasan
Software Engineer | WSO2 Inc
Data & APIs Technologies Team
Mobile : +94 773922820
<http://stackoverflow.com/users/515034>
<http://lk.linkedin.com/in/abimaran> <http://www.lkabimaran.blogspot.com/>
<https://github.com/abimarank> <https://twitter.com/abimaran>
package org.wso2.carbon.am.tests;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.api.clients.logging.LogViewerClient;
import org.wso2.carbon.automation.api.clients.logging.LoggingAdminClient;
import org.wso2.carbon.automation.api.clients.webapp.mgt.WebAppAdminClient;
import org.wso2.carbon.automation.core.ProductConstant;
import org.wso2.carbon.automation.core.utils.UserInfo;
import org.wso2.carbon.automation.core.utils.UserListCsvReader;
import org.wso2.carbon.automation.core.utils.frameworkutils.FrameworkFactory;
import org.wso2.carbon.automation.core.utils.frameworkutils.FrameworkProperties;
import org.wso2.carbon.automation.utils.as.WebApplicationDeploymentUtil;
import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
public class ESBJAVA3530TimeoutHandlerLogMessageTestCase extends APIManagerIntegrationTestBase {
private LogViewerClient logViewerClient;
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init();
logViewerClient = new LogViewerClient(amServer.getBackEndUrl(), amServer.getSessionCookie());
}
public void deployArrService(String backEndUrl, String sessionCookie, String serviceFilePath) throws Exception {
WebAppAdminClient webAppAdminClient = new WebAppAdminClient(backEndUrl, sessionCookie);
webAppAdminClient.warFileUplaoder(serviceFilePath);
WebApplicationDeploymentUtil.isWebApplicationDeployed(backEndUrl, sessionCookie, "CxfRestService-1.0.0-SNAPSHOT");
}
@Test(groups = {"wso2.am"}, description = "test endpoint deployment from car file")
public void testBackendTimeoutLog() throws Exception {
String filePath = ProductConstant.getResourceLocations(ProductConstant.AM_SERVER_NAME) + File.separator + "war"
+ File.separator + "backendTimeout" + File.separator + "CxfRestService-1.0.0-SNAPSHOT.war";
deployArrService(amServer.getBackEndUrl(), amServer.getSessionCookie(), filePath);
OMElement apiXml = buildOMElement(new FileInputStream(ProductConstant.getResourceLocations(
ProductConstant.AM_SERVER_NAME) + File.separator + "synapseconfigs" + File.separator +"backendTimeout"
+ File.separator + "admin--weatherApi_v1.0.0.xml"));
addApi(apiXml);
invokeApi();
LogEvent[] timeoutLogs = logViewerClient.getLogs("WARN", "TimeoutHandler", "", "AM");
log.info("Log Content : " + Arrays.toString(timeoutLogs));
}
public OMElement buildOMElement(InputStream inputStream) throws Exception {
XMLStreamReader parser;
try {
parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
}
catch (XMLStreamException e) {
String msg = "Error in initializing the parser to build the OMElement.";
log.error(msg, e);
throw new Exception(msg, e);
}
finally {
log.info("Reading data from configuration file");
}
StAXOMBuilder builder = new StAXOMBuilder(parser);
return builder.getDocumentElement();
}
private void invokeApi() {
HttpURLConnection conn = null;
BufferedReader br = null;
try {
URL url = new URL("http://localhost:8280/weatherApi/1.0.0/50");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
} catch (IOException e) {
log.error(e);
}
log.info("Invoking the API at : " + new SimpleDateFormat("HH:mm:ss:SSS").format(new Date(System.currentTimeMillis())));
try {
if (conn != null && conn.getResponseCode() == 200) {
log.info("Response Received at : " + new SimpleDateFormat("HH:mm:ss:SSS").format(new Date(System.currentTimeMillis())));
br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
}
} catch (IOException e) {
log.error(e);
}
try {
String output;
log.info("Output from Server .... \n");
while (br != null && (output = br.readLine()) != null) {
log.info(output);
}
} catch (IOException e) {
log.error(e);
}
if (conn != null) {
conn.disconnect();
}
}
}
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev