/** * The provides an extension point. If you want to extend this and use a special dispatcher, * here is the place to do it. * <p> * @param attributes */ @Override public void initialize( RemoteHttpCacheAttributes attributes ) { setRemoteDispatcher( new RemoteHttpCacheDispatcher( attributes ) ); if ( log.isInfoEnabled() ) { log.info( "Created remote Dispatcher." + getRemoteDispatcher() ); } setInitialized( true ); }
String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() ); byte[] responseAsByteArray = processRequest( requestAsByteArray, url );
/** * @param requestAsByteArray * @param url * @return byte[] - the response * @throws IOException * @throws HttpException */ protected byte[] processRequest( byte[] requestAsByteArray, String url ) throws IOException, HttpException { PostMethod post = new PostMethod( url ); RequestEntity requestEntity = new ByteArrayRequestEntity( requestAsByteArray ); post.setRequestEntity( requestEntity ); doWebserviceCall( post ); byte[] response = post.getResponseBody(); return response; }
/** * Verify that we don't get two ?'s */ public void testAddParameters_withQueryString() { // SETUP RemoteHttpCacheAttributes remoteHttpCacheAttributes = new RemoteHttpCacheAttributes(); RemoteHttpCacheDispatcher dispatcher = new RemoteHttpCacheDispatcher( remoteHttpCacheAttributes ); RemoteCacheRequest<String, String> remoteCacheRequest = new RemoteCacheRequest<String, String>(); remoteCacheRequest.setRequestType( RemoteRequestType.REMOVE_ALL ); String cacheName = "myCache"; remoteCacheRequest.setCacheName( cacheName ); String baseUrl = "http://localhost?thishasaquestionmark"; // DO WORK String result = dispatcher.addParameters( remoteCacheRequest, baseUrl ); // VERIFY assertEquals( "Wrong url", baseUrl + "&CacheName=" + cacheName + "&Key=&RequestType=REMOVE_ALL", result ); } }
if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() ) if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue ); if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
/** * Verify that we don't get two ?'s */ public void testAddParameters_withQueryString() { // SETUP RemoteHttpCacheAttributes remoteHttpCacheAttributes = new RemoteHttpCacheAttributes(); RemoteHttpCacheDispatcher dispatcher = new RemoteHttpCacheDispatcher( remoteHttpCacheAttributes ); RemoteCacheRequest<String, String> remoteCacheRequest = new RemoteCacheRequest<String, String>(); remoteCacheRequest.setRequestType( RemoteRequestType.REMOVE_ALL ); String cacheName = "myCache"; remoteCacheRequest.setCacheName( cacheName ); String baseUrl = "http://localhost?thishasaquestionmark"; // DO WORK String result = dispatcher.addParameters( remoteCacheRequest, baseUrl ); // VERIFY assertEquals( "Wrong url", baseUrl + "&CacheName=" + cacheName + "&Key=&RequestType=REMOVE_ALL", result ); } }
if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() ) if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue ); if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() ); byte[] responseAsByteArray = processRequest( requestAsByteArray, url );
/** * The provides an extension point. If you want to extend this and use a special dispatcher, * here is the place to do it. * <p> * @param attributes */ @Override public void initialize( RemoteHttpCacheAttributes attributes ) { setRemoteDispatcher( new RemoteHttpCacheDispatcher( attributes ) ); if ( log.isInfoEnabled() ) { log.info( "Created remote Dispatcher." + getRemoteDispatcher() ); } setInitialized( true ); }
/** * @param requestAsByteArray * @param url * @return byte[] - the response * @throws IOException * @throws HttpException */ protected byte[] processRequest( byte[] requestAsByteArray, String url ) throws IOException, HttpException { PostMethod post = new PostMethod( url ); RequestEntity requestEntity = new ByteArrayRequestEntity( requestAsByteArray ); post.setRequestEntity( requestEntity ); doWebserviceCall( post ); byte[] response = post.getResponseBody(); return response; }