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

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

本文整理了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

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

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

@DELETE
@Path("/{id}")
@Produces({ "application/json" })
@ApiOperation(value = "Close the specified connection.", notes = "Disconnects the specified amqp connection if the connection exists in the broker", response = CloseConnectionResponse.class, authorizations = {
    @Authorization(value = "basicAuth")
}, tags={  })
@ApiResponses(value = {
    @ApiResponse(code = 202, message = "Connection removal request submitted.", response = CloseConnectionResponse.class),
    @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
    @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
    @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class),
    @ApiResponse(code = 404, message = "The specified resource was not found", response = Error.class)
})
public Response closeConnection(@Context Request request, @PathParam("id") @ApiParam("Identifier of the connection") Integer id,
                @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."
                                           + " If set to false, the broker will send a connection close frame to the client and the connection will be closed when the "
                                           + "client responds back with a connection close ok.")  Boolean force,
                @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,"
                                            + " the connection will be closed regardless of the registered number of channels.")  Boolean used) {
  return connectionsApiDelegate.closeConnection(id, force, used, (Subject) request.getSession().getAttribute
      (BrokerAuthConstants.AUTHENTICATION_ID));
}

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

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

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

@DELETE
@Path("/{connectionId}/channels/{channelId}")
@Produces({ "application/json" })
@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 = {
    @Authorization(value = "basicAuth")
}, tags={  })
@ApiResponses(value = {
    @ApiResponse(code = 202, message = "Channel removal request submitted.", response = RequestAcceptedResponse.class),
    @ApiResponse(code = 400, message = "Bad request. Invalid request or validation error.", response = Error.class),
    @ApiResponse(code = 401, message = "Authentication information is missing or invalid", response = Error.class),
    @ApiResponse(code = 403, message = "User is not autherized to perform operation", response = Error.class),
    @ApiResponse(code = 404, message = "The specified resource was not found", response = Error.class)
})
public Response closeChannel(@Context Request request,
               @PathParam("connectionId") @ApiParam("Identifier of the connection") Integer connectionId,
               @PathParam("channelId") @ApiParam("Identifier of the channel") Integer channelId,
               @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, "
                                           + "the channel will be closed regardless of the number of active consumers.")  Boolean used) {
  return connectionsApiDelegate.closeChannel(connectionId, channelId,
                        used,
                        (Subject) request.getSession().getAttribute(BrokerAuthConstants.AUTHENTICATION_ID));
}

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

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

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

@GET
  public int count(@Context Request request) {
    Session session = request.getSession();

    // Create & set the counter in the session
    Object attribute = session.getAttribute(COUNTER);
    if (attribute == null) {
      attribute = 0;
    }
    int counter = (int) attribute;
    counter++;
    session.setAttribute(COUNTER, counter);

    // Invalidate this session if the count goes beyond 100
    if (counter >= 100) {
      session.invalidate();
    }
    return counter;
  }
}

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

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

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

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

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

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

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

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

相关文章