Reputation: 351
I am new to web services and have published a web service on my localhost (Websphere Application Server 8).
I am able to consume the web service successfully but not able to find where the logs are getting generated or even the logs are getting generated or not.
I had place log4j.properties file in WebContent/WEB-INF/classes, but this file is file is automatically getting deleted when I am trying to generate WSDL from Java (Steps - Right click on project name --> New --> Web Service --> Select Class).
Files that were generated:
and some JARs getting added in WebContent/WEB-INF/lib.
After the file was deleted I have copied log4j.properties again to WebContent/WEB-INF/classes and exported the EAR which was deployed on server.
I have already checked logs in folders:
but no log file was generated.
Main web service -->
package com.gateway.request.demo;
import java.util.Date;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
@WebService
public class GetDemoTicketv2 {
//Logger log = Logger.getLogger(GetDemoTicket.class);
Logger log = LogManager.getLogger(GetDemoTicketv2.class);
public GetDemoTicketv2() {
super();
// TODO Auto-generated constructor stub
}
@WebMethod
public String getTicket(String serviceName, String actionName, String bodyStr, String userId){
Date curDate = new Date();
log.debug("Starting Execution");
log.info("Service Name is: "+serviceName);
log.info("Action is: "+actionName);
log.info("Body: "+bodyStr);
log.info("User ID is: "+userId);
log.debug("Execution Done");
serviceName = "Service name received: "+serviceName+" "+curDate.toString()+"\n";
actionName = "Action name received: "+actionName+" "+curDate.toString()+"\n";
bodyStr = "Body string received: "+bodyStr+" "+curDate.toString()+"\n";
userId = "User ID received: "+userId+" "+curDate.toString()+"\n";
log.info("Return Values is \n"+serviceName+actionName+bodyStr+userId);
return serviceName+actionName+bodyStr+userId;
}
/*public static void main(String[] args) {
System.out.println("CHECKING...");
GetDemoTicketv2 obj = new GetDemoTicketv2();
String retVal = obj.getTicket("My Service T", "My Action T", "My Body String T", "My User ID T");
System.out.println(retVal);
}*/}
Client -->
package com.gateway.request.demo;
import java.rmi.RemoteException;
public class TestService {
public static void main(String[] args) {
// TODO Auto-generated method stub
GetDemoTicketv2Proxy pxy = new GetDemoTicketv2Proxy("http://hostname:9081/Gateway_Webservice_For_ISTM_v3.0/GetDemoTicketv2Service");
try {
String retVal = pxy.getTicket("SERVICE", "ACTION", "BODY", "USER ID");
System.out.println("Value returned:\n"+retVal);
} catch (RemoteException e) {
// TODO Auto-generated catch block
System.out.println("RemoteException while consuming web service");
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception while consuming web service");
e.printStackTrace();
}
}}
log4j.properties
log4j.rootLogger=DEBUG, main
log4j.appender.main=org.apache.log4j.RollingFileAppender
log4j.appender.main.MaxFileSize=15MB
log4j.appender.main.MaxBackupIndex=10
log4j.appender.main.File=logs/DemoRequest.log
log4j.appender.main.layout=org.apache.log4j.PatternLayout
log4j.appender.main.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n
Upvotes: 0
Views: 3520
Reputation: 1044
From the above code snippets - it seems like its missing the logic to load the log4j.properties file, which you should load in the beginning of your program. So please try adding something like:
Properties applicationProp = new Properties();
String applicationPropFilePath = "C:\\log4j.properties";
load( applicationPropFilePath, applicationProp );
/* This method is a cookie-cutter and loads the given properties file to the given handle */
public static void load( String propFilepath, Properties propFileHandle ){
try {
InputStream is = new FileInputStream( propFilepath );
propFileHandle.load( is );
} catch (FileNotFoundException e) {
System.out.println(" Unable to locate properties file: " + propFilepath + e );
} catch (IOException e) {
System.out.println(" IO Error while loading properties file: " + propFilepath + e );
} catch (Exception e) {
System.out.println(" Some error occurred while loading properties file: " + propFilepath + e );
}
Upvotes: 1