gpt4 book ai didi

java - 为什么我的 SalesForce.com-GoogleApp 无法初始化 com.sforce.ws.ConnectorConfig 类?

转载 作者:行者123 更新时间:2023-12-01 15:57:39 25 4
gpt4 key购买 nike

我目前正在编写一个名为 Force.com for Google App Engine for Java: Getting Started 的 SalesForce.com 教程。

我已经安装了 Google Eclipse 插件,下载了库并将它们安装到构建路径,然后进入“Hello World App”(如教程页面所示):

package com.force;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;
import java.util.logging.*;

import com.sforce.ws.*;
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;


@SuppressWarnings("serial")
public class HelloWorldServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(HelloWorldServlet.class.getName());

private String username = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private String password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private PartnerConnection connection;

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("Hello, world. this is a test2");

PrintWriter t = resp.getWriter();
getConnection( t, req);
if ( connection == null ) { return; }

QueryResult result = null;

try {

result = connection.query( "select id, name, phone from Account order by LastModifiedDate desc limit 10 ");

} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (SObject account : result.getRecords()) {
t.println("<li>"+ (String)account.getField("Name") + "</li>");
}
}

void getConnection(PrintWriter out, HttpServletRequest req) {

try {
// build up a ConnectorConfig from a sid
String sessionid = req.getParameter("sid");
String serverurl = req.getParameter("srv");

if ( connection == null ) {

out.println("<p>new connection needed</p>");
// login to the Force.com Platform
ConnectorConfig config = new ConnectorConfig();
if ( sessionid != null && serverurl != null) {
config.setServiceEndpoint(serverurl);
config.setSessionId(sessionid);
config.setManualLogin(false);
out.println("using session from query string");
} else {
config.setUsername(username);
config.setPassword(password);
}
connection = Connector.newConnection(config);
out.println( connection.getConfig().getSessionId() );
out.println( connection.getConfig().getServiceEndpoint() );
} else {
out.println("<p> reuse existing connection");
out.println( connection.getConfig().getSessionId() );
}
log.warning("Connection SID " +connection.getConfig().getSessionId());

} catch ( ConnectionException ce) {
log.warning("ConnectionException " +ce.getMessage());

out.println( ce.getMessage() + " s " + ce.getClass() );

}

}
}

当我将应用程序作为“Web 应用程序”运行时,我在 Web 浏览器中看到以下内容:

    HTTP ERROR 500

Problem accessing /sfdc_gae_tutorials/hello2. Reason:

Could not initialize class com.sforce.ws.ConnectorConfig
Caused by:

java.lang.NoClassDefFoundError: Could not initialize class com.sforce.ws.ConnectorConfig
at hu.flux.salesforce.hello.HelloWorld2Servlet.getConnection(HelloWorld2Servlet.java:57)
at hu.flux.salesforce.hello.HelloWorld2Servlet.doGet(HelloWorld2Servlet.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Powered by Jetty://

知道为什么初始化没有发生、出了什么问题和/或如何修复它吗?

最佳答案

您没有将 WSC 添加到 Eclipse 项目的类路径中。从您发布的教程中:

  • 将 Force.com Java 库(wsc.jar + Partner-library.jar 或 your-enterprise-library.jar)添加到应用程序的 WEB-INF/lib 文件夹
  • 右键单击新添加的库,然后选择“构建路径 -> 添加到构建路径”

这些说明的唯一问题是您应该使用 wsc-gae-*.jar,而不仅仅是常规的 wsc.jar。

关于java - 为什么我的 SalesForce.com-GoogleApp 无法初始化 com.sforce.ws.ConnectorConfig 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4787697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com