サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') import org.apache.http.client.entity.* import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.auth.* import org.apache.http.message.* import org.apache.http.protocol.* import groovy.json.* def host = "192.168.1.219" def port = 15672 def user = "guest" def pass = "guest" def httpclient = new DefaultHttpClient() httpclient.getCredentialsProvider().setCredentials( new AuthScope(host, port), new UsernamePasswordCredentials(user, pass) ) def method = new HttpGet("http://${host}:${port}/api/exchanges") response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def json = new JsonSlurper().parseText(response.getEntity().getContent().text) println json println "----" for(exchange in json){ println "[${exchange.name}]:type=${exchange.type}" }動作環境
groovy 2.3.6, JDK7 update 65, RabbitMQ 3.3.5
0 件のコメント:
コメントを投稿