org.apache.axis2.context.OperationContext Java Examples
The following examples show how to use
org.apache.axis2.context.OperationContext.
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: 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 #2
Source File: APIGatewayAdminClientTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { environment = new Environment(); environment.setName(ENV_NAME); environment.setPassword(PASSWORD); environment.setUserName(USERNAME); environment.setServerURL(SERVER_URL); apiGatewayAdminStub = Mockito.mock(APIGatewayAdminStub.class); Options options = new Options(); ServiceContext serviceContext = new ServiceContext(); OperationContext operationContext = Mockito.mock(OperationContext.class); serviceContext.setProperty(HTTPConstants.COOKIE_STRING, ""); ServiceClient serviceClient = Mockito.mock(ServiceClient.class); AuthenticationAdminStub authAdminStub = Mockito.mock(AuthenticationAdminStub.class); Mockito.doReturn(true).when(authAdminStub).login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.when(authAdminStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(operationContext); Mockito.when(operationContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(apiGatewayAdminStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getOptions()).thenReturn(options); PowerMockito.whenNew(AuthenticationAdminStub.class) .withArguments(Mockito.any(ConfigurationContext.class), Mockito.anyString()).thenReturn(authAdminStub); }
Example #3
Source File: Soap.java From openxds with Apache License 2.0 | 6 votes |
public OMElement getInHeader() throws XdsInternalException { OperationContext oc = serviceClient.getLastOperationContext(); HashMap<String, MessageContext> ocs = oc.getMessageContexts(); MessageContext in = ocs.get("In"); if (in == null) return null; if (in.getEnvelope() == null) return null; if (in.getEnvelope().getHeader() == null) return null; return Util.deep_copy( in.getEnvelope().getHeader()); }
Example #4
Source File: JMSTestsUtils.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Create a empty message context. * * @return A context with empty message * @throws AxisFault on an error creating a context */ public static org.apache.synapse.MessageContext createMessageContext() throws AxisFault { Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration()); org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext(); axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration())); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MC.setServiceContext(svcCtx); axis2MC.setOperationContext(opCtx); org.apache.synapse.MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment); mc.setMessageID(UIDGenerator.generateURNString()); SOAPEnvelope env = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope(); OMNamespace namespace = OMAbstractFactory.getSOAP11Factory() .createOMNamespace("http://ws.apache.org/commons/ns/payload", "text"); env.declareNamespace(namespace); mc.setEnvelope(env); SOAPBody body = OMAbstractFactory.getSOAP11Factory().createSOAPBody(); OMElement element = OMAbstractFactory.getSOAP11Factory().createOMElement("TestElement", namespace); element.setText("This is a test!!"); body.addChild(element); mc.getEnvelope().addChild(body); return mc; }
Example #5
Source File: ProxyMessageReceiver.java From carbon-commons with Apache License 2.0 | 5 votes |
private SOAPEnvelope getResponseEnvelope(ServiceClient client) throws AxisFault { OperationContext operationContext = client.getLastOperationContext(); MessageContext messageContext = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); if (messageContext != null) { return messageContext.getEnvelope(); } return null; }
Example #6
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From micro-integrator 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 #7
Source File: RegistryCacheInvalidationClientTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws APIManagementException, RemoteException { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(ConfigurationContextFactory.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class); amConfig = Mockito.mock(APIManagerConfiguration.class); configFactory = Mockito.mock(ConfigurationContextFactory.class); configurationContext = Mockito.mock(ConfigurationContext.class); serviceClient = Mockito.mock(ServiceClient.class); authStub = Mockito.mock(AuthenticationAdminStub.class); cacheStub = Mockito.mock(RegistryCacheInvalidationServiceStub.class); OperationContext opContext = Mockito.mock(OperationContext.class); ServiceContext serviceContext = Mockito.mock(ServiceContext.class); Environment environment = new Environment(); environment.setServerURL(SERVER_URL); environment.setUserName(USERNAME); environment.setPassword(PASSWORD); validEnvironments = new HashMap<String, Environment>(); validEnvironments.put(ENV_NAME, environment); Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie"); Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext); Mockito.when(serviceClient.getOptions()).thenReturn(new Options()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService); Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig); Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null)) .thenReturn(configurationContext); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); }
Example #8
Source File: TierCacheInvalidationClientTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws APIManagementException, RemoteException { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(ConfigurationContextFactory.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class); amConfig = Mockito.mock(APIManagerConfiguration.class); configFactory = Mockito.mock(ConfigurationContextFactory.class); configurationContext = Mockito.mock(ConfigurationContext.class); serviceClient = Mockito.mock(ServiceClient.class); authStub = Mockito.mock(AuthenticationAdminStub.class); cacheStub = Mockito.mock(TierCacheServiceStub.class); OperationContext opContext = Mockito.mock(OperationContext.class); ServiceContext serviceContext = Mockito.mock(ServiceContext.class); Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie"); Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext); Mockito.when(serviceClient.getOptions()).thenReturn(new Options()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService); Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig); Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null)) .thenReturn(configurationContext); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); }
Example #9
Source File: Soap.java From openxds with Apache License 2.0 | 5 votes |
public OMElement getOutHeader() throws XdsInternalException { OperationContext oc = serviceClient.getLastOperationContext(); HashMap<String, MessageContext> ocs = oc.getMessageContexts(); MessageContext out = ocs.get("Out"); if (out == null) return null; return Util.deep_copy( out.getEnvelope().getHeader()); }
Example #10
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From product-ei with Apache License 2.0 | 5 votes |
@Test(groups = {"wso2.esb"}, description = "sending and accepting gzip compressed payload") public void sendingAndReceivingGzipCompressedRequestInAllPathTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendAndReceiveGZIPCompressedPayload")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, true); 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 #11
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From product-ei with Apache License 2.0 | 5 votes |
@Test(groups = {"wso2.esb"}, description = "having 'Accept-Encoding = gzip' within both in and out sequences") public void sendingAndReceivingGzipCompressedPayloadTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendingGZIPCompressedPayloadToClient")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, true); 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: ESBJAVA2262ContentEncodingGzipTestCase.java From product-ei with Apache License 2.0 | 5 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 #13
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 #14
Source File: WebSocketClientHandler.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = fac.getDefaultEnvelope(); axis2MsgCtx.setEnvelope(envelope); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #15
Source File: HL7MessageUtils.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { // Create super tenant message context org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #16
Source File: InboundHttpServerWorker.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Updates additional properties in Axis2 Message Context from Synapse Message Context * * @param synCtx Synapse Message Context * @return Updated Axis2 Message Context * @throws AxisFault */ private org.apache.synapse.MessageContext updateAxis2MessageContextForSynapse( org.apache.synapse.MessageContext synCtx) throws AxisFault { ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); ((Axis2MessageContext) synCtx).getAxis2MessageContext().setServiceContext(svcCtx); ((Axis2MessageContext) synCtx).getAxis2MessageContext().setOperationContext(opCtx); return synCtx; }
Example #17
Source File: InboundWebsocketSourceHandler.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); axis2MsgCtx.setProperty(TENANT_DOMAIN, SUPER_TENANT_DOMAIN_NAME); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = fac.getDefaultEnvelope(); axis2MsgCtx.setEnvelope(envelope); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #18
Source File: CacheMediatorTest.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Create Synapse Context. * * @return mc created message context. * @throws AxisFault when exception happens on message context creation. */ private MessageContext createSynapseMessageContext() throws AxisFault { org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext(); axis2MC.setConfigurationContext(this.configContext); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MC.setServiceContext(svcCtx); axis2MC.setOperationContext(opCtx); Axis2MessageContext mc = new Axis2MessageContext(axis2MC, this.synapseConfig, null); mc.setMessageID(UIDGenerator.generateURNString()); mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope()); mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody()); return mc; }
Example #19
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
@Test(groups = { "wso2.esb" }, description = "sending and accepting gzip compressed payload") public void sendingAndReceivingGzipCompressedRequestInAllPathTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendAndReceiveGZIPCompressedPayload")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, true); 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 #20
Source File: ESBJAVA2262ContentEncodingGzipTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
@Test(groups = { "wso2.esb" }, description = "having 'Accept-Encoding = gzip' within both in and out sequences") public void sendingAndReceivingGzipCompressedPayloadTest() throws Exception { ServiceClient client = getServiceClient(getProxyServiceURLHttp("sendingGZIPCompressedPayloadToClient")); client.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, true); 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 #21
Source File: XdsRaw.java From openxds with Apache License 2.0 | 4 votes |
public void setOperationContext(OperationContext opCtx) throws AxisFault { inMesasgeContext = opCtx.getMessageContext( WSDLConstants.MESSAGE_LABEL_IN_VALUE); }
Example #22
Source File: Xds.java From openxds with Apache License 2.0 | 4 votes |
public void setOperationContext(OperationContext opCtx) throws AxisFault { inMesasgeContext = opCtx.getMessageContext( WSDLConstants.MESSAGE_LABEL_IN_VALUE); }
Example #23
Source File: APIKeyValidationServiceTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Before public void Init() throws Exception { System.setProperty(CARBON_HOME, ""); privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); metricService = Mockito.mock(MetricService.class); org.wso2.carbon.metrics.manager.ServiceReferenceHolder serviceReferenceHolder1 = Mockito .mock(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class); Timer timer = Mockito.mock(Timer.class); Timer.Context timerContext = Mockito.mock(Timer.Context.class); MessageContext messageContext = Mockito.mock(MessageContext.class); OperationContext operationContext = Mockito.mock(OperationContext.class); MessageContext responseMessageContext = Mockito.mock(MessageContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.mockStatic(ApiMgtDAO.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class); PowerMockito.mockStatic(APIKeyMgtUtil.class); PowerMockito.mockStatic(MessageContext.class); PowerMockito.mockStatic(APIKeyMgtDataHolder.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); PowerMockito.when(privilegedCarbonContext.getUsername()).thenReturn(USER_NAME); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO); PowerMockito.when(MessageContext.getCurrentMessageContext()).thenReturn(messageContext); PowerMockito.when(APIKeyMgtDataHolder.isJwtGenerationEnabled()).thenReturn(true); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()) .thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_MANGER_VALIDATIONHANDLER_CLASS_NAME)) .thenReturn(API_KEY_MANGER_VALIDATION_HANDLER_CLASS_NAME); Mockito.when(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.getInstance()) .thenReturn(serviceReferenceHolder1); Mockito.when(serviceReferenceHolder1.getMetricService()).thenReturn(metricService); Mockito.when(timer.start()).thenReturn(timerContext); Mockito.when(metricService.timer(Mockito.anyString(), Mockito.any(org.wso2.carbon.metrics.manager.Level.class))) .thenReturn(timer); Mockito.when(messageContext.getOperationContext()).thenReturn(operationContext); Mockito.when(operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE)) .thenReturn(responseMessageContext); Map headers = new HashMap(); headers.put("activityID", "1s2f2g4g5"); Mockito.when(messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)) .thenReturn(headers); String cacheKey = APIUtil.getAccessTokenCacheKey(ACCESS_TOKEN, API_CONTEXT, API_VERSION, "/*", "GET", REQUIRED_AUTHENTICATION_LEVEL); org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO infoDTO = new org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO(); infoDTO.setApiPublisher(USER_NAME); infoDTO.setEndUserName(USER_NAME); PowerMockito.when(APIKeyMgtUtil.getFromKeyManagerCache(cacheKey)).thenReturn(infoDTO); }
Example #24
Source File: InOnlyMEPHandler.java From carbon-commons with Apache License 2.0 | 4 votes |
@Override // Handle IN_ONLY operations public void flowComplete(MessageContext msgContext) { if (msgContext.getEnvelope() == null) { return; } AxisService axisService = msgContext.getAxisService(); if (axisService == null || SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) || axisService.isClientSide()) { return; } try { // Process Request Counter OperationContext opContext = msgContext.getOperationContext(); if (opContext != null && opContext.isComplete()) { AxisOperation axisOp = opContext.getAxisOperation(); if (axisOp != null && axisOp.isControlOperation()) { return; } if (axisOp != null) { String mep = axisOp.getMessageExchangePattern(); if (mep != null && (mep.equals(WSDL2Constants.MEP_URI_IN_ONLY) || mep.equals(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY))) { // Increment operation counter final AxisOperation axisOperation = msgContext.getAxisOperation(); if (axisOperation != null) { Parameter operationParameter = axisOperation.getParameter(StatisticsConstants.IN_OPERATION_COUNTER); if (operationParameter != null) { ((AtomicInteger) operationParameter.getValue()).incrementAndGet(); } else { log.error(StatisticsConstants.IN_OPERATION_COUNTER + " has not been set for operation " + axisService.getName() + "." + axisOperation.getName()); return; } // Calculate response times try { ResponseTimeCalculator.calculateResponseTimes(msgContext); } catch (AxisFault axisFault) { log.error("Cannot compute response times", axisFault); } } // Increment global counter Parameter globalRequestCounter = msgContext.getParameter(StatisticsConstants.GLOBAL_REQUEST_COUNTER); ((AtomicInteger) globalRequestCounter.getValue()).incrementAndGet(); updateCurrentInvocationGlobalStatistics(msgContext); } } } } catch (Throwable e) { // Catching Throwable since exceptions here should not be propagated up log.error("Could not call InOnlyMEPHandler.flowComplete", e); } }