2015-02-10 54 views
0

我是web服务的新手,并在本地主机(Websphere Application Server 8)上发布了Web服务。在Websphere Application Server上发布的Web服务没有生成日志8

我能够成功,但不使用的Web服务能够发现哪里如何产生,甚至日志如何产生与否的日志。

我有地方log4j.properties文件的WebContent/WEB-INF/classes中,但这个文件是文件被自动删除得到当我试图生成从Java WSDL(步骤 - 右击项目名称 - >新建 - > Web服务 - >选择类)

文件生成的:

  1. 的deploy.wsdd
  2. deploy.wsdd.bak
  3. undeploy.wsdd

的WebContent/WEB-INF获取添加一些JAR文件/ lib

后的文件被删除我已经再次复制log4j.properties的WebContent/WEB-INF/classes中和出口这是部署在服务器上的EAR。

我已经检查日志文件夹中:

  • d:\ IBM \的WebSphere \ AppServer的\型材\ cw_profile \日志
  • d:\ IBM \的WebSphere \ AppServer的\日志\的manageprofiles \ cw_profile

但没有生成日志文件。

主要网络服务 - >

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); 
}*/} 

客户端 - >

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 
+0

所有我认为你在log4j.properties编辑您的变量首先: log4j.appender.main.File = /日志/ ISTMRequest.log – adimoise91 2015-02-10 14:35:49

+0

日志没有得到即使将变量更改为log4j.appender.main.File =/logs/ISTMRequest.log – Lizzie 2015-02-11 05:48:31

+0

您的路径(/ logs /)存在?如果该文件夹未创建,则可以在SystemOut.log中编写文件,因此请为您的路径创建日志文件夹。长话短说:在根,创建文件夹日志:)我在等你回答。 ;) – adimoise91 2015-02-11 08:43:41

回答

1

在t他上面的代码片段 - 它似乎缺少加载log4j.properties文件的逻辑,您应该在程序开始时加载该文件。所以,请尽量添加类似:

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); 
    } 
相关问题