Search in sources :

Example 21 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class RdfDatasetConverter method writeInternal.

@Override
protected void writeInternal(Dataset dataset, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    MediaType contentType = httpOutputMessage.getHeaders().getContentType();
    Lang rdfLanguage = mimeTypeToJenaLanguage(contentType, Lang.TRIG);
    WonEtagHelper.setMediaTypeForEtagHeaderIfPresent(contentType, httpOutputMessage.getHeaders());
    RDFDataMgr.write(httpOutputMessage.getBody(), dataset, rdfLanguage);
    // append content type to ETAG header to avoid confusing different representations of the same resource
    httpOutputMessage.getBody().flush();
    stopWatch.stop();
    logger.debug("writing dataset took " + stopWatch.getLastTaskTimeMillis() + " millls");
}
Also used : MediaType(org.springframework.http.MediaType) StopWatch(org.springframework.util.StopWatch)

Example 22 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method readConnectionEvents.

@RequestMapping(value = "${uri.path.data.connection}/{identifier}/events", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readConnectionEvents(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String beforeId, @RequestParam(value = "resumeafter", required = false) String afterId, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "deep", required = false, defaultValue = "false") boolean deep) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    logger.debug("readConnection() called");
    Dataset rdfDataset;
    HttpHeaders headers = new HttpHeaders();
    Integer preferedSize = getPreferredSize(request);
    URI connectionUri = URI.create(this.connectionResourceURIPrefix + "/" + identifier);
    URI connectionEventsURI = URI.create(connectionUri.toString() + "/" + "events");
    WonMessageType msgType = getMessageType(type);
    try {
        String passableMap = getPassableQueryMap("type", type);
        if (preferedSize == null) {
            // client doesn't not support paging - return all members; does not support type
            // filtering for clients that do
            // not support paging
            rdfDataset = linkedDataService.listConnectionEventURIs(connectionUri, deep);
        } else if (page == null && beforeId == null && afterId == null) {
            // client supports paging but didn't specify which page to return - return page
            // with latest events
            NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIs(connectionUri, 1, preferedSize, msgType, // TODO: does not
            deep);
            // respect
            // preferredSize if
            // deep is used
            rdfDataset = resource.getContent();
            addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
        } else if (page != null) {
            // a page having particular page number is requested
            NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIs(connectionUri, page, preferedSize, msgType, deep);
            rdfDataset = resource.getContent();
            addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, page, passableMap);
        } else if (beforeId != null) {
            // a page that precedes the item identified by the beforeId is requested
            URI referenceEvent = uriService.createEventURIForId(beforeId);
            NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsBefore(connectionUri, referenceEvent, preferedSize, msgType, deep);
            rdfDataset = resource.getContent();
            addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
        } else {
            // a page that follows the item identified by the afterId is requested
            URI referenceEvent = uriService.createEventURIForId(afterId);
            NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsAfter(connectionUri, referenceEvent, preferedSize, msgType, deep);
            rdfDataset = resource.getContent();
            addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
        }
    } catch (NoSuchConnectionException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    // TODO: events list information does change over time, unless the connection is
    // closed and cannot be reopened.
    // The events list of immutable connection information should never expire, the
    // mutable should
    addLocationHeaderIfNecessary(headers, URI.create(request.getRequestURI()), URI.create(this.connectionResourceURIPrefix));
    addMutableResourceHeaders(headers);
    addCORSHeader(headers);
    stopWatch.stop();
    logger.debug("readConnectionEvents took " + stopWatch.getLastTaskTimeMillis() + " millis");
    return new ResponseEntity<>(rdfDataset, headers, HttpStatus.OK);
}
Also used : NeedInformationService(won.protocol.service.NeedInformationService) HttpHeaders(org.springframework.http.HttpHeaders) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) WonMessageType(won.protocol.message.WonMessageType) URI(java.net.URI) StopWatch(org.springframework.util.StopWatch) ResponseEntity(org.springframework.http.ResponseEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with StopWatch

use of org.springframework.util.StopWatch in project gocd by gocd.

the class UserSqlMapDaoCachingTest method enabledUserCacheShouldBeThreadSafe.

@Test(timeout = 60000)
public void enabledUserCacheShouldBeThreadSafe() throws Exception {
    ThreadSafetyChecker threadSafetyChecker = new ThreadSafetyChecker(10000);
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("enabledUserCount");
            stopWatch.start("enabledUserCount");
            userDao.enabledUserCount();
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("deleteAll");
            stopWatch.start("deleteAll");
            userDao.deleteAll();
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("saveOrUpdate");
            stopWatch.start("saveOrUpdate");
            userDao.saveOrUpdate(new User("some-random-user " + runIndex));
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("enableUsers");
            stopWatch.start("enableUsers");
            userDao.enableUsers(Arrays.asList("some-random-user " + runIndex));
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.run(250);
}
Also used : User(com.thoughtworks.go.domain.User) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 24 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class DefaultWoNAccessDecisionVoter method vote.

@Override
public int vote(final Authentication authentication, final Object object, final Collection collection) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (!(authentication instanceof PreAuthenticatedAuthenticationToken))
        return ACCESS_ABSTAIN;
    Object principal = authentication.getPrincipal();
    if (!(principal instanceof WebIdUserDetails))
        return ACCESS_ABSTAIN;
    WebIdUserDetails userDetails = (WebIdUserDetails) principal;
    if (!(object instanceof FilterInvocation))
        return ACCESS_ABSTAIN;
    String webId = userDetails.getUsername();
    String resource = ((FilterInvocation) object).getRequest().getRequestURL().toString();
    if (authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).filter(r -> "ROLE_WEBID".equals(r)).findAny().isPresent()) {
        // perform our hard coded access control checks
        List<String> webIDs = new ArrayList<>(1);
        webIDs.add(webId);
        if (defaultAccessControlRules.isAccessPermitted(resource, webIDs)) {
            stopWatch.stop();
            logger.debug("access control check took " + stopWatch.getLastTaskTimeMillis() + " millis");
            return ACCESS_GRANTED;
        }
        return ACCESS_DENIED;
    }
    return ACCESS_DENIED;
}
Also used : ArrayList(java.util.ArrayList) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) FilterInvocation(org.springframework.security.web.FilterInvocation) StopWatch(org.springframework.util.StopWatch)

