@Test public void shouldSaveCallbackParamNameInContextWhenPresent() throws Exception { JsonpConfigBean config = new JsonpConfigBean(); config.setCallbackParamName("testParam"); QueryMap queryParams = new QueryMap(); queryParams.put("testParam", "testFunction"); ApiRequest request = new ApiRequest(); request.setQueryParams(queryParams); IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class); jsonpPolicy.doApply(request, sContext, config, chain); assertEquals("testFunction", sContext.getAttribute("callbackFunctionName", null)); verify(chain).doApply(request); }
@Override protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config, IPolicyChain<ApiRequest> chain) { String callbackParamName = config.getCallbackParamName(); String callbackFunctionName = request.getQueryParams().get(callbackParamName); request.getQueryParams().remove(callbackParamName); if (callbackFunctionName != null) { context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName); } super.doApply(request, context, config, chain); }
JsonpPolicy extends AbstractMappedPolicy<JsonpConfigBean> implements IDataPolicy { @Override protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config, IPolicyChain<ApiRequest> chain) { String callbackParamName = config.getCallbackParamName(); String callbackFunctionName = request.getQueryParams().get(callbackParamName); request.getQueryParams().remove(callbackParamName); if (callbackFunctionName != null) { context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName); } super.doApply(request, context, config, chain); } }
JsonpPolicy extends AbstractMappedPolicy<JsonpConfigBean> implements IDataPolicy { @Override protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config, IPolicyChain<ApiRequest> chain) { String callbackParamName = config.getCallbackParamName(); String callbackFunctionName = request.getQueryParams().get(callbackParamName); request.getQueryParams().remove(callbackParamName); if (callbackFunctionName != null) { context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName); } super.doApply(request, context, config, chain); }  }
JsonpPolicy extends AbstractMappedPolicy<JsonpConfigBean> implements IDataPolicy { @Override protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config, IPolicyChain<ApiRequest> chain) { String callbackParamName = config.getCallbackParamName(); String callbackFunctionName = request.getQueryParams().get(callbackParamName); request.getQueryParams().remove(callbackParamName); if (callbackFunctionName != null) { context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName); } super.doApply(request, context, config, chain); }  @Override IReadWriteStream<ApiRequest> getRequestDataHandler(ApiRequest request,
            IPolicyContext context, Object policyConfiguration); @Override IReadWriteStream<ApiResponse> getResponseDataHandler(final ApiResponse response,
            IPolicyContext context, Object policyConfiguration); }
JsonpPolicy extends AbstractMappedPolicy<JsonpConfigBean> implements IDataPolicy { @Override protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config, IPolicyChain<ApiRequest> chain) { String callbackParamName = config.getCallbackParamName(); String callbackFunctionName = request.getQueryParams().get(callbackParamName); request.getQueryParams().remove(callbackParamName); if (callbackFunctionName != null) { context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName); } super.doApply(request, context, config, chain); }  @Override IReadWriteStream<ApiRequest> getRequestDataHandler(ApiRequest request,
            IPolicyContext context, Object policyConfiguration); @Override IReadWriteStream<ApiResponse> getResponseDataHandler(final ApiResponse response,
            IPolicyContext context, Object policyConfiguration);  }