Java Code Examples for org.apache.axis2.context.MessageContext#getProperty()
The following examples show how to use
org.apache.axis2.context.MessageContext#getProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoadbalanceFailoverClient.java From micro-integrator with Apache License 2.0 | 6 votes |
protected String extractSessionID(MessageContext axis2MessageContext) { Object o = axis2MessageContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (o != null && o instanceof Map) { Map headerMap = (Map) o; String cookie = (String) headerMap.get(SET_COOKIE); if (cookie == null) { cookie = (String) headerMap.get(COOKIE); } else { cookie = cookie.split(";")[0]; } return cookie; } return null; }
Example 2
Source File: WSS4JUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Returns the UsernameTokenPrincipal from the security results. * * @param mc The message context of the message * @return the UsernameTokenPrincipal from the security results as an * <code>org.apache.ws.security.WSUsernameTokenPrincipal</code>. * If a wsse:UsernameToken was not present in the wsse:Security header then * <code>null</code> will be returned. * @throws Exception If there are no security results. * @see org.apache.ws.security.WSUsernameTokenPrincipal */ public static WSUsernameTokenPrincipal getUsernameTokenPrincipal( MessageContext mc) throws Exception { Vector results; if ((results = (Vector) mc.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) { throw new Exception("No security results available in the message context"); } else { for (int i = 0; i < results.size(); i++) { WSHandlerResult rResult = (WSHandlerResult) results.get(i); Vector wsSecEngineResults = rResult.getResults(); for (int j = 0; j < wsSecEngineResults.size(); j++) { WSSecurityEngineResult wser = (WSSecurityEngineResult) wsSecEngineResults.get(j); Integer actInt = (Integer) wser .get(WSSecurityEngineResult.TAG_ACTION); if (actInt.intValue() == WSConstants.UT) { return (WSUsernameTokenPrincipal) wser .get(WSSecurityEngineResult.TAG_PRINCIPAL); } } } } return null; }
Example 3
Source File: LoadbalanceFailoverClient.java From product-ei with Apache License 2.0 | 6 votes |
protected String extractSessionID(MessageContext axis2MessageContext) { Object o = axis2MessageContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (o != null && o instanceof Map) { Map headerMap = (Map) o; String cookie = (String) headerMap.get(SET_COOKIE); if (cookie == null) { cookie = (String) headerMap.get(COOKIE); } else { cookie = cookie.split(";")[0]; } return cookie; } return null; }
Example 4
Source File: TracerUtils.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Get a prettified XML string from the SOAPEnvelope * * @param env The SOAPEnvelope to be prettified * @param msgContext The MessageContext * @return prettified XML string from the SOAPEnvelope */ public static String getPrettyString(OMElement env, MessageContext msgContext) { String xml; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); env.serialize(baos); InputStream xmlIn = new ByteArrayInputStream(baos.toByteArray()); String encoding = (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING); XMLPrettyPrinter xmlPrettyPrinter = new XMLPrettyPrinter(xmlIn, encoding); xml = xmlPrettyPrinter.xmlFormat(); } catch (Throwable e) { String error = "Error occurred while pretty printing message. " + e.getMessage(); log.error(error, e); xml = error; } return xml; }
Example 5
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = { "wso2.esb" }, description = "having 'Content-Encoding = gzip' within both in and out sequences and accepting gzip response") public void gzipCompressionBothInAndOutSequencesTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendAndReceiveGZIPCompressedPayload")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_ACCEPT_GZIP, true); OMElement response = client.sendReceive(Utils.getStockQuoteRequest("GZIP")); OperationContext operationContext = client.getLastOperationContext(); MessageContext inMessageContext = operationContext.getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN); CommonsTransportHeaders transportHeaders = (CommonsTransportHeaders) inMessageContext .getProperty(TRANSPORT_HEADERS); Assert.assertTrue(transportHeaders.containsKey(CONTENT_ENCODING), "Response Message not encoded"); Assert.assertEquals(transportHeaders.get(CONTENT_ENCODING), "gzip", "Response Message not gzip encoded"); Assert.assertTrue(response.toString().contains("GZIP")); Assert.assertTrue(response.toString().contains("GZIP Company")); }
Example 6
Source File: LoadBalanceSessionFullClient.java From product-ei with Apache License 2.0 | 6 votes |
protected String extractSessionID(MessageContext axis2MessageContext) { Object o = axis2MessageContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (o instanceof Map) { Map headerMap = (Map) o; String cookie = (String) headerMap.get(SET_COOKIE); if (cookie == null) { cookie = (String) headerMap.get(COOKIE); } else { cookie = cookie.split(";")[0]; } return cookie; } return null; }
Example 7
Source File: JMSUtils.java From micro-integrator with Apache License 2.0 | 5 votes |
private static boolean isHyphenReplaceMode(MessageContext msgContext) { if (msgContext == null) { return false; } String hyphenSupport = (String) msgContext.getProperty(JMSConstants.PARAM_JMS_HYPHEN_MODE); if (hyphenSupport != null && hyphenSupport.equals(JMSConstants.HYPHEN_MODE_REPLACE)) { return true; } return false; }
Example 8
Source File: MultipleCredentialsUserProxy.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Gets logged in user of the server * * @return user name */ private String getLoggedInUser() { MessageContext context = MessageContext.getCurrentMessageContext(); if (context != null) { HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); if (request != null) { HttpSession httpSession = request.getSession(false); return (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); } } return null; }
Example 9
Source File: GatewayUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private static void setTracingId(TracingSpan tracingSpan, MessageContext axis2MessageContext) { Map headersMap = (Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headersMap.containsKey(APIConstants.ACTIVITY_ID)) { Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_ACTIVITY_ID, (String) headersMap.get(APIConstants.ACTIVITY_ID)); } else { Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_ACTIVITY_ID, axis2MessageContext.getMessageID()); } }
Example 10
Source File: MultipleCredentialsUserProxy.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Gets logged in user of the server * * @return user name */ private String getLoggedInUser() { MessageContext context = MessageContext.getCurrentMessageContext(); if (context != null) { HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); if (request != null) { HttpSession httpSession = request.getSession(false); return (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); } } return null; }
Example 11
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From product-ei with Apache License 2.0 | 5 votes |
@Test(groups = {"wso2.esb"}, description = "having 'Content-Encoding = gzip' within outsequence") public void gzipCompressionInsideOutSequenceTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendingGZIPCompressedPayloadToClient")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_ACCEPT_GZIP, true); OMElement response = client.sendReceive(Utils.getStockQuoteRequest("GZIP")); OperationContext operationContext = client.getLastOperationContext(); MessageContext inMessageContext = operationContext.getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN); CommonsTransportHeaders transportHeaders = (CommonsTransportHeaders) inMessageContext.getProperty(TRANSPORT_HEADERS); Assert.assertTrue(transportHeaders.containsKey(CONTENT_ENCODING), "Response Message not encoded"); Assert.assertEquals(transportHeaders.get(CONTENT_ENCODING), "gzip", "Response Message not gzip encoded"); Assert.assertTrue(response.toString().contains("GZIP")); Assert.assertTrue(response.toString().contains("GZIP Company")); }
Example 12
Source File: OpenIDProviderService.java From carbon-identity with Apache License 2.0 | 5 votes |
public OpenIDRememberMeDTO handleRememberMe(String openID, String ipaddress) throws Exception { String userName = OpenIDUtil.getUserName(openID); String hmac = null; OpenIDRememberMeDTO dto = new OpenIDRememberMeDTO(); dto.setAuthenticated(false); String cookie = null; OpenIDRememberMeDO rememberMe = new OpenIDRememberMeDO(); rememberMe.setOpenID(openID); rememberMe.setUserName(userName); OpenIDRememberMeTokenManager tokenManager = new OpenIDRememberMeTokenManager(); if (ipaddress != null) { cookie = IdentityUtil.generateUUID(); hmac = IdentityUtil.getHMAC(ipaddress, cookie); rememberMe.setToken(hmac); tokenManager.updateToken(rememberMe); dto.setNewCookieValue(cookie); dto.setAuthenticated(true); MessageContext msgContext = MessageContext.getCurrentMessageContext(); if (msgContext != null) { HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { httpSession.setAttribute(OpenIDServerConstants.OPENID_LOGGEDIN_USER, userName); } } } return dto; }
Example 13
Source File: GatewayUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Can be used to extract Query Params from {@code org.apache.axis2.context.MessageContext}. * * @param messageContext The Axis2 MessageContext * @return A Map with Name Value pairs. */ public static Map<String, String> getQueryParams(MessageContext messageContext) { String queryString = (String) messageContext.getProperty(NhttpConstants.REST_URL_POSTFIX); if (!StringUtils.isEmpty(queryString)) { if (queryString.indexOf("?") > -1) { queryString = queryString.substring(queryString.indexOf("?") + 1); } String[] queryParams = queryString.split("&"); Map<String, String> queryParamsMap = new HashMap<String, String>(); String[] queryParamArray; String queryParamName, queryParamValue = ""; for (String queryParam : queryParams) { queryParamArray = queryParam.split("="); if (queryParamArray.length == 2) { queryParamName = queryParamArray[0]; queryParamValue = queryParamArray[1]; } else { queryParamName = queryParamArray[0]; } queryParamsMap.put(queryParamName, queryParamValue); } return queryParamsMap; } return null; }
Example 14
Source File: LoadBalanceSessionFullClient.java From micro-integrator with Apache License 2.0 | 5 votes |
protected String getSetCookieHeader(MessageContext axis2MessageContext) { Object o = axis2MessageContext.getProperty(MessageContext.TRANSPORT_HEADERS); if (o instanceof Map) { Map headerMap = (Map) o; return (String) headerMap.get(SET_COOKIE); } return null; }
Example 15
Source File: ThrottleConditionEvaluator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private boolean isHeaderPresent(MessageContext messageContext, ConditionDTO condition) { TreeMap<String, String> transportHeaderMap = (TreeMap<String, String>) messageContext .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (transportHeaderMap != null) { String value = transportHeaderMap.get(condition.getConditionName()); if (value == null) { return false; } Pattern pattern = Pattern.compile(condition.getConditionValue()); Matcher matcher = pattern.matcher(value); return matcher.find(); } return false; }
Example 16
Source File: OpenIDProviderService.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Authenticates with the remember me token given in previous authentication. * * @param openID * @param password * @param ipaddress * @param cookie * @return * @throws Exception */ public OpenIDRememberMeDTO authenticateWithOpenIDRememberMe(String openID, String password, String ipaddress, String cookie) throws Exception { String userName = OpenIDUtil.getUserName(openID); boolean isAutheticated = false; String hmac = null; OpenIDRememberMeDTO dto = new OpenIDRememberMeDTO(); dto.setAuthenticated(false); if (password != null && password.trim().length() > 0) { isAutheticated = authenticateWithOpenID(openID, password); if (!isAutheticated) { return dto; } } else { if (cookie == null || "null".equals(cookie) || ipaddress == null) { return dto; } } OpenIDRememberMeDO rememberMe = new OpenIDRememberMeDO(); rememberMe.setOpenID(openID); rememberMe.setUserName(userName); OpenIDRememberMeTokenManager tokenManager = new OpenIDRememberMeTokenManager(); String token = null; if (ipaddress != null) { if (cookie != null && !"null".equals(cookie)) { hmac = IdentityUtil.getHMAC(ipaddress, cookie); token = tokenManager.getToken(rememberMe); // if the authentication failed and no valid rememberMe cookie found, then failed. if (!isAutheticated && (token == null || !token.equals(hmac))) { return dto; } } else if (!isAutheticated) { return dto; } cookie = IdentityUtil.generateUUID(); hmac = IdentityUtil.getHMAC(ipaddress, cookie); rememberMe.setToken(hmac); tokenManager.updateToken(rememberMe); dto.setNewCookieValue(cookie); dto.setAuthenticated(true); MessageContext msgContext = MessageContext.getCurrentMessageContext(); if (msgContext != null) { HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { httpSession.setAttribute(OpenIDServerConstants.OPENID_LOGGEDIN_USER, userName); } } return dto; } return dto; }
Example 17
Source File: IheHTTPServer.java From openxds with Apache License 2.0 | 4 votes |
public SessionContext getSessionContext(MessageContext messageContext) { String sessionKey = (String) messageContext.getProperty(HTTPConstants.COOKIE_STRING); return this.sessionManager.getSessionContext(sessionKey); }
Example 18
Source File: OpenIDProviderService.java From carbon-identity with Apache License 2.0 | 4 votes |
public OpenIDRememberMeDTO authenticateWithRememberMeCookie(String openID, String ipaddress, String cookie) throws Exception { String userName = OpenIDUtil.getUserName(openID); boolean isAutheticated = false; String hmac = null; OpenIDRememberMeDTO dto = new OpenIDRememberMeDTO(); dto.setAuthenticated(false); if (cookie == null || "null".equals(cookie) || ipaddress == null) { return dto; } OpenIDRememberMeDO rememberMe = new OpenIDRememberMeDO(); rememberMe.setOpenID(openID); rememberMe.setUserName(userName); OpenIDRememberMeTokenManager tokenManager = new OpenIDRememberMeTokenManager(); String token = null; hmac = IdentityUtil.getHMAC(ipaddress, cookie); token = tokenManager.getToken(rememberMe); // if the authentication failed and no valid rememberMe cookie found, then failed. if (!isAutheticated && (token == null || !token.equals(hmac))) { return dto; } cookie = IdentityUtil.generateUUID(); hmac = IdentityUtil.getHMAC(ipaddress, cookie); rememberMe.setToken(hmac); tokenManager.updateToken(rememberMe); dto.setNewCookieValue(cookie); dto.setAuthenticated(true); MessageContext msgContext = MessageContext.getCurrentMessageContext(); if (msgContext != null) { HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { httpSession.setAttribute(OpenIDServerConstants.OPENID_LOGGEDIN_USER, userName); } } return dto; }
Example 19
Source File: OauthAuthenticator.java From carbon-device-mgt with Apache License 2.0 | 2 votes |
/** * Retrieve HTTP Servlet Request form thr Message Context. * * @param messageContext Containing the Servlet Request for backend authentication. * @return HTTPServletRequest. */ private HttpServletRequest getHttpRequest(MessageContext messageContext) { return (HttpServletRequest) messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); }
Example 20
Source File: AbstractAuthorizationProvider.java From micro-integrator with Apache License 2.0 | 2 votes |
/** * Default implementation to get user name from message context. * * @param msgContext * @return username. */ public String getUsername(MessageContext msgContext) { String userName = (String) msgContext.getProperty( DBConstants.MSG_CONTEXT_USERNAME_PROPERTY); return userName; }