summaryrefslogtreecommitdiffstats
path: root/base/server/cmscore/src/com/netscape/cmscore/connector
diff options
context:
space:
mode:
authorChristina Fu <cfu@redhat.com>2014-03-24 15:47:16 -0700
committerChristina Fu <cfu@redhat.com>2014-03-25 10:27:26 -0700
commit35b8e2c69b86df07c2897e34861f4c6c636010a7 (patch)
tree3b0b136a81e08d49f5451f757e4a8323fd6c245b /base/server/cmscore/src/com/netscape/cmscore/connector
parentac40e7abc06a6cae1860ef6d364b84f03c9f1d40 (diff)
downloadpki-35b8e2c69b86df07c2897e34861f4c6c636010a7.tar.gz
pki-35b8e2c69b86df07c2897e34861f4c6c636010a7.tar.xz
pki-35b8e2c69b86df07c2897e34861f4c6c636010a7.zip
trac ticket #862 HTTP connection factory multi-uri addendum
Diffstat (limited to 'base/server/cmscore/src/com/netscape/cmscore/connector')
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnFactory.java41
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnection.java40
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnector.java16
3 files changed, 41 insertions, 56 deletions
diff --git a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnFactory.java b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnFactory.java
index be727a54b..db2a51afd 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnFactory.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnFactory.java
@@ -113,7 +113,7 @@ public class HttpConnFactory {
CMS.debug("leaving HttpConnFactory init.");
}
- private IHttpConnection createConnection(String op) throws EBaseException {
+ private IHttpConnection createConnection() throws EBaseException {
IHttpConnection retConn = null;
@@ -122,20 +122,11 @@ public class HttpConnFactory {
try {
ISocketFactory tFactory = new JssSSLSocketFactory(mNickname);
- if (op == null) {
- if (mTimeout == 0) {
- retConn = CMS.getHttpConnection(mDest, tFactory);
- } else {
- retConn = CMS.getHttpConnection(mDest, tFactory, mTimeout);
- }
+ if (mTimeout == 0) {
+ retConn = CMS.getHttpConnection(mDest, tFactory);
} else {
- if (mTimeout == 0) {
- retConn = CMS.getHttpConnection(mDest, tFactory, op);
- } else {
- retConn = CMS.getHttpConnection(mDest, tFactory, mTimeout, op);
- }
+ retConn = CMS.getHttpConnection(mDest, tFactory, mTimeout);
}
-
} catch (Exception e) {
CMS.debug("can't make new Htpp Connection");
@@ -150,7 +141,7 @@ public class HttpConnFactory {
/**
* makes the minumum number of connections
*/
- private void makeMinimum(String op) throws EBaseException {
+ private void makeMinimum() throws EBaseException {
CMS.debug("In HttpConnFactory.makeMinimum.");
int increment;
@@ -165,7 +156,7 @@ public class HttpConnFactory {
CMS.debug(
"increasing minimum connections by " + increment);
for (int i = increment - 1; i >= 0; i--) {
- mConns[i] = createConnection(op);
+ mConns[i] = createConnection();
}
mTotal += increment;
mNumConns += increment;
@@ -198,15 +189,6 @@ public class HttpConnFactory {
return getConn(true);
}
- /*
- * See getConn() above
- * @param op operation to determine the receiving servlet (multi-uri support)
- */
- public IHttpConnection getConn(String op)
- throws EBaseException {
- return getConn(true, op);
- }
-
/**
* Returns a Http connection - a clone of the master connection.
* All connections should be returned to the factory using returnConn()
@@ -231,20 +213,11 @@ public class HttpConnFactory {
*/
public synchronized IHttpConnection getConn(boolean waitForConn)
throws EBaseException {
- return getConn(waitForConn, null);
- }
-
- /*
- * See getConn() above
- * @param op operation to determine the receiving servlet (multi-uri support)
- */
- public synchronized IHttpConnection getConn(boolean waitForConn, String op)
- throws EBaseException {
boolean waited = false;
CMS.debug("In HttpConnFactory.getConn");
if (mNumConns == 0)
- makeMinimum(op);
+ makeMinimum();
if (mNumConns == 0) {
if (!waitForConn)
return null;
diff --git a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnection.java b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnection.java
index 30d70be1b..c179f4b3e 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnection.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnection.java
@@ -60,14 +60,16 @@ public class HttpConnection implements IHttpConnection {
return false;
}
- public HttpConnection(IRemoteAuthority dest, ISocketFactory factory) {
- this(dest, factory, null);
+ public void setRequestURI(String uri)
+ throws EBaseException {
+ mHttpreq.setURI(uri);
}
- /*
- * @param op operation to determine the receiving servlet (multi-uri support)
- */
- public HttpConnection(IRemoteAuthority dest, ISocketFactory factory, String op) {
+ public String getRequestURI() {
+ return mHttpreq.getURI();
+ }
+
+ public HttpConnection(IRemoteAuthority dest, ISocketFactory factory) {
mDest = dest;
mReqEncoder = new HttpRequestEncoder();
mHttpClient = new HttpClient(factory);
@@ -75,11 +77,10 @@ public class HttpConnection implements IHttpConnection {
Debug.trace("Created HttpClient");
try {
mHttpreq.setMethod("POST");
- if (op == null)
+ // in case of multi-uri, uri will be set right before send
+ // by calling setRequestURI(uri)
+ if (mDest.getURI() != null)
mHttpreq.setURI(mDest.getURI());
- else {
- mHttpreq.setURI(mDest.getURI(op));
- }
String contentType = dest.getContentType();
if (contentType != null) {
@@ -110,26 +111,20 @@ public class HttpConnection implements IHttpConnection {
}
}
- // Inserted by beomsuk
- public HttpConnection(IRemoteAuthority dest, ISocketFactory factory, int timeout) {
- this(dest, factory, timeout, null);
- }
-
/*
* @param op operation to determine the receiving servlet (multi-uri support)
*/
- public HttpConnection(IRemoteAuthority dest, ISocketFactory factory, int timeout, String op) {
+ public HttpConnection(IRemoteAuthority dest, ISocketFactory factory, int timeout) {
mDest = dest;
mReqEncoder = new HttpRequestEncoder();
mHttpClient = new HttpClient(factory);
CMS.debug("HttpConn:Created HttpConnection: factory " + factory + "client " + mHttpClient);
try {
mHttpreq.setMethod("POST");
- if (op == null)
+ // in case of multi-uri, uri will be set right before send
+ // by calling setRequestURI(op)
+ if (mDest.getURI() != null)
mHttpreq.setURI(mDest.getURI());
- else {
- mHttpreq.setURI(mDest.getURI(op));
- }
String contentType = dest.getContentType();
if (contentType != null) {
@@ -163,6 +158,7 @@ public class HttpConnection implements IHttpConnection {
CMS.debug("in HttpConnection.send " + this);
if (Debug.ON)
Debug.trace("encoding request ");
+
String content = null;
try {
@@ -222,6 +218,10 @@ public class HttpConnection implements IHttpConnection {
HttpResponse resp = null;
boolean reconnect = false;
+ if (getRequestURI() == null) {
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", "URI not set in HttpRequest"));
+ }
+
mHttpreq.setHeader("Content-Length",
Integer.toString(content.length()));
CMS.debug("HttpConnection.doSend: with String content length: " + Integer.toString(content.length()));
diff --git a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnector.java b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnector.java
index ff0ece148..2a51b2265 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnector.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/connector/HttpConnector.java
@@ -108,11 +108,23 @@ public class HttpConnector implements IConnector {
// cfu
public HttpResponse send(String op, String msg)
throws EBaseException {
- CMS.debug("HttpConnector: send(): cfu");
+ CMS.debug("HttpConnector: send(): begins");
HttpResponse resp = null;
IHttpConnection curConn = null;
+ String uri;
+
+ if (op != null) {
+ uri = mDest.getURI(op);
+ } else {
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", "HttpConnector.send(): op null"));
+ }
+ if (uri == null) {
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", "HttpConnector.send(): cannot find uri for op"));
+ }
+
try {
- curConn = mConnFactory.getConn(op);
+ curConn = mConnFactory.getConn();
+ curConn.setRequestURI(uri);
resp = curConn.send(msg);
} catch (EBaseException e) {
CMS.debug("HttpConnector: send():"+ e.toString());