0

我是发送了一次请求,之后请求并没有成功,显示如下信息:

二月 14, 2018 6:28:14 下午 org.apache.catalina.core.StandardServer await
信息: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["http-nio-8080"]
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["ajp-nio-8009"]
二月 14, 2018 6:28:14 下午 org.apache.catalina.core.StandardService stopInternal
信息: Stopping service Catalina
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol stop
信息: Stopping ProtocolHandler ["http-nio-8080"]
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol stop
信息: Stopping ProtocolHandler ["ajp-nio-8009"]
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["http-nio-8080"]
二月 14, 2018 6:28:14 下午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["ajp-nio-8009"]

下面是我的代码:

package com.main.service;


import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.rosuda.REngine.REXP;
import org.rosuda.REngine.Rserve.RConnection;

import com.main.util.Rservel;

public class WordCloud extends JFrame{
private static final long serialVersionUID=1L;
static Image img;
    public static void main(String[] args) throws Exception{
        // TODO Auto-generated method stub
        System.out.println("12");
        WordCloud wc=new WordCloud();
        REXP xp=wc.getRobj();//获得R对象
        wc.PlotDemo(xp,wc);//
        System.out.println("1212");
    }
    private REXP getRobj() throws Exception{
    
        RConnection c=Rservel.getRConnection();
        System.out.println("c=Rservel.getRConnection()......"+c);
        c.setStringEncoding("utf8");//设置字符编码
        System.out.println("12");
        //返回R的版本
        REXP Rservesion=c.eval("R.version.string");
        System.out.println(Rservesion.asString());
        System.out.println("\n----------绘图演示--------");
        System.out.println("");
        REXP xp=c.parseAndEval("jpeg('test.jpg',quality=90)");
        c.eval("library(RColorBrewer)");
        c.eval("H <- c(7,12,28,3,41)");
        c.eval("colors<-brewer.pal(5,'Set1')");
        c.parseAndEval(" barplot(H,rep(1,5),col=colors);dev.off()");
        xp=c.parseAndEval("r=readBin('test.jpg','raw',3000*3000);unlink('test.jpg');r");
        return xp;
    }
    public void PlotDemo(REXP xp, JFrame f)throws Exception{
        Image image=Toolkit.getDefaultToolkit().createImage(xp.asBytes());
        BufferedImage bufferedImage=toBufferedImage(image);
        try {
           ImageIO.write(bufferedImage, "JPG", new File("./outImg/90.jpg"));
       } catch (IOException e) {
           e.printStackTrace();
       }
    }


    
    public static BufferedImage toBufferedImage(Image image) {  
        if (image instanceof BufferedImage) {  
            return (BufferedImage)image;  
         }  
         image = new ImageIcon(image).getImage();  
         BufferedImage bimage = null;  
         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();  
        try {  
             
            int transparency = Transparency.OPAQUE;   
             GraphicsDevice gs = ge.getDefaultScreenDevice();  
             GraphicsConfiguration gc = gs.getDefaultConfiguration();  
             bimage = gc.createCompatibleImage(  
             image.getWidth(null), image.getHeight(null), transparency);  
         } catch (HeadlessException e) {  
         }  
        
        if (bimage == null) {   
            int type = BufferedImage.TYPE_INT_RGB;   
             bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);  
         }  
         Graphics g = bimage.createGraphics();  
         g.drawImage(image, 0, 0, null);  
         g.dispose();  
        
        return bimage;  
    }  

}


 

1 个回答

0

我在好奇你怎么在用swing和awt包下的?
可能是端口被占用的原因,直接在任务管理中kill。如果下次还是不能正常关闭,在service.xml 修改下端口。

google了下不出意外应该是这个端口被占用了:

<Server port="8005" shutdown="SHUTDOWN">