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 ******************************************************************************/
24 package datarouter.provisioning;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.security.KeyManagementException;
31 import java.security.KeyStore;
32 import java.security.KeyStoreException;
33 import java.security.NoSuchAlgorithmException;
34 import java.security.UnrecoverableKeyException;
36 import org.apache.http.HttpEntity;
37 import org.apache.http.HttpResponse;
38 import org.apache.http.client.methods.HttpPost;
39 import org.apache.http.conn.scheme.Scheme;
40 import org.apache.http.conn.ssl.SSLSocketFactory;
41 import org.apache.http.entity.ByteArrayEntity;
42 import org.apache.http.entity.ContentType;
43 import org.apache.http.impl.client.AbstractHttpClient;
44 import org.apache.http.impl.client.DefaultHttpClient;
45 import org.apache.http.util.EntityUtils;
46 import org.json.JSONArray;
47 import org.json.JSONObject;
48 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
57 * This is the main method of the FillDB class.
59 * @throws KeyStoreException KeyStore exception
60 * @throws FileNotFoundException Exeception thrown when error locating file
61 * @throws KeyManagementException KeyManagement exception
62 * @throws UnrecoverableKeyException Exception thrown when Key cannot be recovered
63 * @throws NoSuchAlgorithmException Exception thrown when algorithm does not exist
65 public static void main(String[] args)
66 throws KeyStoreException, FileNotFoundException, KeyManagementException, UnrecoverableKeyException,
67 NoSuchAlgorithmException {
68 AbstractHttpClient httpclient = new DefaultHttpClient();
70 String keystore = "/home/eby/dr2/misc/client.keystore";
71 String kspass = "changeit";
72 KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
73 FileInputStream instream = new FileInputStream(new File(keystore));
75 trustStore.load(instream, kspass.toCharArray());
76 } catch (Exception x) {
77 System.err.println("READING KEYSTORE: " + x);
81 } catch (Exception ignore) {
86 SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore, "changeit", trustStore);
87 Scheme sch = new Scheme("https", 443, socketFactory);
88 httpclient.getConnectionManager().getSchemeRegistry().register(sch);
90 JSONObject jo = buildFeedRequest();
91 for (int i = 0; i < 10000; i++) {
92 jo.put("version", "" + System.currentTimeMillis());
94 String url = "https://conwy.proto.research.att.com:6443/";
95 HttpPost httpPost = new HttpPost(url);
97 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
98 String feedRequestString = jo.toString();
99 HttpEntity body = new ByteArrayEntity(feedRequestString.getBytes(),
100 ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
101 httpPost.setEntity(body);
103 HttpResponse response = httpclient.execute(httpPost);
104 rv = response.getStatusLine().getStatusCode();
105 HttpEntity entity = response.getEntity();
106 EntityUtils.consume(entity);
107 } catch (IOException e) {
108 System.err.println(e);
110 httpPost.releaseConnection();
112 System.out.println(i + " " + rv);
116 private static JSONObject buildFeedRequest() {
117 JSONObject jo = new JSONObject();
118 jo.put("name", "feed");
119 jo.put("version", "" + System.currentTimeMillis());
120 jo.put("description", "Sample feed used by JUnit to test");
122 JSONObject jo2 = new JSONObject();
123 jo2.put("classification", "unrestricted");
126 JSONObject jo3 = new JSONObject();
127 jo3.put("id", "id001");
128 jo3.put("password", "re1kwelj");
130 JSONObject jo4 = new JSONObject();
131 jo4.put("id", "id002");
132 jo4.put("password", "o9eqlmbd");
134 JSONArray ja = new JSONArray();
137 jo2.put("endpoint_ids", ja);
139 ja = new JSONArray();
141 ja.put("192.168.0.1");
142 ja.put("135.207.136.128/25");
143 jo2.put("endpoint_addrs", ja);
145 jo.put("authorization", jo2);