org.wso2.msf4j.Request.getSession()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中org.wso2.msf4j.Request.getSession方法的一些代码示例,展示了Request.getSession的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getSession方法的具体详情如下:
包路径:org.wso2.msf4j.Request
类名称:Request
方法名:getSession

Request.getSession介绍

[英]Returns the current session associated with this request, or if the request does not have a session, creates one.
[中]返回与此请求关联的当前会话,如果请求没有会话,则创建一个会话。

代码示例

代码示例来源:origin: io.ballerina.messaging/broker-amqp

  1. @GET
  2. @Produces({ "application/json" })
  3. @ApiOperation(value = "Get all connections", notes = "Retrieves all connections to the broker", response = ConnectionMetadata.class, responseContainer = "List", authorizations = {
  4. @Authorization(value = "basicAuth")
  5. }, tags={ })
  6. @ApiResponses(value = {
  7. @ApiResponse(code = 200, message = "List of active Connections", response = ConnectionMetadata.class, responseContainer = "List"),
  8. @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
  9. @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
  10. @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class)
  11. })
  12. public Response getAllConnections(@Context Request request) {
  13. return connectionsApiDelegate.getAllConnections((Subject) request.getSession().getAttribute(BrokerAuthConstants.AUTHENTICATION_ID));
  14. }

代码示例来源:origin: io.ballerina.messaging/broker-amqp

  1. @DELETE
  2. @Path("/{id}")
  3. @Produces({ "application/json" })
  4. @ApiOperation(value = "Close the specified connection.", notes = "Disconnects the specified amqp connection if the connection exists in the broker", response = CloseConnectionResponse.class, authorizations = {
  5. @Authorization(value = "basicAuth")
  6. }, tags={ })
  7. @ApiResponses(value = {
  8. @ApiResponse(code = 202, message = "Connection removal request submitted.", response = CloseConnectionResponse.class),
  9. @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
  10. @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
  11. @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class),
  12. @ApiResponse(code = 404, message = "The specified resource was not found", response = Error.class)
  13. })
  14. public Response closeConnection(@Context Request request, @PathParam("id") @ApiParam("Identifier of the connection") Integer id,
  15. @DefaultValue("false") @QueryParam("force") @ApiParam("If set to true the broker will close the underlying connection without trying to communicate with the connected AMQP client."
  16. + " If set to false, the broker will send a connection close frame to the client and the connection will be closed when the "
  17. + "client responds back with a connection close ok.") Boolean force,
  18. @DefaultValue("false") @QueryParam("used") @ApiParam("If set to false, the broker will close the connection only if there are no AMQP channels registered on it. If set to true,"
  19. + " the connection will be closed regardless of the registered number of channels.") Boolean used) {
  20. return connectionsApiDelegate.closeConnection(id, force, used, (Subject) request.getSession().getAttribute
  21. (BrokerAuthConstants.AUTHENTICATION_ID));
  22. }

代码示例来源:origin: io.ballerina.messaging/broker-amqp

  1. @GET
  2. @Path("/{connectionId}/channels")
  3. @Produces({ "application/json" })
  4. @ApiOperation(value = "Get all channels for connection", notes = "Retrieves all AMQP channels established on an AMQP connection", response = ChannelMetadata.class, responseContainer = "List", authorizations = {
  5. @Authorization(value = "basicAuth")
  6. }, tags={ })
  7. @ApiResponses(value = {
  8. @ApiResponse(code = 200, message = "List of channels created on the connection", response = ChannelMetadata.class, responseContainer = "List"),
  9. @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
  10. @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
  11. @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class),
  12. @ApiResponse(code = 404, message = "The specified resource was not found", response = Error.class)
  13. })
  14. public Response getAllChannelsForConnection(@Context Request request,
  15. @PathParam("connectionId")
  16. @ApiParam("Identifier of the connection") Integer connectionId) {
  17. return connectionsApiDelegate.getAllChannels(connectionId, (Subject) request.getSession().getAttribute(BrokerAuthConstants.AUTHENTICATION_ID));
  18. }
  19. }

