部署REST Web服务时出现错误。

11

我对REST Web服务不熟悉。

http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/中选择了一个例子。

在访问URL http://localhost:8080/RESTfulExample/rest/hello/mkyong 时,我遇到了这个奇怪的错误:

输入图像描述

详细信息如下:

PLATFORM VERSION INFO
    Windows             : 6.1.7601.65536 (Win32NT)
    Common Language Runtime     : 4.0.30319.1022
    System.Deployment.dll       : 4.0.30319.1 (RTMRel.030319-0100)
    clr.dll             : 4.0.30319.1022 (RTMGDR.030319-1000)
    dfdll.dll           : 4.0.30319.1 (RTMRel.030319-0100)
    dfshim.dll          : 4.0.31106.0 (Main.031106-0000)

SOURCES
    Deployment url          : http://localhost:8080/rs1/rest/hello/hi,

ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * Activation of http://localhost:8080/rs1/rest/hello/hi, resulted in exception. Following failure messages were detected:
        + Exception reading manifest from http://localhost:8080/rs1/rest/hello/hi,: the manifest may not be valid or the file could not be opened.
        + Data at the root level is invalid. Line 1, position 1.

COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

WARNINGS
    There were no warnings during this operation.

OPERATION PROGRESS STATUS
    * [9/16/2014 11:30:26 AM] : Activation of `http://localhost:8080/rs1/rest/hello/hi`, has started.

ERROR DETAILS
    Following errors were detected during this operation.
    * [9/16/2014 11:30:26 AM] System.Deployment.Application.InvalidDeploymentException (ManifestParse)
        - Exception reading manifest from http://localhost:8080/rs1/rest/hello/hi,: the manifest may not be valid or the file could not be opened.
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
            at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
        --- Inner Exception ---
        System.Xml.XmlException
        - Data at the root level is invalid. Line 1, position 1.
        - Source: System.Xml
        - Stack trace:
            at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
            at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
            at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
            at System.Deployment.Application.ManifestValidatingReader.XmlFilteredReader.Read()
            at System.Xml.XmlCharCheckingReader.Read()
            at System.Xml.XsdValidatingReader.Read()
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)

COMPONENT STORE TRANSACTION DETAILS
    No transaction information is available.

我正在使用Eclipse Kepler和Apache Tomcat 6。


你有使用过Poster吗? - Kishan Bheemajiyani
5个回答

15

我也在IE上遇到了这个问题。我正在使用Tomcat 8,jersey用于REST,并使用LDAP安全约束将用户引导到登录页面。登录页面显示正常,但在认证后,此错误仍然存在。我们的用户基本上都是IE用户,因此使用Chrome、Firefox等浏览器并不是一个真正的选择(尽管该网站在它们上面按预期工作)。

只是提醒,在IE中将该站点添加到“受信任站点”可以解决这个问题。

对日志文件进行一些挖掘会发现,似乎IE正在尝试启动一个应用程序(ClickOnce),并期望有一个清单文件。这很令人困惑,可能会误导人,因为我们的站点上没有应用程序。非常感谢任何提供帮助的人。

更新:我成功解决了这个问题。在查看我的域类时,我想到我没有为响应指定MIME类型。在我的域(rest)类方法中添加@Produces("text/html")注释解决了这个问题:

例如:

@GET
@Produces("text/html")
public Response welcome()
{
return Response.ok("This should now work in IE").build();
}

我猜测如果IE在响应头中没有特别指定这种MIME类型,它就会认为你正在尝试提供一个应用程序(ClickOnce)。我希望IE能更像Chrome或Firefox。


我有同样的问题。我还发现,如果我在兼容模式下运行站点,该问题仅在IE 11上发生。否则它可以正常工作。 - dleerob
哇哦,IE 又出问题了!!如果我跟着一个链接到我的 URL,它可以正常工作。如果我点击刷新,它也可以正常工作。但是如果我接着点击地址栏并按下回车键(URL 没有改变),它就会抛出那个错误!! - dleerob

3

我也曾遇到这个问题。如果你使用Chrome或者IE等其他浏览器,它就可以正常工作。


1
如果您在使用Spring MVC时遇到此问题,则可以通过将 produces = mime type 添加到 @RequestMapping 注释中来解决该问题。结果类似于以下内容:
...
@RequestMapping(value = "/mapping-address", produces = "text/html;charset=UTF-8")
...

当我使用@ResponseBody注解注释一个返回String类型的方法时,遇到了这个问题。


1

我知道可能有点晚了。虽然我是个新手,但我想分享一下我解决这个问题的方法。所以,我遇到了同样的错误,但是我通过以下步骤解决了它:

  1. 打开您的网络浏览器(例如我使用的是Chrome)
  2. 打开apache tomcat的主屏幕

http://localhost:{port} (在Eclipse中默认为端口8080)

  1. 打开 "Manager App"。在我这种情况下,我需要修改位于apache路径安装中的 tomcat-user.xml 文件。(因此,您将拥有管理员权限)
  2. 当您打开 Manager App 时,您将看到您的 /RESTfulExample 在一行中。检查它是否正在运行
  3. 最后,在您的网络浏览器中输入

    http://localhost:8080/RESTfulExample/rest/hello/hello%20world

  4. 然后你会看到

    Jersey say : hello world

我希望您能在心中有另一个解决方案


0

我有同样的问题,这不是一个答案,只是为了给问题添加更多信息。只有当我的IE 11处于该域名/ URL的兼容模式下时,我才会遇到这个问题。

如果我关闭兼容模式,响应就会按照预期进行解释。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接