@Override public ResponseDescriptorDTO getResponseDescriptor(final String key) { return routingService.getResponseDescriptorDTOAndRemove(key); }
/** * This method execute the given command. The given command is any operation which works with the stubDescriptors collection. * * @param command is the given operation * @throws ClassNotFoundException if problem happens */ public void performModification(final StubDescriptorModificationCommand command) throws ClassNotFoundException { synchronized (guard) { stubDescriptors = command.modify(stubDescriptors); } getOperationMode(); } }
/** * Redirects requests by changing their URI. * @param request the request that is redirected */ public void reroute(final WilmaHttpRequest request) { if (routingService.redirectRequestToStub(request)) { try { request.setUri(getURI()); } catch (URISyntaxException e) { logger.error(e.getMessage()); } } }
/** * Modify the ordering in the stubDescriptors of routingService. * @param direction is the way where we want to move the selected stub descriptor * @param groupName is the groupname of selected stub descriptor * @param request is only needed for {@link UrlAccessLogMessageAssembler} * @throws ClassNotFoundException in case of problem */ public void doChange(final int direction, final String groupName, final HttpServletRequest request) throws ClassNotFoundException { routingService.performModification(new ChangeOrderCommand(direction, groupName, request, urlAccessLogMessageAssembler)); } }
@Test public void testRerouteShouldNotSetNewUri() throws URISyntaxException { //GIVEN uri = new URI("http://127.0.0.1:" + internalPort + "/stub/"); given(routingService.redirectRequestToStub(request)).willReturn(false); //WHEN underTest.reroute(request); //TEST verify(request, times(0)).setUri(uri); }
@Test public void testRerouteWhenUriNotCorrectShouldLogError() throws URISyntaxException { //GIVEN doThrow(new URISyntaxException("", "")).when(underTest).getURI(); given(routingService.redirectRequestToStub(request)).willReturn(true); //WHEN underTest.reroute(request); //THEN verify(logger).error(Mockito.anyString()); }
@Override public void process(final WilmaHttpEntity entity) throws ApplicationException { WilmaHttpRequest request = (WilmaHttpRequest) entity; /** * If this method was called then localhost blocking is turned on, * so we only need to check if the request targets localhost in order to determine if it needs to be rerouted. */ boolean requestNeedsRerouting = localhostRequestChecker.checkIfRequestTargetsLocalhost(request); if (requestNeedsRerouting) { localhostRequestRouter.reroute(request); request.setRerouted(true); } }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info(urlAccessLogMessageAssembler.assembleMessage(req, "Set Operation Mode: STUB.")); proxyModeToggle.switchProxyModeOff(); routingService.setOperationMode(OperationMode.STUB); }
/** * This method deletes all old files from the cache folder. * Then it gets all stub descriptors from {@link RoutingService} and call {@link StubConfigurationSaver} to save all of the descriptors. * @throws JsonTransformationException is thrown when a document can not be written */ public void saveStubConfigurations() throws JsonTransformationException { cleaner.cleanCache(); Map<String, StubDescriptor> descriptors = routingService.getStubDescriptors(); saver.saveAllStubConfigurations(descriptors); }
@Override public void process(final WilmaHttpEntity entity) throws ApplicationException { WilmaHttpRequest request = (WilmaHttpRequest) entity; boolean bypassWilma = isByPassPresentInHeader(request.getHeaders()); if (!bypassWilma && !request.isRerouted()) { router.reroute(request); } }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); boolean proxyModeOn = proxyModeToggle.isProxyModeOn(); boolean stubModeOn = routingService.isStubModeOn(); boolean wilmaModeOn = !proxyModeOn && !stubModeOn; out.write("{\"proxyMode\":" + proxyModeOn + ",\"stubMode\":" + stubModeOn + ",\"wilmaMode\":" + wilmaModeOn + "}"); out.flush(); out.close(); }
/** * Call the changeStubConfigurationStatus what set the enabled/disabled status at the selected stub descriptor and then applies the change at {@link RoutingService}. * @param nextStatus is the new status of the selected stub descriptor * @param groupName is the groupname of selected stub descriptor * @param request is only needed for {@link UrlAccessLogMessageAssembler} * @throws ClassNotFoundException in case of problem */ public void changeStatus(final boolean nextStatus, final String groupName, final HttpServletRequest request) throws ClassNotFoundException { routingService.performModification(new ChangeStatusCommand(nextStatus, groupName, request, urlAccessLogMessageAssembler)); } }
@Test public void testRerouteShouldSetNewUri() throws URISyntaxException { //GIVEN uri = new URI("http://127.0.0.1:" + internalPort + "/stub/"); given(routingService.redirectRequestToStub(request)).willReturn(true); //WHEN underTest.reroute(request); //TEST verify(request).setUri(uri); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info(urlAccessLogMessageAssembler.assembleMessage(req, "Set Operation Mode: PROXY.")); proxyModeToggle.switchProxyModeOn(); routingService.setOperationMode(OperationMode.PROXY); }
@Test public void testGetResponseDescriptorShouldCallRoutingService() { //GIVEN String key = "key"; //WHEN underTest.getResponseDescriptor(key); //THEN verify(routingService).getResponseDescriptorDTOAndRemove(key); }
private void createStubDescriptor(final String jsonFilePath) { try { StubDescriptorModificationCommand command; command = newStubDescriptorJsonCommandFactory.create(jsonFilePath, stubConfigurationJsonBuilder, sequenceDescriptorHolder); routingService.performModification(command); } catch (ClassNotFoundException | FileNotFoundException e) { throw new DescriptorCannotBeParsedException("One of the stub descriptor files cannot be found!", e); } }
@Test public void testRerouteShouldReturnRequestWithNewUri() throws URISyntaxException { //GIVEN uri = new URI("http://127.0.0.1:" + internalPort + "/stub/"); given(request.getUri()).willReturn(uri); given(routingService.redirectRequestToStub(request)).willReturn(true); //WHEN underTest.reroute(request); //TEST verify(request).setUri(uri); }
@Test public void testDoGetShouldSetOpModeAndToggleInRoutingService() throws ServletException, IOException { //GIVEN OperationMode operationMode = OperationMode.STUB; //WHEN underTest.doGet(request, response); //THEN verify(routingService).setOperationMode(operationMode); }
@Test public void testDoGetShouldSetOpModeAndToggleInRoutingService() throws ServletException, IOException { //GIVEN OperationMode operationMode = OperationMode.PROXY; //WHEN underTest.doGet(request, response); //THEN verify(routingService).setOperationMode(operationMode); }
@Test public void testDoGetShouldSetOpModeAndToggleInRoutingService() throws ServletException, IOException { //GIVEN OperationMode operationMode = OperationMode.WILMA; //WHEN underTest.doGet(request, response); //THEN verify(routingService).setOperationMode(operationMode); }