-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9fefa0
commit eeaf3fc
Showing
5 changed files
with
261 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
package org.rmq4j.common; | ||
|
||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
import org.unify4j.common.UniqueId4j; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
public class Rmq4j { | ||
|
||
/** | ||
* @return the HTTP servlet request, class {@link HttpServletRequest} | ||
*/ | ||
public static HttpServletRequest getRequest() { | ||
ServletRequestAttributes s = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); | ||
return s.getRequest(); | ||
} | ||
|
||
/** | ||
* Retrieves the current session ID from the request context. | ||
* <p> | ||
* This method accesses the current request attributes from the RequestContextHolder | ||
* and extracts the session ID associated with the current request. This is useful | ||
* for tracking the session of the user making the request, especially in web | ||
* applications where session management is crucial for user authentication and | ||
* maintaining user state across multiple requests. | ||
* | ||
* @return the session ID of the current request, or null if no session is associated with the current request context | ||
*/ | ||
public static String getCurrentSessionId() { | ||
try { | ||
ServletRequestAttributes s = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); | ||
return s.getSessionId(); | ||
} catch (IllegalStateException e) { | ||
return String.valueOf(UniqueId4j.getUniqueId19()); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the session ID from the given HttpServletRequest. | ||
* <p> | ||
* This method gets the current HttpSession associated with the request, | ||
* and then extracts the session ID from it. If there is no current session | ||
* and create is false, it returns null. | ||
* | ||
* @param request the HttpServletRequest from which to retrieve the session ID | ||
* @return the session ID, or null if there is no current session | ||
*/ | ||
public static String getSessionId(HttpServletRequest request) { | ||
if (request == null) { | ||
return String.valueOf(UniqueId4j.getUniqueId19()); | ||
} | ||
HttpSession session = request.getSession(false); // Pass false to prevent creating a new session if one does not exist | ||
return (session != null) ? session.getId() : null; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
plugin/src/main/groovy/org/rmq4j/service/Rmq4jWrapCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.rmq4j.service; | ||
|
||
import org.unify4j.model.response.WrapResponse; | ||
|
||
/** | ||
* This interface defines a callback mechanism for handling RabbitMQ-related operations. | ||
* Implementations of this interface should provide logic for handling exceptions | ||
* that may occur during these operations and return a wrapped response. | ||
*/ | ||
public interface Rmq4jWrapCallback { | ||
|
||
/** | ||
* This method is called when an exception occurs during a RabbitMQ operation. | ||
* Implementations should handle the exception and return an appropriate | ||
* WrapResponse object. | ||
* | ||
* @param response a WrapResponse object containing the result or error information, class {@link WrapResponse} | ||
*/ | ||
void onCallback(WrapResponse<?> response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters