/** * Submits the pending operations associated with this {@link Wavelet}. * * @param wavelet the bundle that contains the operations to be submitted. * @param rpcServerUrl the active gateway to send the operations to. * @return a list of {@link JsonRpcResponse} that represents the responses * from the server for all operations that were submitted. * * @throws IllegalStateException if this method is called prior to setting * the proper consumer key, secret, and handler URL. * @throws IOException if there is a problem submitting the operations. */ public List<JsonRpcResponse> submit(Wavelet wavelet, String rpcServerUrl) throws IOException { return waveService.submit(wavelet, rpcServerUrl); }
/** * @see #blindWavelet(WaveId, WaveletId) * * @param proxyForId the proxying information that should be set on the * operation queue. Please note that this parameter should be properly * encoded to ensure that the resulting participant id is valid * (see {@link Util#checkIsValidProxyForId(String)} for more details). */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId) { return waveService.blindWavelet(waveId, waveletId, proxyForId); }
/** * @see #fetchWavelet(WaveId, WaveletId, String) * * @param proxyForId the proxy id that should be used to fetch this wavelet. * Please note that this parameter should be properly encoded to ensure * that the resulting participant id is valid (see * {@link Util#checkIsValidProxyForId(String)} for more details). */ public Wavelet fetchWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, String rpcServerUrl) throws IOException { return waveService.fetchWavelet(waveId, waveletId, proxyForId, rpcServerUrl); }
public void testSubmit() throws Exception { HttpFetcher fetcher = mock(HttpFetcher.class); when(fetcher.execute(any(HttpMessage.class), anyMapOf(String.class, Object.class))) .thenReturn(new HttpResponse("POST", new URL("http://foo.google.com"), 0, new ByteArrayInputStream("[{\"id\":\"op1\",\"data\":{}}]".getBytes()))); MockRobot robot = new MockRobot(); robot.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); WaveService service = new WaveService(fetcher, robot.computeHash()); service.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); OperationQueue opQueue = new OperationQueue(); opQueue.appendOperation(OperationType.ROBOT_NOTIFY, Parameter.of(ParamsProperty.CAPABILITIES_HASH, "123")); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(opQueue); assertEquals(1, opQueue.getPendingOperations().size()); robot.submit(wavelet, "http://gmodules.com/api/rpc", service); assertEquals(0, opQueue.getPendingOperations().size()); verify(fetcher, times(1)).execute(any(HttpMessage.class), anyMapOf(String.class, Object.class)); }
waveService.setupOAuth(consumerKey, consumerSecret, rpcServerUrl); setAllowUnsignedRequests(false);
/** * Initializes the robot. Call it if required to re-compute robot's * capabilities. Re-invoke {@link #setupOAuth} if needed. */ protected void initRobot() { capabilityMap = computeCapabilityMap(); version = computeHash(); waveService = new WaveService(version); }
if (!waveService.hasConsumerData(bundle.getRpcServerUrl())) { throw new IllegalArgumentException("No consumer key is found for the RPC server URL: " + bundle.getRpcServerUrl()); @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = req.getParameterMap(); waveService.validateOAuthRequest(req.getRequestURL().toString(), parameterMap, json, bundle.getRpcServerUrl()); } catch (OAuthException e) {
/** * Sets whether or not unsigned incoming requests from robot proxy are * allowed. * * @param allowUnsignedRequests whether or not unsigned requests from robot * proxy are allowed. */ protected void setAllowUnsignedRequests(boolean allowUnsignedRequests) { if (!allowUnsignedRequests && waveService.getConsumerDataMap().isEmpty()) { throw new IllegalArgumentException("Please call AbstractRobot.setupOAuth() first to " + "setup the consumer key and secret to validate the request."); } this.allowUnsignedRequests = allowUnsignedRequests; }
/** * Submits the given operation. * * @param opQueue the operation queue with operation to be submitted. * @param rpcServerUrl the active gateway to send the operations to. * @return the data of response. * @throws IllegalStateException if this method is called prior to setting the * proper consumer key, secret, and handler URL. * @throws IOException if there is a problem submitting the operations, or error response. */ private Map<ParamsProperty, Object> makeSingleOperationRpc(OperationQueue opQueue, String rpcServerUrl) throws IOException { JsonRpcResponse response = makeRpc(opQueue, rpcServerUrl).get(0); if (response.isError()) { throw new IOException(response.getErrorMessage()); } return response.getData(); }
String url = createOAuthUrlString( json, consumerDataObj.getRpcServerUrl(), consumerDataObj.getAccessor()); if (LOG.isLoggable(Level.FINE)) {
public void testSubmit() throws Exception { HttpFetcher fetcher = mock(HttpFetcher.class); when(fetcher.execute(any(HttpMessage.class), anyMapOf(String.class, Object.class))) .thenReturn(new HttpResponse("POST", new URL("http://foo.google.com"), 0, new ByteArrayInputStream("[{\"id\":\"op1\",\"data\":{}}]".getBytes()))); MockRobot robot = new MockRobot(); robot.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); WaveService service = new WaveService(fetcher, robot.computeHash()); service.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); OperationQueue opQueue = new OperationQueue(); opQueue.appendOperation(OperationType.ROBOT_NOTIFY, Parameter.of(ParamsProperty.CAPABILITIES_HASH, "123")); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(opQueue); assertEquals(1, opQueue.getPendingOperations().size()); robot.submit(wavelet, "http://gmodules.com/api/rpc", service); assertEquals(0, opQueue.getPendingOperations().size()); verify(fetcher, times(1)).execute(any(HttpMessage.class), anyMapOf(String.class, Object.class)); }
if (!waveService.getConsumerDataMap().isEmpty()) { xml.append(" <w:consumer_keys>\n"); for (ConsumerData consumerDataObj : waveService.getConsumerDataMap().values()) { xml.append(" <w:consumer_key for=\"" + consumerDataObj.getRpcServerUrl() + "\">" + consumerDataObj.getConsumerKey() + "</w:consumer_key>\n");
/** * Submits the pending operations associated with this {@link Wavelet}. * * @param wavelet the bundle that contains the operations to be submitted. * @param rpcServerUrl the active gateway to send the operations to. * @return a list of {@link JsonRpcResponse} that represents the responses * from the server for all operations that were submitted. * * @throws IllegalStateException if this method is called prior to setting the * proper consumer key, secret, and handler URL. * @throws IOException if there is a problem submitting the operations. */ public List<JsonRpcResponse> submit(Wavelet wavelet, String rpcServerUrl) throws IOException { List<JsonRpcResponse> responses = makeRpc(wavelet.getOperationQueue(), rpcServerUrl); wavelet.getOperationQueue().clear(); return responses; }
public List<JsonRpcResponse> submit(Wavelet wavelet, String rpcServerUrl, WaveService service) throws IOException { return service.submit(wavelet, rpcServerUrl); }
/** * @see #blindWavelet(WaveId, WaveletId, String) * * @param blips a collection of blips that belong to this wavelet. */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, Map<String, Blip> blips) { return waveService.blindWavelet(waveId, waveletId, proxyForId, blips); }
/** * Fetches a wavelet using the active API. * * The returned wavelet contains a snapshot of the state of the wavelet at * that point. It can be used to modify the wavelet, but the wavelet might * change in between, so treat carefully. * * Also, the returned wavelet has its own {@link OperationQueue}. It is the * responsibility of the caller to make sure this wavelet gets submitted to * the server, either by calling {@link AbstractRobot#submit(Wavelet, String)} * or by calling {@link Wavelet#submitWith(Wavelet)} on the new wavelet. * * @param waveId the id of the wave to fetch. * @param waveletId the id of the wavelet to fetch. * @param rpcServerUrl the active gateway that is used to fetch the wavelet. * * @throws IOException if there is a problem fetching the wavelet. */ public Wavelet fetchWavelet(WaveId waveId, WaveletId waveletId, String rpcServerUrl) throws IOException { return fetchWavelet(waveId, waveletId, null, rpcServerUrl); }
public List<JsonRpcResponse> submit(Wavelet wavelet, String rpcServerUrl, WaveService service) throws IOException { return service.submit(wavelet, rpcServerUrl); }
/** * @see #blindWavelet(WaveId, WaveletId, String, Map) * * @param threads a collection of threads that belong to this wavelet. */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, Map<String, Blip> blips, Map<String, BlipThread> threads) { return waveService.blindWavelet(waveId, waveletId, proxyForId, blips, threads); }
/** * Fetches a wavelet using the active API. * * The returned wavelet contains a snapshot of the state of the wavelet at * that point. It can be used to modify the wavelet, but the wavelet might * change in between, so treat carefully. * * Also, the returned wavelet has its own {@link OperationQueue}. It is the * responsibility of the caller to make sure this wavelet gets submitted to * the server, either by calling {@link AbstractRobot#submit(Wavelet, String)} * or by calling {@link Wavelet#submitWith(Wavelet)} on the new wavelet. * * @param waveId the id of the wave to fetch. * @param waveletId the id of the wavelet to fetch. * @param rpcServerUrl the active gateway that is used to fetch the wavelet. * * @throws IOException if there is a problem fetching the wavelet. */ public Wavelet fetchWavelet(WaveId waveId, WaveletId waveletId, String rpcServerUrl) throws IOException { return waveService.fetchWavelet(waveId, waveletId, rpcServerUrl); }
JsonRpcResponse response = this.submit(newWavelet, rpcServerUrl).get(1); if (response.isError()) { throw new IOException(response.getErrorMessage());