2013-10-22 43 views
1

我使用Apache Camel发送邮件。当我打电话的发送方法从我的主类,我没有得到任何异常,但是当我试图从其他服务,那么我得到这个异常调用它,整条曲线是在这里:获取异常org.apache.cxf.interceptor.Fault:org/apache/camel/CamelContext

http://camel.465427.n5.nabble.com/i-am-getting-exception-org-apache-cxf-interceptor-Fault-org-apache-camel-CamelContext-td5742012.html#a5742016

这是我休息服务的方法。

@POST 
@Path("/sendemail") 
public Response sendEmail(final String userdata) 
{ 
    System.out.println("the starting of the send email process"); 
    ResponseBuilder builder=Response.ok(); 
    JSONObject data=(JSONObject) JSONSerializer.toJSON(userdata); 

    EmailInterface ei=new EmailInterface(); 
    boolean status=ei.sendEmail(data); 
    if(status) 
     builder.status(200).entity("SUCCESS"); 
    else 
     builder.status(400).entity("UN SUCCESS"); 
    return builder.build(); 
} 

此方法调用EmailInterface类的方法。

public class EmailInterface { 
    private CamelContext camel; 
    private ProducerTemplate template; 

public boolean sendEmail(JSONObject data) 
{ 
    boolean status=false; 
    camel = new DefaultCamelContext(); 
    template = camel.createProducerTemplate(); 

    Map<String, Object> map = new HashMap<String, Object>(); 
    map.put("To",data.getString("toaddress")); 
    String body = data.getString("body"); 
    map.put("Subject", data.getString("subject")); 
    map.put("From", "[email protected]"); 

    template.sendBodyAndHeaders("smtps://smtp.gmail.com?     [email protected]&password=ixxxxx", body, map); 
    status=true; 
    return status; 

} 
    public static void main(String args[]) 
{ 

    JSONObject data=new JSONObject(); 
    data.put("toaddress", "[email protected]"); 
    data.put("subject", "Service Status"); 
    data.put("body", "hi testing message"); 
    EmailInterface emailInterface=new EmailInterface(); 
    System.out.println(emailInterface.sendEmail(data)); 
} 

当我从EmailInterface的主要方法调用,那么它的做工精细,并发送电子邮件,但是当我试图从REST调用,然后我只得到这个execption。

+0

看来你的libs有问题(* java.lang.NoClassDefFoundError:org/apache/camel/CamelContext *)。在部署Web服务时,你确定骆驼库包含在战争中吗? – Pith

+0

我包括两个lib文件到类path.so它从主要类的工作,但不工作从休息uri。 – user2549122

+0

hey.i包含在类路径然后它不工作,但是当我在apache lib文件夹pute,然后它的工作正常...感谢您的帮助。 – user2549122

回答

4

看来你的libs文件有问题java.lang.NoClassDefFoundError: org/apache/camel/CamelContext

将它们包含在服务器的lib文件夹中。