我正在按照本教程使用 Google 端点框架在 Google 应用程序引擎 Java 项目上实现 Twilio。所以,我尝试了最新版本的 Twilio 并实现了它的 7.1.0 版本。小服务程序代码是
`public class SendSmsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
final String twilioAccountSid = System.getenv("TWILIO_ACCOUNT_SID");
final String twilioAuthToken = System.getenv("TWILIO_AUTH_TOKEN");
final String twilioNumber = System.getenv("TWILIO_NUMBER");
final String toNumber = (String) req.getParameter("to");
if (toNumber == null) {
resp.getWriter()
.print("Please provide the number to message in the \"to\" query string parameter.");
return;
}
Twilio.init(twilioAccountSid, twilioAuthToken);
String sms="This is the ship that made the Kessel Run in fourteen parsecs?";
Message message = Message.creator(new PhoneNumber(toNumber),
new PhoneNumber("+1 904-222-6016 "),
"This is the ship that made the Kessel Run in fourteen parsecs?").create();
resp.getWriter().print(message.getSid());
}
}
当使用相关号码调用此端点时,它会给出流动错误
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit> (SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry (PoolingHttpClientConnectionManager.java:109)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init> (PoolingHttpClientConnectionManager.java:116)
at com.twilio.http.NetworkHttpClient.<init> (NetworkHttpClient.java:45)
at com.twilio.http.TwilioRestClient$Builder.<init> (TwilioRestClient.java:66)
at com.twilio.Twilio.getRestClient (Twilio.java:118)
at com.twilio.base.Creator.create (Creator.java:45)
at in.prago.merchant.servlet.SendSmsServlet.service (SendSmsServlet.java:58)
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.googlecode.objectify.ObjectifyFilter.doFilter (ObjectifyFilter.java:48)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter (ParseBlobUploadFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter (SaveSessionFilter.java:37)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter (JdbcMySqlConnectionCleanupFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter (TransactionCleanupFilter.java:48)
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.runtime.jetty.AppVersionHandlerMap.handle (AppVersionHandlerMap.java:257)
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 com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable (RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle (HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:657)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:619)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:589)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext (TraceContext.java:453)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run (TraceContext.java:460)
at com.google.tracing.CurrentContext.runInContext (CurrentContext.java:293)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref (TraceContext.java:319)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext (TraceContext.java:311)
at com.google.tracing.TraceContext$TraceContextRunnable.run (TraceContext.java:457)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:263)
at java.lang.Thread.run (Thread.java:745)
我的 pom.xml 有点像这样
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.echo</groupId>
<artifactId>echo</artifactId>
<parent>
<artifactId>appengine-doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>../..</relativePath>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<endpoints.framework.version>2.0.7</endpoints.framework.version>
<endpoints.management.version>1.0.3</endpoints.management.version>
<endpoints.project.id>MY_PROJECT_KEY</endpoints.project.id>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<appengine.maven.plugin.version>1.3.1</appengine.maven.plugin.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.googlecode.objectify/objectify -->
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
<version>5.1.17</version>
</dependency>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<scope>compile</scope>
<version>7.1.0</version>
</dependency>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>${endpoints.management.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>GetSwaggerDoc</id>
<activation>
<property>
<name>GetSwaggerDoc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>com.google.api.server.spi.tools.EndpointsTool</mainClass>
<arguments>
<argument>get-swagger-doc</argument>
<argument>--hostname=echo-api.endpoints.${endpoints.project.id}.cloud.goog</argument>
<argument>--war=target/echo-1.0-SNAPSHOT</argument>
<argument>com.example.echo.Echo</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework-tools</artifactId>
<version>${endpoints.framework.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.30</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<!-- for hot reload of the web application-->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
查看堆栈跟踪,我认为存在一些 SSL 问题。我是谷歌云的新手。请指导解决这个问题。