Example 25 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class WebIdUserDetailsService method loadUserDetails.

@Override
public UserDetails loadUserDetails(final PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    String principal = (String) token.getPrincipal();
    Certificate certificate = (Certificate) token.getCredentials();
    logger.debug("Adding userDetails for '" + principal + "'");
    URI webID = null;
    try {
        webID = new URI(principal);
    } catch (URISyntaxException e) {
        throw new BadCredentialsException("Principal of X.509 Certificate must be a WebId URI. Actual value: '" + principal + "'");
    }
    // at this point, we know that a client certificate was presented. Grant this role:
    List<GrantedAuthority> authorities = new ArrayList<>(3);
    authorities.add(new SimpleGrantedAuthority("ROLE_CLIENT_CERTIFICATE_PRESENTED"));
    logger.debug("verifying webId '" + principal + "'");
    try {
        if (webIDVerificationAgent.verify(certificate.getPublicKey(), webID)) {
            authorities.add(new SimpleGrantedAuthority("ROLE_WEBID"));
            logger.debug("webId '" + principal + "' successfully verified - ROLE_WEBID granted");
        } else {
            logger.debug("could not verify webId '" + principal + "'. ROLE_WEBID not granted");
        }
    } catch (Exception e) {
        logger.debug("could not verify webId '" + principal + "' because of an error during verification. ROLE_WEBID " + "not granted. Cause is logged", e);
    }
    stopWatch.stop();
    logger.debug("webID check took " + stopWatch.getLastTaskTimeMillis() + " millis");
    return new WebIdUserDetails(webID, authorities);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) URI(java.net.URI) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) URISyntaxException(java.net.URISyntaxException) StopWatch(org.springframework.util.StopWatch) Certificate(java.security.cert.Certificate)

Aggregations

StopWatch (org.springframework.util.StopWatch)106 Test (org.junit.Test)45 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)10 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Ignore (org.junit.Ignore)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4