zoukankan      html  css  js  c++  java
  • Jersey实现跨服务器上传图片:UniformInterfaceException:403 Forbidden

    jersey.api.client.UniformInterfaceException :returned a response status of 403 Forbidden

    图片服务器:端口8082



    图片上传:

    public PictureResult uploadFile(MultipartFile uploadFile) {
    		PictureResult result=new PictureResult();
    		//判断图片是否为空
    		if (uploadFile.isEmpty()) {
    			result.setError(1);
    			result.setMessage("图片为空");
    			return result;
    		}
    		//图片上传服务器
    		try {
    			//文件名称  在服务器可能重复
    			String newFileName=new SimpleDateFormat("yyyymmddHHmmssSSS").format(new Date());
    			//文件名+随机数 防止重复
    			Random random=new Random();
    			for (int i = 0; i < 3; i++) {
    				newFileName=newFileName +random.nextInt(10);
    			}
    			//根据日期生成目录
    			String path= new SimpleDateFormat("yyyy").format(new Date())+"/"
    						+new SimpleDateFormat("mm").format(new Date())+"/"+
    						new SimpleDateFormat("dd").format(new Date())+"/";
    			
    			//获取文件扩展名
    			String suffix = FilenameUtils.getExtension(uploadFile.getOriginalFilename());
    			
    			//创建jesy服务器  进行跨服务器上传
    			Client client = Client.create();
    			//把文件关联到远程服务器
    			String url=PIC_HOST+path+newFileName+"."+suffix;
    			WebResource resource = client.resource(url);
    			//上传
    			resource.put(String.class, uploadFile.getBytes());
    
    			//上传成功 响应给客户端
    			result.setError(0);
    			result.setUrl(url);
    		} catch (Exception e) {
    			e.printStackTrace();
    			result.setError(1);
    			result.setMessage("图片上传失败");
    		}
    		
    		return result;


    一直报错:

    后来定位到 put的地方:


    后来发现 :图片服务器的 配置下web.xml

    是默认只读  不能保存的

        <servlet>
            <servlet-name>default</servlet-name>
            <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
            <init-param>
                <param-name>debug</param-name>
                <param-value>0</param-value>
            </init-param>
            <init-param>
                <param-name>listings</param-name>
                <param-value>true</param-value>
            </init-param>
    
       
      <!--       readonly        Is this context "read only", so HTTP           -->
    <!-- commands like PUT and DELETE are --> <!-- rejected? [true] <init-param> <param-name>readonly</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
    
    


    修改之后就ok了


  • 相关阅读:
    centos 7 -- Disk Requirements: At least 134MB more space needed on the / filesystem.
    DNS Server Centos 7
    生成report由Eamil定時寄出
    WRT 版本说明
    cisco linksys ea3500 刷机 openwrt
    [QNAP crontab 定時執行程式
    实例 编辑 .bashrc(不断更新)
    tar命令
    ls -l 显示年份
    git 丢弃本地代码时遇到的问题
  • 原文地址:https://www.cnblogs.com/inyu/p/13659102.html
Copyright © 2011-2022 走看看