use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.
the class PLLRequestServlet method doPost.
/*
* doPost() Accepts POST requests, reads Inpt Stream, forwards the
* RequestSet XML Flushes the ResponseSet XML to OutputStream @param
* HttpServletRequest Reference to HttpServletRequest object @param
* HttpServletResponse Reference to HttpServletResponse object
*
* @see javax.servlet.http.HttpServlet
*/
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException {
PLLAuditor auditor = newAuditor(req);
try {
int length = req.getContentLength();
if (length == -1) {
PLLServer.pllDebug.warning(PLLBundle.getString("unknownLength"));
throw servletException("unknownLength");
}
if (length > maxContentLength) {
PLLServer.pllDebug.error("content length exceeded configured max request size - " + length);
throw servletException("largeContentLength");
}
byte[] reqData = new byte[length];
InputStream in = req.getInputStream();
int rlength = 0;
int offset = 0;
while (rlength != length) {
int r = in.read(reqData, offset, length - offset);
if (r == -1) {
throw servletException("readRequestError");
}
rlength += r;
offset += r;
}
String xml = new String(reqData, 0, length, "UTF-8");
RequestSet set = RequestSet.parseXML(xml);
String svcid = set.getServiceID();
if (!AUTH_SVC_ID.equalsIgnoreCase(svcid)) {
if (PLLServer.pllDebug.messageEnabled()) {
PLLServer.pllDebug.message("\nReceived RequestSet XML :\n" + xml);
}
}
String responseXML = handleRequest(auditor, set, req, res);
res.setContentLength(responseXML.getBytes("UTF-8").length);
OutputStreamWriter out = new OutputStreamWriter(res.getOutputStream(), "UTF-8");
try {
out.write(responseXML);
out.flush();
} catch (IOException e) {
throw e;
} finally {
try {
out.close();
} catch (Exception ex) {
}
}
} catch (IOException | ServletException | RuntimeException e) {
auditor.auditAccessFailure(e.getMessage());
throw e;
}
}
use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.
the class ResourceResultCache method sendPLLRequest.
/**
* Return a PolicyService object based on the XML document received
* from remote Policy Server. This is in response to a request that we
* send to the Policy server.
* @param policyServiceUrl The URL of the Policy Service
* @param preq The SessionRequest XML document
* @return PolicyService
* @exception SendRequestException is thrown if there was an error in
* sending the XML document or PolicyException if there are any parsing
* errors.
*/
public static PolicyService sendPLLRequest(URL policyServiceUrl, PolicyRequest preq) throws SendRequestException, PolicyException {
String lbcookie = null;
try {
lbcookie = getLBCookie(preq);
} catch (Exception e) {
throw new SendRequestException(e);
}
PolicyService policyService = new PolicyService();
policyService.setMethodID(PolicyService.POLICY_REQUEST_ID);
policyService.setPolicyRequest(preq);
String xmlString = policyService.toXMLString();
Request request = new Request(xmlString);
RequestSet requestSet = new RequestSet(PolicyService.POLICY_SERVICE);
requestSet.addRequest(request);
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.sendPLLRequest:" + "sending PLL request to URL=" + policyServiceUrl + ":\nPLL message=" + xmlString);
}
Vector responses = PLLClient.send(policyServiceUrl, lbcookie, requestSet);
Response response = (Response) responses.elementAt(0);
PolicyService ps = PolicyService.parseXML(response.getContent());
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.sendPLLRequest:" + "result=" + ps.toXMLString());
}
return ps;
}
use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.
the class SessionPLLSender method sendPLLRequest.
/**
* Returns a Session Response object based on the XML document received from
* remote Session Server. This is in response to a request that we send to
* the session server.
*
* @param svcurl The URL of the Session Service.
* @param sreq The Session Request XML document.
* @return a Vector of responses from the remote server
* @exception com.iplanet.dpro.session.SessionException if there was an error in sending the XML
* document or if the response has multiple components.
*/
public SessionResponse sendPLLRequest(URL svcurl, SessionRequest sreq) throws SessionException {
try {
String cookies = sessionCookies.getCookieName() + "=" + sreq.getSessionID();
if (!SystemProperties.isServerMode()) {
SessionID sessionID = new SessionID(sreq.getSessionID());
cookies = cookies + ";" + sessionCookies.getLBCookie(sessionID);
}
final Request req = new Request(sreq.toXMLString());
final RequestSet set = new RequestSet(SESSION_SERVICE);
set.addRequest(req);
final Vector responses = PLLClient.send(svcurl, cookies, set);
if (responses.size() != 1) {
throw new SessionException(SessionBundle.rbName, "unexpectedResponse", null);
}
final Response res = (Response) responses.elementAt(0);
return SessionResponse.parseXML(res.getContent());
} catch (Exception e) {
throw new SessionException(e);
}
}
use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.
the class WebtopNaming method getNamingTable.
private static Hashtable getNamingTable(URL nameurl) throws Exception {
Hashtable nametbl = null;
NamingRequest nrequest = new NamingRequest(NamingRequest.reqVersion);
Request request = new Request(nrequest.toXMLString());
RequestSet set = new RequestSet(NAMING_SERVICE);
set.addRequest(request);
Vector responses = null;
try {
responses = PLLClient.send(nameurl, set);
if (responses.size() != 1) {
throw new Exception(NamingBundle.getString("unexpectedResponse"));
}
Response res = (Response) responses.elementAt(0);
NamingResponse nres = NamingResponse.parseXML(res.getContent());
if (nres.getException() != null) {
throw new Exception(nres.getException());
}
nametbl = nres.getNamingTable();
} catch (SendRequestException sre) {
debug.error("Naming service connection failed for " + nameurl, sre);
} catch (Exception e) {
debug.error("getNamingTable: ", e);
}
return nametbl;
}
use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.
the class AuthXMLHandler method processRequest.
/* process the request */
private Response processRequest(PLLAuditor auditor, Request req, HttpServletRequest servletReq, HttpServletResponse servletRes) {
// this call is to create a http session so that the JSESSIONID cookie
// is created. The appserver(8.1) load balancer plugin relies on the
// JSESSIONID cookie to set its JROUTE sticky cookie.
debug.message("=======================Entering processRequest");
servletReq.getSession(true);
String content = req.getContent();
AuthXMLResponse authResponse = null;
// Check for mis-routed requests
String cookieURL = null;
int index = content.indexOf(AuthXMLTags.AUTH_ID_HANDLE);
if (index != -1) {
// Check for mis-routed requests, get server URL for
// AuthIdentifier
int beginIndex = content.indexOf('"', index);
int endIndex = content.indexOf('"', beginIndex + 1);
String authIdentifier = content.substring(beginIndex + 1, endIndex);
if (debug.messageEnabled()) {
debug.message("authIdentifier = " + authIdentifier + "beginIndex = " + beginIndex + "endIndex =" + endIndex);
}
if (!authIdentifier.equals("0")) {
try {
SessionID sessionID = new SessionID(authIdentifier);
URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
StringBuilder srtBuff = new StringBuilder(100);
srtBuff.append(sessionServerURL.getProtocol()).append("://").append(sessionServerURL.getHost()).append(":").append(Integer.toString(sessionServerURL.getPort())).append(serviceURI);
cookieURL = srtBuff.toString();
} catch (Exception exp) {
debug.error("Error in getting URL from session", exp);
cookieURL = null;
}
}
}
if ((cookieURL != null) && (cookieURL.trim().length() != 0) && !(AuthUtils.isLocalServer(cookieURL, serviceURI))) {
// Routing to the correct server, the looks like a mis-routed
// requested.
HashMap cookieTable = new HashMap();
Map headers = new HashMap();
Enumeration headerNames = servletReq.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
List headerValues = new ArrayList();
Enumeration enum1 = servletReq.getHeaders(headerName);
while (enum1.hasMoreElements()) {
headerValues.add(enum1.nextElement());
}
headers.put(headerName, headerValues);
}
if (debug.messageEnabled()) {
debug.message("Headers: " + headers);
}
PLLClient.parseCookies(headers, cookieTable);
if (debug.messageEnabled()) {
debug.message("Cookies: " + cookieTable);
}
RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
set.addRequest(req);
try {
Vector responses = PLLClient.send(new URL(cookieURL), set, cookieTable);
if (!responses.isEmpty()) {
auditor.auditAccessAttempt();
// Just record result as success here to avoid parsing response
auditor.auditAccessSuccess();
debug.message("=====================Returning redirected");
return ((Response) responses.elementAt(0));
}
} catch (Exception e) {
debug.error("Error in misrouted ", e);
// Attempt to contact server failed
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
setErrorCode(authResponse, e);
auditor.auditAccessAttempt();
auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
return new Response(authResponse.toXMLString());
}
}
// Either local request or new request, handle it locally
try {
AuthXMLRequest sreq = AuthXMLRequest.parseXML(content, servletReq);
sreq.setHttpServletRequest(servletReq);
authResponse = processAuthXMLRequest(content, auditor, sreq, servletReq, servletRes);
} catch (AuthException e) {
debug.error("Got Auth Exception", e);
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
authResponse.setErrorCode(e.getErrorCode());
} catch (Exception ex) {
debug.error("Error while processing xml request", ex);
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
setErrorCode(authResponse, ex);
}
debug.message("=======================Returning");
if (authResponse.isException) {
auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
} else {
auditor.auditAccessSuccess();
}
return new Response(authResponse.toXMLString());
}
Aggregations