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;
47 import org.onap.dmaap.datarouter.provisioning.FeedServlet;
50 public static void main(String[] args)
51 throws KeyStoreException, FileNotFoundException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException
53 AbstractHttpClient httpclient = new DefaultHttpClient();
55 String keystore = "/home/eby/dr2/misc/client.keystore";
56 String kspass = "changeit";
57 KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
58 FileInputStream instream = new FileInputStream(new File(keystore));
60 trustStore.load(instream, kspass.toCharArray());
61 } catch (Exception x) {
62 System.err.println("READING KEYSTORE: "+x);
64 try { instream.close(); } catch (Exception ignore) {}
67 SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore, "changeit", trustStore);
68 Scheme sch = new Scheme("https", 443, socketFactory);
69 httpclient.getConnectionManager().getSchemeRegistry().register(sch);
71 JSONObject jo = buildFeedRequest();
72 for (int i = 0; i < 10000; i++) {
73 jo.put("version", ""+System.currentTimeMillis());
75 String url = "https://conwy.proto.research.att.com:6443/";
76 HttpPost httpPost = new HttpPost(url);
78 httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
79 String t = jo.toString();
80 HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
81 httpPost.setEntity(body);
83 HttpResponse response = httpclient.execute(httpPost);
84 rv = response.getStatusLine().getStatusCode();
85 HttpEntity entity = response.getEntity();
86 EntityUtils.consume(entity);
87 } catch (IOException e) {
88 System.err.println(e);
90 httpPost.releaseConnection();
92 System.out.println(i + " " + rv);
95 private static JSONObject buildFeedRequest() {
96 JSONObject jo = new JSONObject();
97 jo.put("name", "feed");
98 jo.put("version", ""+System.currentTimeMillis());
99 jo.put("description", "Sample feed used by JUnit to test");
101 JSONObject jo2 = new JSONObject();
102 jo2.put("classification", "unrestricted");
104 JSONArray ja = new JSONArray();
105 JSONObject jo3 = new JSONObject();
106 jo3.put("id", "id001");
107 jo3.put("password", "re1kwelj");
108 JSONObject jo4 = new JSONObject();
109 jo4.put("id", "id002");
110 jo4.put("password", "o9eqlmbd");
113 jo2.put("endpoint_ids", ja);
115 ja = new JSONArray();
117 ja.put("192.168.0.1");
118 ja.put("135.207.136.128/25");
119 jo2.put("endpoint_addrs", ja);
121 jo.put("authorization", jo2);