代码示例来源:origin: io.ballerina.messaging/broker-amqp

  1. @DELETE
  2. @Path("/{connectionId}/channels/{channelId}")
  3. @Produces({ "application/json" })
  4. @ApiOperation(value = "Force disconnect the specified channel.", notes = "Disconnects the specified amqp channel if an active channel exists in the broker", response = RequestAcceptedResponse.class, authorizations = {
  5. @Authorization(value = "basicAuth")
  6. }, tags={ })
  7. @ApiResponses(value = {
  8. @ApiResponse(code = 202, message = "Channel removal request submitted.", response = RequestAcceptedResponse.class),
  9. @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
  10. @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
  11. @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class),
  12. @ApiResponse(code = 404, message = "The specified resource was not found", response = Error.class)
  13. })
  14. public Response closeChannel(@Context Request request,
  15. @PathParam("connectionId") @ApiParam("Identifier of the connection") Integer connectionId,
  16. @PathParam("channelId") @ApiParam("Identifier of the channel") Integer channelId,
  17. @DefaultValue("false") @QueryParam("used") @ApiParam("If set to false, the broker will close the channel only if there are no AMQP consumers for it. If set to true, "
  18. + "the channel will be closed regardless of the number of active consumers.") Boolean used) {
  19. return connectionsApiDelegate.closeChannel(connectionId, channelId,
  20. used,
  21. (Subject) request.getSession().getAttribute(BrokerAuthConstants.AUTHENTICATION_ID));
  22. }

代码示例来源:origin: io.ballerina.messaging/broker-rest-runner

  1. @Override
  2. public boolean interceptRequest(Request request, Response response) throws Exception {
  3. String authHeader = request.getHeader(javax.ws.rs.core.HttpHeaders.AUTHORIZATION);
  4. if (authHeader != null) {
  5. String authType = authHeader.substring(0, AUTH_TYPE_BASIC_LENGTH);
  6. String authEncoded = authHeader.substring(AUTH_TYPE_BASIC_LENGTH).trim();
  7. if (AUTH_TYPE_BASIC.equals(authType) && !authEncoded.isEmpty()) {
  8. // Read the Basic auth header and extract the username and password from base 64 encoded string.
  9. byte[] decodedByte = Base64.getDecoder().decode(authEncoded.getBytes(StandardCharsets.UTF_8));
  10. char[] array = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(decodedByte)).array();
  11. int separatorIndex = findIndex(array, ':');
  12. String userName = new String(Arrays.copyOfRange(array, 0, separatorIndex));
  13. char[] password = Arrays.copyOfRange(array, separatorIndex + 1, array.length);
  14. if (authenticate(userName, password)) {
  15. Subject subject = new Subject();
  16. subject.getPrincipals().add(new UsernamePrincipal(userName));
  17. request.getSession().setAttribute(BrokerAuthConstants.AUTHENTICATION_ID, subject);
  18. return true;
  19. }
  20. }
  21. }
  22. response.setStatus(javax.ws.rs.core.Response.Status.UNAUTHORIZED.getStatusCode());
  23. response.setHeader(javax.ws.rs.core.HttpHeaders.WWW_AUTHENTICATE, AUTH_TYPE_BASIC);
  24. return false;
  25. }

代码示例来源:origin: wso2/msf4j

  1. @GET
  2. public int count(@Context Request request) {
  3. Session session = request.getSession();
  4. // Create & set the counter in the session
  5. Object attribute = session.getAttribute(COUNTER);
  6. if (attribute == null) {
  7. attribute = 0;
  8. }
  9. int counter = (int) attribute;
  10. counter++;
  11. session.setAttribute(COUNTER, counter);
  12. // Invalidate this session if the count goes beyond 100
  13. if (counter >= 100) {
  14. session.invalidate();
  15. }
  16. return counter;
  17. }
  18. }

代码示例来源:origin: wso2/msf4j

  1. /**
  2. * Operation which returns content in the response and sets a value in the session.
  3. */
  4. @GET
  5. @Path("/set-session2/{value}")
  6. public String setObjectInSession2(@Context Request request, @PathParam("value") String value) {
  7. request.getSession().setAttribute(SAMPLE_STRING, value);
  8. return value;
  9. }

代码示例来源:origin: wso2/msf4j

  1. @GET
  2. @Path("/expire-session")
  3. public void expireSession(@Context Request request) {
  4. request.getSession().invalidate();
  5. }

代码示例来源:origin: wso2/msf4j

  1. /**
  2. * Operation with no content in the response and sets a value in the session.
  3. */
  4. @GET
  5. @Path("/set-session/{value}")
  6. public void setObjectInSession(@Context Request request, @PathParam("value") String value) {
  7. request.getSession().setAttribute(SAMPLE_STRING, value);
  8. }

代码示例来源:origin: wso2/msf4j

  1. /**
  2. * Operation which retrieves value set in the session in the {@link #setObjectInSession} &
  3. * {@link #setObjectInSession2} methods.
  4. */
  5. @GET
  6. @Path("/get-session")
  7. public String getObjectFromSession(@Context Request request) {
  8. return (String) request.getSession().getAttribute(SAMPLE_STRING);
  9. }

相关文章