【问题标题】:Why am I not seeing my Java / SalesForce / Google App?为什么我看不到我的 Java/SalesForce/Google 应用程序?
【发布时间】:2011-01-22 19:28:51
【问题描述】:

我目前正在编写名为 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 应用程序”运行时,我会在控制台中看到以下内容:

Initializing AppEngine server
Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Successfully processed D:\education\java\HelloWorldOriginal\war\WEB-INF/appengine-web.xml
Successfully processed D:\education\java\HelloWorldOriginal\war\WEB-INF/web.xml
The server is running at http://localhost:8888/
Warning: default mime table not found: C:\devtool\Java\jre6\lib\content-types.properties

当我尝试访问 http://localhost:8080/ 时,我看到:

Oops! Google Chrome could not connect to localhost:8080
Did you mean: localhost-­8080.­com
Additional suggestions:
Try reloading: localhost:­8080
Search on Google:

Google Chrome Help - Why am I seeing this page?
©2011 Google - Google Home

但是当我访问 http://localhost:8888/ 时,我得到:

Web Application Starter Project

Please enter your name:
    Send

(这也不是期望或预期的结果。)

我缺少的这个 content-type.properties 是什么,我该如何解决?还是这只是更大问题的征兆?

【问题讨论】:

    标签: java google-app-engine wsdl salesforce mime-types


    【解决方案1】:

    您是否检查过您的 web.xml 是否将 / 的请求定向到相应的处理程序类?仅仅编写类是不够的——你必须确保传入的请求被定向到它。

    【讨论】:

    • 我认为您可能对此有所了解...我隐约记得为一些早期的动态 Web 应用程序这样做过,但后来发现由于一些注释,较新的应用程序不需要这个... . 我会试试这个然后回复你。 :-)
    • 现在我遇到了一些其他错误,但我稍后会解决它们。为修复我询问的问题而欢呼。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多