From: Dave B. <bla...@us...> - 2012-08-01 18:23:19
|
Update of /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient/internal/wbem In directory vz-cvs-3.sog:/tmp/cvs-serv5808/src/org/sblim/cimclient/internal/wbem Modified Files: Tag: Experimental WBEMClientCIMXML.java Log Message: 3545797 - Support new error code of SFCB Index: WBEMClientCIMXML.java =================================================================== RCS file: /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient/internal/wbem/WBEMClientCIMXML.java,v retrieving revision 1.21.2.64 retrieving revision 1.21.2.65 diff -u -d -r1.21.2.64 -r1.21.2.65 --- WBEMClientCIMXML.java 11 May 2012 17:49:04 -0000 1.21.2.64 +++ WBEMClientCIMXML.java 1 Aug 2012 18:23:16 -0000 1.21.2.65 @@ -66,6 +66,7 @@ * 3522904 2012-05-02 blaschke-oss Add new API WBEMClientSBLIM.isActive() * 3521157 2012-05-10 blaschke-oss JSR48 1.0.0: PROP_ENABLE_*_LOGGING is Level, not 0/1 * 3525914 2012-05-11 blaschke-oss TCK: SetPropertyTest.testSetProperty failing + * 3545797 2012-07-19 blaschke-oss Support new error code of SFCB */ package org.sblim.cimclient.internal.wbem; @@ -1683,6 +1684,20 @@ this.iConfiguration.setCustomSocketFactory(pFactory); } + private String getHttpErrorString(int pStatusCode) { + switch (pStatusCode) { + case 401: + return "401 - UNAUTHORIZED"; + case 403: + return "403 - FORBIDDEN"; + case 405: + return "405 - METHOD NOT ALLOWED"; + case 407: + return "407 - PROXY AUTHENTICATION REQUIRED"; + } + return null; + } + private InputStreamReader transmitRequest(String pCimMethod, HttpHeader pHeader, Document pDocument) throws IOException, ProtocolException, WBEMException { @@ -1690,6 +1705,7 @@ logger.entry(); HttpUrlConnection connection = null; + int exceptionNum = WBEMException.CIM_ERR_FAILED; // retry HTTP MPOST only if failure is more than 24 hours old if (this.iMPostFailed) { @@ -1742,10 +1758,10 @@ } String cimError = headers.getField("CIMError"); + exceptionNum = WBEMException.CIM_ERR_FAILED; switch (resultCode) { - // 200 - case HttpURLConnection.HTTP_OK: + case HttpURLConnection.HTTP_OK: // 200 if (this.iConfiguration.isHttpContentLengthRetryEnabled()) { String contentLengthField = headers.getField("Content-length"); @@ -1754,8 +1770,8 @@ int lengthToCheck = this.iConfiguration.getHttpContentLengthThreshold(); if (contentLength < lengthToCheck) { - logger.trace(Level.FINE, "Content Length below :" + lengthToCheck - + " ...retrying !"); + logger.trace(Level.FINE, "Content Length below " + lengthToCheck + + ", retrying"); break; } } @@ -1771,13 +1787,7 @@ return new InputStreamReader(is, charset); - // 500 - case HttpURLConnection.HTTP_INTERNAL_ERROR: - logger.trace(Level.FINER, "Received HTTP Error 500 - HTTP_INTERNAL_ERROR"); - break; - - // 501 - case HttpURLConnection.HTTP_NOT_IMPLEMENTED: + case HttpURLConnection.HTTP_NOT_IMPLEMENTED: // 501 // TODO if there is an error with the default xml // encoder/decoder, load the correct version // The problem is that the CIMOM does not return the DTD @@ -1787,85 +1797,54 @@ if (cimProtocolVersion == null && cimError == null && useMPost) { logger .trace(Level.FINER, - "Received HTTP Error 501 - HTTP NOT IMPLEMENTED - falling back to HTTP POST"); + "Received HTTP Error 501 - NOT IMPLEMENTED with M-POST, falling back to POST"); this.iMPostFailTime = System.currentTimeMillis(); useMPost = false; this.iMPostFailed = true; ++retries; break; } - if (cimProtocolVersion == null || cimProtocolVersion.length() == 0) { - cimProtocolVersion = "1.0"; - } - logger.trace(Level.FINER, "Received HTTP Error 501 - HTTP NOT IMPLEMENTED" - + (cimError != null ? " - " + cimError : "")); - retries = 0; - break; - // 400 - case HttpURLConnection.HTTP_BAD_REQUEST: - if (cimError != null) { - logger.trace(Level.FINER, "Received HTTP Error 400 - BAD REQUEST - " - + cimError); - } else { - logger.trace(Level.FINER, "Received HTTP Error 400 - BAD REQUEST"); - } + logger.trace(Level.FINER, "Received HTTP Error 501 - NOT IMPLEMENTED" + + (cimError != null ? "(CIMError: \"" + cimError + "\")" : "") + + ", skipping retries"); retries = 0; break; - // 401 - case HttpURLConnection.HTTP_UNAUTHORIZED: - logger - .trace(Level.FINER, - "Received HTTP Error 401 - UNAUTHORIZED. Throwing WBEMAuthenticationException!"); - connection.disconnect(); - throw new WBEMException(WBEMException.CIM_ERR_ACCESS_DENIED, - "HTTP 401 - Unauthorized", null); - - // 403 - case HttpURLConnection.HTTP_FORBIDDEN: - logger.trace(Level.FINER, "Received HTTP Error 403 - FORBIDDEN."); + case HttpURLConnection.HTTP_BAD_REQUEST: // 400 + logger.trace(Level.FINER, "Received HTTP Error 400 - BAD REQUEST" + + getHttpErrorString(resultCode) + + (cimError != null ? " (CIMError: \"" + cimError + "\")" : "") + + ", skipping retries"); retries = 0; break; - // 407 - case HttpURLConnection.HTTP_PROXY_AUTH: - logger - .trace(Level.FINER, - "Received HTTP Error 407 - ERR PROXY AUTHENTICATION. Throwing CIMAuthenticationException!"); - connection.disconnect(); - throw new WBEMException(WBEMException.CIM_ERR_ACCESS_DENIED, - "HTTP 407 - Err Proxy Authentication"); - - // 405 - case HttpURLConnection.HTTP_BAD_METHOD: - logger.trace(Level.FINER, "Received HTTP Error 405 - BAD METHOD."); + case HttpURLConnection.HTTP_FORBIDDEN: // 403 + case HttpURLConnection.HTTP_BAD_METHOD: // 405 + logger.trace(Level.FINER, "Received HTTP Error " + + getHttpErrorString(resultCode) + ", skipping retries"); retries = 0; break; - // 505 Version Not Supported - case 505: - // 510 Not Extended - case 510: - logger.trace(Level.FINER, "Received HTTP Error " + resultCode - + " on M-POST. Retrying with POST."); - if (useMPost) { - this.iMPostFailTime = System.currentTimeMillis(); - useMPost = false; - this.iMPostFailed = true; - ++retries; - } + case HttpURLConnection.HTTP_UNAUTHORIZED: // 401 + case HttpURLConnection.HTTP_PROXY_AUTH: // 407 + logger.trace(Level.FINER, "Received HTTP Error " + + getHttpErrorString(resultCode) + ", skipping retries"); + exceptionNum = WBEMException.CIM_ERR_ACCESS_DENIED; + retries = 0; break; default: - logger - .trace(Level.FINER, - "No known HTTP error recognized. Retrying with POST."); if (useMPost) { + logger.trace(Level.FINER, "Received HTTP Error " + resultCode + + " with M-POST, falling back to POST"); this.iMPostFailTime = System.currentTimeMillis(); useMPost = false; this.iMPostFailed = true; ++retries; + } else { + logger.trace(Level.FINER, "Received HTTP Error " + resultCode + + ", retrying"); } } @@ -1899,15 +1878,59 @@ } catch (Exception e) { errorOP = null; } + logger.trace(Level.FINER, "Found PGErrorDetail field with value \"" + errorOP + "\""); + } + + // Look for SFCB error details, decode and include in exception + // if it exists + String errorSFCB = connection.getHeaderField("SFCBErrorDetail"); + if (errorSFCB != null) { + try { + errorSFCB = URLDecoder.decode(errorSFCB, "UTF-8"); + } catch (Exception e) { + errorSFCB = null; + } + logger.trace(Level.FINER, "Found SFCBErrorDetail field with value \"" + errorSFCB + + "\""); + } + + // Format of WBEMException message is: + // + // HTTP StatusCode - ReasonPhrase (CIMError: "ErrorString", OpenPegasus + // Error: "ErrorString", SFCB Error: "ErrorString") + // + // For example: + // HTTP 503 - Service Unavailable (SFCB Error: + // "Max Session Limit Exceeded") + StringBuffer errorMsg = new StringBuffer("HTTP "); + errorMsg.append(connection.getResponseCode()); + errorMsg.append(" - "); + errorMsg.append(connection.getResponseMessage()); + if (errorCIM != null || errorOP != null || errorSFCB != null) { + errorMsg.append(" ("); + if (errorCIM != null) { + errorMsg.append("CIMError: \""); + errorMsg.append(errorCIM); + errorMsg.append('"'); + } + if (errorOP != null) { + if (errorCIM != null) errorMsg.append(", "); + errorMsg.append("OpenPegasus Error: \""); + errorMsg.append(errorOP); + errorMsg.append('"'); + } + if (errorSFCB != null) { + if (errorCIM != null || errorOP != null) errorMsg.append(", "); + errorMsg.append("SFCB Error: \""); + errorMsg.append(errorSFCB); + errorMsg.append('"'); + } + errorMsg.append(')'); } - String errorMsg = "HTTP " + connection.getResponseCode() + " - " - + connection.getResponseMessage() - + (errorCIM != null ? (", CIMError: " + errorCIM) : "") - + (errorOP != null ? (", OpenPegasus Error Detail: \"" + errorOP + "\"") : ""); connection.disconnect(); - throw new WBEMException(WBEMException.CIM_ERR_FAILED, errorMsg); + throw new WBEMException(exceptionNum, errorMsg.toString()); } private HttpUrlConnection newConnection(String pCimMethod, HttpHeader pHeader, boolean pUseMPost) { |