Java 在嵌入式tomcat服务器中调用JAX-RS API时,从浏览器调用415(不支持的媒体类型)

Java 在嵌入式tomcat服务器中调用JAX-RS API时,从浏览器调用415(不支持的媒体类型),java,javascript,web-services,jquery,jax-rs,Java,Javascript,Web Services,Jquery,Jax Rs,当我试图通过JAX-RSRESTAPI上传csv格式的excel文件时,我从浏览器中获得415(不支持的媒体类型)。Web应用程序是在嵌入式Tomcat服务器下部署和运行的 如果我在tomcat 7服务器上部署我的web应用程序,而该服务器不是嵌入式tomcat,我就能够成功上传csv文件 我感谢您为解决我的问题提供的意见 URL:ipaddress:8090/config/configutil/upload 浏览器标头请求失败: JAX-RSAPI 调用此JAX-RS API的Java脚本代码

当我试图通过JAX-RSRESTAPI上传csv格式的excel文件时,我从浏览器中获得415(不支持的媒体类型)。Web应用程序是在嵌入式Tomcat服务器下部署和运行的

如果我在tomcat 7服务器上部署我的web应用程序,而该服务器不是嵌入式tomcat,我就能够成功上传csv文件

我感谢您为解决我的问题提供的意见

URL:ipaddress:8090/config/configutil/upload

浏览器标头请求失败: JAX-RSAPI 调用此JAX-RS API的Java脚本代码: HTML页面:


Content-TypeHTTP头是根据您上面粘贴的JAX-RS方法的期望设置的,但是我在请求跟踪日志中看到了一个
boundary=---
。我不确定这是不是罪魁祸首。谢谢你的回复。但当我在Tomcat7服务器(未嵌入)中部署相同的web应用程序时,我并没有从浏览器中得到415个不受支持的错误。请参阅下面的成功标头请求。请求URL:请求方法:POST状态代码:200确定请求标头查看源接受:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3接受编码:gzip,deflate,sdch接受语言:en-US,en;q=0.8缓存控制:最大年龄=0连接:保持活动内容长度:6467内容类型:多部分/表单数据;边界=----WebKitFormBoundaryH6x1m2vr8SBat1fS Cookie:local=“9148@ASVINNAK-WS01“Host:localhost:8080源代码:Referer:找到此问题的解决方案。在提到META-INF文件下的mimepull.jar之后,文件导入正在工作。现在415个不受支持的媒体类型错误得到了解决。Aswani,如果您能更详细地解释解决方法/修复,并将其作为答案发布,这将对其他人有所帮助。
Content-type
HTTP头是按照您上面粘贴的JAX-RS方法的预期设置的,但我在请求跟踪日志中看到了一个
boundary=-
。我不确定这是不是罪魁祸首。谢谢你的回复。但当我在Tomcat7服务器(未嵌入)中部署相同的web应用程序时,我并没有从浏览器中得到415个不受支持的错误。请参阅下面的成功标头请求。请求URL:请求方法:POST状态代码:200确定请求标头查看源接受:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3接受编码:gzip,deflate,sdch接受语言:en-US,en;q=0.8缓存控制:最大年龄=0连接:保持活动内容长度:6467内容类型:多部分/表单数据;边界=----WebKitFormBoundaryH6x1m2vr8SBat1fS Cookie:local=“9148@ASVINNAK-WS01“Host:localhost:8080源代码:Referer:找到此问题的解决方案。在提到META-INF文件下的mimepull.jar之后,文件导入正在工作。现在415不支持的媒体类型错误已解决。Aswani,如果您能更详细地解释解决方法/修复方法,并将其作为答案发布,这将对其他人有所帮助。
Request URL:http://localhost:8090/config/configutil/upload
Request Method:POST
Status Code:415 Unsupported Media Type
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:2346
Content-Type:multipart/form-data; boundary=----WebKitFormBoundarycWT1QSyGGxijtUUP
Host:localhost:8090
Origin:http://localhost:8090
Referer:http://localhost:8090/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Request Payload
------WebKitFormBoundarycWT1QSyGGxijtUUP
Content-Disposition: form-data; name="UserExportFormat"

XML
------WebKitFormBoundarycWT1QSyGGxijtUUP
Content-Disposition: form-data; name="uploadedFile"; filename="1-06092012 (3).csv"
Content-Type: application/vnd.ms-excel


------WebKitFormBoundarycWT1QSyGGxijtUUP--
Response Headersview source
Cache-Control:no-cache
Content-Length:1117
Content-Type:text/html;charset=utf-8
Date:Tue, 18 Sep 2012 00:09:35 GMT
Server:Apache-Coyote/1.1
/**
     * API will import the ConfigSet from CSV file request and returns the response in Text/Html format.
     * @param is
     * @param request
     * @param response
     */


@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public void upload(@FormDataParam("uploadedFile") InputStream is, @Context HttpServletRequest request, @Context HttpServletResponse response) {
    // read it with BufferedReader

    ObjectMapper mapper = new ObjectMapper();
    PrintWriter out;
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(is));
        ConfigSetResponse configSetResponse = new CSVReader().csvReader(br);
        out = response.getWriter();
        mapper.writeValue(out, configSetResponse);

    } catch (Exception e) {
        logger.error("Error while uploading :", e);
        e.printStackTrace();
    } finally {
        // Close the file once all data has been read.
        try {
            if (null != br) {
                br.close();
            }
            if (null != is) {
                is.close();
            }
        } catch (IOException e) {
            logger.error("Error while uploading :", e);
            e.printStackTrace();
        }
    }
}
var importForm = $( modal ).find("#icwExportForm");                 


                        importForm.ajaxForm({
                            contentType: false,
                            success : function(responseObj) {
                                try{



                                    refreshConfigSetUI(eval(responseObj));
                                    ccw.modal.hide(modal);
                                }catch(e){
                                    ccw.modal.hide(modal);
                                    $('#runtimeErrorMessages').html(commonErrorData);                                   
                                }
                            },
                            error : function(request, msg,  err) {
                                ccw.modal.hide(modal);
                                $('#runtimeErrorMessages').html(commonErrorData);
                            }
                        });

                        importForm.attr("action", "config/configutil/upload");
                        importForm.attr("Content-Type" ,"multipart/form-data");
                        importForm.submit();
                    });
<form class="icwExportForm" id="icwExportForm"   method="post" action="" name="ExportOptionInputForm" enctype="multipart/form-data" accept-charset="utf-8">

<div class="icwImportContent" style="padding: 5px 0px 10px 20px">
                    <input type="file" name="uploadedFile" value="" id="icwUploadFile" class="icwButton" size="45"  tabindex="1" />

</div>

</form>