1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
23 package datarouter.provisioning;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.security.KeyManagementException;
30 import java.security.KeyStore;
31 import java.security.KeyStoreException;
32 import java.security.NoSuchAlgorithmException;
33 import java.security.UnrecoverableKeyException;
35 import org.apache.http.HttpEntity;
36 import org.apache.http.HttpResponse;
37 import org.apache.http.client.methods.HttpPost;
38 import org.apache.http.conn.scheme.Scheme;
39 import org.apache.http.conn.ssl.SSLSocketFactory;
40 import org.apache.http.entity.ByteArrayEntity;
41 import org.apache.http.entity.ContentType;
42 import org.apache.http.impl.client.AbstractHttpClient;
43 import org.apache.http.impl.client.DefaultHttpClient;
44 import org.apache.http.util.EntityUtils;
45 import org.json.JSONArray;
46 import org.json.JSONObject;
48 import com.att.research.datarouter.provisioning.FeedServlet;
51 public static void main(String[] args)
52 throws KeyStoreException, FileNotFoundException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException
54 AbstractHttpClient httpclient = new DefaultHttpClient();
56 String keystore = "/home/eby/dr2/misc/client.keystore";
57 String kspass = "changeit";
58 KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
59 FileInputStream instream = new FileInputStream(new File(keystore));
61 trustStore.load(instream, kspass.toCharArray());
62 } catch (Exception x) {
63 System.err.println("READING KEYSTORE: "+x);
65 try { instream.close(); } catch (Exception ignore) {}
68 SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore, "changeit", trustStore);
69 Scheme sch = new Scheme("https", 443, socketFactory);
70 httpclient.getConnectionManager().getSchemeRegistry().register(sch);
72 JSONObject jo = buildFeedRequest();
73 for (int i = 0; i < 10000; i++) {
74 jo.put("version", ""+System.currentTimeMillis());
76 String url = "https://conwy.proto.research.att.com:6443/";
77 HttpPost httpPost = new HttpPost(url);
79 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
80 String t = jo.toString();
81 HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
82 httpPost.setEntity(body);
84 HttpResponse response = httpclient.execute(httpPost);
85 rv = response.getStatusLine().getStatusCode();
86 HttpEntity entity = response.getEntity();
87 EntityUtils.consume(entity);
88 } catch (IOException e) {
89 System.err.println(e);
91 httpPost.releaseConnection();
93 System.out.println(i + " " + rv);
96 private static JSONObject buildFeedRequest() {
97 JSONObject jo = new JSONObject();
98 jo.put("name", "feed");
99 jo.put("version", ""+System.currentTimeMillis());
100 jo.put("description", "Sample feed used by JUnit to test");
102 JSONObject jo2 = new JSONObject();
103 jo2.put("classification", "unrestricted");
105 JSONArray ja = new JSONArray();
106 JSONObject jo3 = new JSONObject();
107 jo3.put("id", "id001");
108 jo3.put("password", "re1kwelj");
109 JSONObject jo4 = new JSONObject();
110 jo4.put("id", "id002");
111 jo4.put("password", "o9eqlmbd");
114 jo2.put("endpoint_ids", ja);
116 ja = new JSONArray();
118 ja.put("192.168.0.1");
119 ja.put("135.207.136.128/25");
120 jo2.put("endpoint_addrs", ja);
122 jo.put("authorization", jo2);