Java tutorial
package com.yihaodian.performance; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; @Mojo(name = "upload", defaultPhase = LifecyclePhase.TEST, threadSafe = true, requiresDependencyResolution = ResolutionScope.TEST) public class UploadReportMojo extends AbstractMojo { @Parameter(property = "dtmp.upload_end_point", defaultValue = "http://dtmp.yihaodian.com.cn/perf4junit/upload") private String endPoint; @Override public void execute() throws MojoExecutionException { File file = new File("target/perf4junit/report.xml"); FileInputStream fis; BufferedInputStream bis; try { fis = new FileInputStream(file); bis = new BufferedInputStream(fis); HttpClient httpclient = new DefaultHttpClient(); HttpPost http = new HttpPost(endPoint); http.setEntity(new InputStreamEntity(bis, file.length())); HttpResponse response = httpclient.execute(http); getLog().info(endPoint); bis.close(); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }