public HttpResponse doEndpoint(StaplerRequest request) throws IOException { final ParameterList requestp = new ParameterList(request.getParameterMap()); final String mode = requestp.getParameterValue("openid.mode"); final String realm = getRealm(requestp); if ("associate".equals(mode)) { // --- process an association extend --- return new MessageResponse(manager.associationResponse(requestp)); } else if ("checkid_setup".equals(mode) || "checkid_immediate".equals(mode)) { // No need to redirect to a page with an HTML form // Skip the authentication step String identity = getUserIdentity(); Message rsp = manager.authResponse(requestp, identity, identity, true, false); try { respondToExtensions(requestp, rsp); } catch (MessageException ex) { throw new OperationFailure(ex.getMessage()); } // Need to sign after because SReg extension parameters are signed by openid4java if (rsp instanceof AuthSuccess) { try { manager.sign((AuthSuccess) rsp); } catch (ServerException e) { throw new OperationFailure(e.getMessage()); } catch (AssociationException e) { throw new OperationFailure(e.getMessage()); } } return new HttpRedirect(rsp.getDestinationUrl(true)); } else if ("check_authentication".equals(mode)) { return new MessageResponse(manager.verify(requestp)); } else { throw new OperationFailure("Unknown extend: " + mode); } }
private int postReadProcess() throws IOException { int prot_bytes_read = 0; int data_bytes_read = 0; if (!reading_length_mode && !destroyed) { // reading payload data mode // ensure-restore proper buffer limits payload_buffer.limit(SS, message_length); length_buffer.limit(SS, 4); int read = payload_buffer.position(SS) - pre_read_start_position; if (payload_buffer.position(SS) > 0) { // need to have read the message id first byte if (BTMessageFactory.getMessageType(payload_buffer) == Message.TYPE_DATA_PAYLOAD) { data_bytes_read += read; } else { prot_bytes_read += read; } } if (!payload_buffer.hasRemaining(SS) && !is_paused) { // full message received! payload_buffer.position(SS, 0); DirectByteBuffer ref_buff = payload_buffer; payload_buffer = null; if (reading_handshake_message) { // decode handshake reading_handshake_message = false; DirectByteBuffer handshake_data = DirectByteBufferPool.getBuffer(DirectByteBuffer.AL_MSG_BT_HAND, 68); handshake_data.putInt(SS, HANDSHAKE_FAKE_LENGTH); handshake_data.put(SS, ref_buff); handshake_data.flip(SS); ref_buff.returnToPool(); try { Message handshake = MessageManager.getSingleton() .createMessage(BTMessage.ID_BT_HANDSHAKE_BYTES, handshake_data, (byte) 1); messages_last_read.add(handshake); } catch (MessageException me) { handshake_data.returnToPool(); throw new IOException("BT message decode failed: " + me.getMessage()); } // we need to auto-pause decoding until we're told to start again externally, // as we don't want to accidentally read the next message on the stream if it's an // AZ-format handshake pauseDecoding(); } else { // decode normal message try { messages_last_read.add(createMessage(ref_buff)); } catch (Throwable e) { ref_buff.returnToPoolIfNotFree(); // maintain unexpected errors as such so they get logged later if (e instanceof RuntimeException) { throw ((RuntimeException) e); } throw new IOException("BT message decode failed: " + e.getMessage()); } } reading_length_mode = true; // see if we've already read the next message's length percent_complete = -1; // reset receive percentage } else { // only partial received so far percent_complete = (payload_buffer.position(SS) * 100) / message_length; // compute receive percentage } } if (reading_length_mode && !destroyed) { length_buffer.limit(SS, 4); // ensure proper buffer limit prot_bytes_read += (pre_read_start_buffer == 1) ? length_buffer.position(SS) - pre_read_start_position : length_buffer.position(SS); if (!length_buffer.hasRemaining(SS)) { // done reading the length reading_length_mode = false; length_buffer.position(SS, 0); message_length = length_buffer.getInt(SS); length_buffer.position(SS, 0); // reset it for next length read if (message_length == HANDSHAKE_FAKE_LENGTH) { // handshake message reading_handshake_message = true; message_length = 64; // restore 'real' length payload_buffer = DirectByteBufferPool.getBuffer(DirectByteBuffer.AL_MSG_BT_HAND, message_length); } else if (message_length == 0) { // keep-alive message reading_length_mode = true; last_received_was_keepalive = true; try { Message keep_alive = MessageManager.getSingleton() .createMessage(BTMessage.ID_BT_KEEP_ALIVE_BYTES, null, (byte) 1); messages_last_read.add(keep_alive); } catch (MessageException me) { throw new IOException("BT message decode failed: " + me.getMessage()); } } else if (message_length < MIN_MESSAGE_LENGTH || message_length > MAX_MESSAGE_LENGTH) { throw new IOException( "Invalid message length given for BT message decode: " + message_length); } else { // normal message payload_buffer = DirectByteBufferPool.getBuffer(DirectByteBuffer.AL_MSG_BT_PAYLOAD, message_length); } } } protocol_bytes_last_read += prot_bytes_read; data_bytes_last_read += data_bytes_read; return prot_bytes_read + data_bytes_read; }
/** * If NF_HEADER_LOCATION_PROP exists in context use as the header to forward to Gateway. If * IS_ASYNCHRONOUS_PROP exists in context then use that value to call either processAsync or * processSync * * @param input MessageObject containing the value to be processed * * @param mpcontext The context * @return Optional NVPair containing a Destination name and a MessageObject, or null if none. * @exception ProcessingException Thrown if processing fails. * @exception MessageException Thrown if bad message. */ public NVPair[] process(MessageProcessorContext ctx, MessageObject input) throws MessageException, ProcessingException { if (input == null) return null; try { serverName = getRequiredProperty(ctx, input, SERVER_NAME_PROP); } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } if (StringUtils.hasValue(headerLocation)) { try { header = getString(headerLocation, ctx, input); } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } if (StringUtils.hasValue(isAsyncLocation)) { try { isAsync = StringUtils.getBoolean(getString(isAsyncLocation, ctx, input)); } catch (FrameworkException fe) { throw new ProcessingException( "Value of " + IS_ASYNCHRONOUS_LOCATION_PROP + " is not TRUE/FALSE. " + fe.getMessage()); } } // Fetch the alternate Orb Address, if one exists at the specified context location if (StringUtils.hasValue(orbAgentAddrLocation)) { try { if (exists(orbAgentAddrLocation, ctx, input, true)) { orbAgentAddr = getString(orbAgentAddrLocation, ctx, input); if (Debug.isLevelEnabled(Debug.MSG_STATUS)) Debug.log( Debug.MSG_STATUS, "RequestHandlerClient:: alternate orb exists with orb agent address [" + orbAgentAddr + "]"); } } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } // Fetch the alternate Orb Port, if one exists at the specified context location if (StringUtils.hasValue(orbAgentPortLocation)) { try { if (exists(orbAgentPortLocation, ctx, input, true)) { orbAgentPort = getString(orbAgentPortLocation, ctx, input); if (Debug.isLevelEnabled(Debug.MSG_STATUS)) Debug.log( Debug.MSG_STATUS, "RequestHandlerClient:: alternate orb exists with orb agent port [" + orbAgentPort + "]"); } } catch (MessageException me) { throw new ProcessingException(me.getMessage()); } } String msg = input.getString(); try { try { return (formatNVPair(makeClientCall(serverName, false, header, msg))); } catch (Exception e) { // Any of the following exceptions indicate that the failure might be due to // a CORBA communications issue (stale object reference) that should be retried. if ((e instanceof org.omg.CORBA.OBJECT_NOT_EXIST) || (e instanceof org.omg.CORBA.TRANSIENT) || (e instanceof org.omg.CORBA.COMM_FAILURE) || (e instanceof org.omg.CORBA.INV_OBJREF) || (e instanceof org.omg.CORBA.UNKNOWN)) { Debug.warning( "Caught the following CORBA communication error, so retrying:\n" + e.toString() + "\n" + Debug.getStackTrace(e)); return (formatNVPair(makeClientCall(serverName, true, header, msg))); } else { // It's not a communication exception indicating that retry is recommended, // so just re-throw it. throw e; } } } catch (Exception e) { if (e instanceof InvalidDataException) { Debug.error(e.toString() + "\n" + Debug.getStackTrace(e)); throw new MessageException(((InvalidDataException) e).errorMessage); } else { Debug.error(e.toString() + "\n" + Debug.getStackTrace(e)); throw new ProcessingException(e.toString()); } } }