Техническое Руководство для Cisco Cisco Security Manager 4.7
Cisco Security Manager 4.4 API Specification (Version 1.1)
OL- 29074-01
Page 178
import
java.util.Properties;
public
class
RestClient {
public
static
CookieStore
ascookie
=
null
;
public
static
DefaultHttpClient
httpclient
;
static
{
initSSL();
}
}
private
static
void
initSSL() {
SSLContext sslContext =
null
;
try
{
sslContext = SSLContext.getInstance(
"SSL"
);
sslContext.init(
null
,
new
TrustManager[] {
new
X509TrustManager() {
public
X509Certificate[] getAcceptedIssuers() {
System.
out
.println(
"getAcceptedIssuers ============="
);
return
null
;
}
public
void
checkClientTrusted(X509Certificate[] certs, String authType) {
System.
out
.println(
"checkClientTrusted ============="
);
}
public
void
checkServerTrusted(X509Certificate[] certs, String authType) {
System.
out
.println(
"checkServerTrusted ============="
);
}
}},
}},
new
SecureRandom());
SSLSocketFactory sf =
new
SSLSocketFactory(sslContext);
Scheme httpsScheme =
new
Scheme(
"https"
, 443, sf);
SchemeRegistry schemeRegistry =
new
SchemeRegistry();
schemeRegistry.register(httpsScheme);
HttpParams params =
HttpParams params =
new
BasicHttpParams();
ClientConnectionManager cm =
new
ThreadSafeClientConnManager(params, schemeRegistry);
httpclient
=
new
DefaultHttpClient(cm, params);
}
catch
(NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
catch
(KeyManagementException e) {
e.printStackTrace();
}
}
}
}
/**
* This method will send the XML payload and return the XML response as a string.
*
@param
uri
*
@param
host
*
@param
isCookieNeeded
*
@return
*
@throws
IOException
*
@throws
ClientProtocolException
*/
public
void
doPost (URI uri, String payload, String host,
boolean
isCookieNeeded)
throws
Exception {
HttpResponse httpresponse =
HttpResponse httpresponse =
null
;
HttpPost httppost =
new
HttpPost (uri);
if
(isCookieNeeded) {
httpclient
.setCookieStore(
ascookie
);
}
httppost.addHeader(
httppost.addHeader(
"Content-Type"
,
"text/xml"
);
StringEntity strEntity =
new
StringEntity (payload,
"UTF-8"
);
httppost.setEntity(strEntity);