@Override public URI getUri() { try { return new URI(clientRequest.getUri()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public URI getUri() { try { return new URI(clientRequest.getUri()); } catch (Exception e) { throw new RuntimeException(e); } }
protected HttpURLConnection createConnection(ClientRequest request) throws Exception { String uri = request.getUri(); String httpMethod = request.getHttpMethod(); HttpURLConnection connection = (HttpURLConnection) new URL(uri).openConnection(); connection.setRequestMethod(httpMethod); return connection; }
protected HttpURLConnection createConnection(ClientRequest request) throws Exception { String uri = request.getUri(); String httpMethod = request.getHttpMethod(); HttpURLConnection connection = (HttpURLConnection) new URL(uri).openConnection(); connection.setRequestMethod(httpMethod); return connection; }
@Override public boolean matchesSafely(final ClientRequest clientRequest) { try { return clientRequest.getUri().equals(href); } catch (final Exception e) { return false; } } };
protected void cacheIfPossible(final ClientRequest request, final ClientResponse<?> response) throws Exception { if (response.getStatus() == 200) { final String uri = request.getUri(); final String etag = (String) response.getHeaders().getFirst(HttpHeaders.ETAG); final String contentType = (String) response.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); if (etag != null && !etag.trim().isEmpty()) { cache.put(uri, etag, contentType); } } } }
public RestEasyClientInProcRequest(ClientRequest clientRequest) { this.clientRequest = clientRequest; try { headers.put("Host", UrlHelper.getRequestHost(new URI(clientRequest.getUri()))); } catch (Exception e) { throw new RuntimeException(e); } if (clientRequest.getBodyContentType() != null) { headers.put("Content-type", clientRequest.getBodyContentType().toString()); } headers.putAll(asMap(clientRequest.getHeaders())); }
public RestEasyClientInProcRequest(ClientRequest clientRequest) { this.clientRequest = clientRequest; try { headers.put("Host", UrlHelper.getRequestHost(new URI(clientRequest.getUri()))); } catch (Exception e) { throw new RuntimeException(e); } if (clientRequest.getBodyContentType() != null) { headers.put("Content-type", clientRequest.getBodyContentType().toString()); } headers.putAll(asMap(clientRequest.getHeaders())); }
protected String getETag(final ClientRequest request) throws Exception { final String uri = request.getUri(); String etag; // Different Media Types may have different ETags final String acceptHeader = request.getHeaders().getFirst(HttpHeaders.ACCEPT); if (acceptHeader != null) { final List<WeightedMediaType> waccepts = new ArrayList<WeightedMediaType>(); final String[] split = acceptHeader.split(","); for (final String accept : split) { waccepts.add(WeightedMediaType.valueOf(accept)); } // Sort the media types Collections.sort(waccepts); // Iterate through the list and see if an etag exists for (final MediaType accept : waccepts) { etag = cache.get(uri, accept.toString()); if (etag != null) return etag; } } else { return cache.getAny(uri); } return null; }
public String getOAuthLogoutUrl(final HttpServletRequest servletRequest) { final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpSession session = request.getSession(false); if (session == null) { log.trace("There is no exising session"); return null; } OAuthData oAuthData = (OAuthData) session.getAttribute(Configuration.SESSION_OAUTH_DATA); if (oAuthData == null) { log.trace("There is no OAuthData in the session"); return null; } // TODO: Validate access token ClientRequest clientRequest = new ClientRequest(Configuration.instance().getPropertyValue(Configuration.OAUTH_PROPERTY_LOGOUT_URL)); clientRequest.queryParameter(Configuration.OAUTH_ID_TOKEN_HINT, oAuthData.getIdToken()); clientRequest.queryParameter(Configuration.OAUTH_POST_LOGOUT_REDIRECT_URI, constructRedirectUrl(request)); // Remove OAuth data from session session.removeAttribute(Configuration.SESSION_OAUTH_DATA); try { return clientRequest.getUri(); } catch (Exception ex) { log.error("Failed to prepare OAuth log out URL", ex); } return null; }
protected BrowserCache.Entry getEntry(ClientRequest request) throws Exception String uri = request.getUri();
protected BrowserCache.Entry getEntry(ClientRequest request) throws Exception String uri = request.getUri();
public ClientResponse execute(ClientRequest request) throws Exception { MockHttpRequest mockHttpRequest = MockHttpRequest.create(request.getHttpMethod(), new URI(request.getUri()), baseUri); final MockHttpResponse mockResponse = new MockHttpResponse(); mockHttpRequest.setAsynchronousContext(new SynchronousExecutionContext((SynchronousDispatcher)dispatcher, mockHttpRequest, mockResponse)); loadHttpMethod(request, mockHttpRequest); dispatcher.invoke(mockHttpRequest, mockResponse); return createResponse(request, mockResponse); }
public ClientResponse execute(ClientRequest request) throws Exception { MockHttpRequest mockHttpRequest = MockHttpRequest.create(request.getHttpMethod(), new URI(request.getUri()), baseUri); final MockHttpResponse mockResponse = new MockHttpResponse(); mockHttpRequest.setAsynchronousContext(new SynchronousExecutionContext((SynchronousDispatcher)dispatcher, mockHttpRequest, mockResponse)); loadHttpMethod(request, mockHttpRequest); dispatcher.invoke(mockHttpRequest, mockResponse); return createResponse(request, mockResponse); }
@Test public void reRequestTest() throws Exception { String urlString = "http://localhost:8080/appBase/"; URL appBaseUrl = new URL(urlString); ClientRequestFactory factory = new ClientRequestFactory(appBaseUrl.toURI()); String pathAdd = "/j_security_check"; ClientRequest formRequest = factory.createRelativeRequest(pathAdd); formRequest.formParameter("test", "test"); assertEquals(urlString + pathAdd , formRequest.getUri()); }
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
BrowserCache.Entry entry = cache.put(request.getUri(), old.getMediaType(), old.getHeaders(), old.getCached(), expires, etag, lastModified); return createClientResponse(request, entry);
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }