Create a doc notification in the doc stream service.

@param request The request object containing all options for creating doc notification.
425383
public CreateNotificationResponse createNotification(CreateNotificationRequest request) {

        checkStringNotEmpty(request.getName(),
                "The parameter name should NOT be null or empty string.");
        checkStringNotEmpty(request.getEndpoint(),
                "The parameter endpoint should NOT be null or empty string.");

        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, PATH_NOTIFICATION);
        String strJson = JsonUtils.toJsonString(request);
        byte[] requestJson = null;
        try {
            requestJson = strJson.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            throw new BceClientException("Unsupported encode.", e);
        }

        internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(requestJson.length));
        internalRequest.addHeader(Headers.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
        internalRequest.setContent(RestartableInputStream.wrap(requestJson));
        return invokeHttpClient(internalRequest, CreateNotificationResponse.class);
    }
591237
public GetDocumentResponse getDocument(GetDocumentRequest request) {
        checkNotNull(request, "request should not be null.");
        checkNotNull(request.getDocumentId(), "documentId should not be null.");
        InternalRequest internalRequest = this.createRequest(HttpMethodName.GET, request, DOC, request.getDocumentId());
        GetDocumentResponse response;
        try {
            response = this.invokeHttpClient(internalRequest, GetDocumentResponse.class);
        } finally {
            try {
                internalRequest.getContent().close();
            } catch (Exception e) {
                // ignore exception
            }
        }

        return response;
    }
445357
public void updateStreamPresets(UpdateStreamPresetsRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");

        checkStringNotEmpty(request.getDomain(), "Domain should NOT be empty.");
        checkStringNotEmpty(request.getApp(), "App should NOT be empty");
        checkStringNotEmpty(request.getStream(), "Stream should NOT be empty.");
        // presets can be null for letting stream to use domain's presets,
        // so no need to check if presets is null

        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, LIVE_DOMAIN,
                request.getDomain(), LIVE_APP, request.getApp(), LIVE_STREAM, request.getStream());
        internalRequest.addParameter("presets", null);
        invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }
1355344
public void notifyObserversOfRequestProcessed(CachedSpiceRequest<?> request, Set<RequestListener<?>> requestListeners) {
        RequestProcessingContext requestProcessingContext = new RequestProcessingContext();
        requestProcessingContext.setExecutionThread(Thread.currentThread());
        requestProcessingContext.setRequestListeners(requestListeners);
        post(new RequestProcessedNotifier(request, spiceServiceListenerList, requestProcessingContext));
    }
881441
private void addPostParams(final Request request) {
        if (qualityScore != null) {
            request.addPostParam("QualityScore", qualityScore.toString());
        }

        if (issue != null) {
            for (Feedback.Issues prop : issue) {
                request.addPostParam("Issue", prop.toString());
            }
        }
    }
709764
public <R extends Request<T>, T> R add(R request) {
        //Listener factories should be first so client can listen to events
        for (ListenerFactory listenerFactory : listenerFactories) {
            RequestListener.ResponseListener qResponseListener = listenerFactory
                    .getResponseListener(request);
            RequestListener.ErrorListener qErrorListener = listenerFactory.getErrorListener
                    (request);
            RequestListener.MarkerListener qMarkerListener = listenerFactory.getMarkerListener
                    (request);

            if (qMarkerListener != null) {
                request.addMarkerListener(qMarkerListener);
            }
            if (qResponseListener != null) {
                request.addResponseListener(qResponseListener);
            }
            if (qErrorListener != null) {
                request.addErrorListener(qErrorListener);
            }
        }
        if (JusLog.ErrorLog.isOn()) {
            request.addErrorListener(JusLog.ErrorLog.getLogger(request));
        }

        if (JusLog.ResponseLog.isOn()) {
            request.addResponseListener(JusLog.ResponseLog.getLogger(request));
        }

        if (JusLog.MarkerLog.isOn()) {
            request.addMarkerListener(JusLog.MarkerLog.getLogger(request));
        }
        request.addMarker(Request.EVENT_PRE_ADD_TO_QUEUE);
        Authenticator serverAuthenticator = null;
        Authenticator proxyAuthenticator = null;
        for (Authenticator.Factory factory : authenticatorFactories) {

            if (serverAuthenticator == null) {
                serverAuthenticator = factory.forServer(request.getUrl(), request
                        .getNetworkRequest());
                if (serverAuthenticator != null)
                    request.setServerAuthenticator(serverAuthenticator);
            }

            if (proxyAuthenticator == null) {
                proxyAuthenticator = factory.forProxy(request.getUrl(), request.getNetworkRequest
                        ());
                if (proxyAuthenticator != null)
                    request.setProxyAuthenticator(proxyAuthenticator);
            }

            if (proxyAuthenticator != null && serverAuthenticator != null) {
                break;
            }

        }

        for (Transformer.RequestTransformer transformer : requestTransformers) {
            if (transformer.filter == null || transformer.filter.apply(request)) {
                request.setNetworkRequest(transformer.transform(request.getNetworkRequest()));
            }
        }

        if (retryPolicyFactory != null) {
            request.setRetryPolicy(retryPolicyFactory.get(request));
        }
        if (redirectPolicyFactory != null) {
            request.setRedirectPolicy(redirectPolicyFactory.get(request));
        }

        if (connectivityManagerFactory != null) {
            request.setConnectivityManager(connectivityManagerFactory.get(request));
        }
        if (noConnectionPolicyFactory != null) {
            request.setNoConnectionPolicy(noConnectionPolicyFactory.get(request));
        }

        synchronized (currentRequests) {
            //check if not already cancelled
            if (request.isCanceled()) {
                request.finish(Request.EVENT_ADD_DISCARD_CANCELED);
            }
            // Process requests in the order they are added.
            request.setSequence(getSequenceNumber());
            // Tag the request as belonging to this queue and add it to the set of current requests.
            request.setRequestQueue(this);
            currentRequests.add(request);
        }
        request.addMarker(Request.EVENT_ADD_TO_QUEUE);

        // If the request is uncacheable, skip the cache queue and go straight to the network.
        if (!request.shouldCache()) {
            networkQueue.add(request);
            return request;
        }

        // Insert request into stage if there's already a request with the same cache key in flight.
        synchronized (waitingRequests) {
            String cacheKey = request.getCacheKey();
            if (waitingRequests.containsKey(cacheKey)) {
                // There is already a request in flight. Queue up.
                Queue<Request<?>> stagedRequests = waitingRequests.get(cacheKey);
                if (stagedRequests == null) {
                    stagedRequests = new LinkedList<>();
                }
                stagedRequests.add(request);
                waitingRequests.put(cacheKey, stagedRequests);
//                if (JusLog.DEBUG) {
//                    JusLog.v("Request for cacheKey=%s is in flight, putting on hold.", cacheKey);
//                }
                //todo add queue markers
            } else {
                // Insert 'empty list' queue for this cacheKey, indicating there is now a request in
                // flight.
                waitingRequests.put(cacheKey, new LinkedList<Request<?>>());
                cacheQueue.add(request);
            }
            return request;
        }
    }
691852
function(request) {
        var format = new OpenLayers.Format.WMSDescribeLayer();
        var doc = request.responseXML;
        if(!doc || !doc.documentElement) {
            doc = request.responseText;
        }
        var describeLayer = format.read(doc);
        var typeNames = [];
        var url = null;
        for (var i=0, len=describeLayer.length; i<len; i++) {
            // perform a WFS DescribeFeatureType request
            if (describeLayer[i].owsType == "WFS") {
                typeNames.push(describeLayer[i].typeName);
                url = describeLayer[i].owsURL;
            }
        }
        var options = {
            url: url,
            params: {
                SERVICE: "WFS",
                TYPENAME: typeNames.toString(),
                REQUEST: "DescribeFeatureType",
                VERSION: "1.0.0"
            },
            callback: function(request) {
                var format = new OpenLayers.Format.WFSDescribeFeatureType();
                var doc = request.responseXML;
                if(!doc || !doc.documentElement) {
                    doc = request.responseText;
                }
                var describeFeatureType = format.read(doc);
                this.control.wfsCache[this.layer.id] = describeFeatureType;
                this.control._queue && this.control.applySelection();
            },
            scope: this
        };
        OpenLayers.Request.GET(options);
    }
1298722
public void releaseRequest(HttpRequestMessageImpl request) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "releaseRequest: " + request);
        }
        this.reqPool.put(request);
    }
971920
private void addPostParams(final Request request) {
        if (body != null) {
            request.addPostParam("Body", body);
        }

        if (attributes != null) {
            request.addPostParam("Attributes", attributes);
        }
    }
1285478
private static void request(final Request request) {
        if (null == request) {
            WonderPush.logError("Request with null request.");
            return;
        }

        WonderPush.safeDefer(new Runnable() {
            @Override
            public void run() {
                // Decorate parameters
                WonderPushRequestParamsDecorator.decorate(request.getResource(), request.getParams());

                // Generate signature
                BasicHeader authorizationHeader = request.getAuthorizationHeader();

                // Headers
                BasicHeader[] headers = null;
                if (null != authorizationHeader) {
                    headers = new BasicHeader[1];
                    headers[0] = authorizationHeader;
                }

                String url = WonderPushUriHelper.getAbsoluteUrl(request.getResource());
                WonderPush.logDebug("requesting url: " + request.getMethod() + " " + url + "?" + request.getParams().getURLEncodedString());
                // TODO: support other contentTypes such as "application/json"
                String contentType = "application/x-www-form-urlencoded";

                // Handler
                final ResponseHandler handler = request.getHandler();
                HttpEntity entity = null;
                if (request.getParams() != null) {
                    try {
                        entity = request.getParams() != null ? request.getParams().getEntity(null) : null;
                    } catch (IOException ex) {
                        WonderPush.logError("Failed to create HttpEntity from params " + request.getParams(), ex);
                        if (handler != null) {
                            handler.onFailure(ex, new Response(""));
                        }
                        return;
                    }
                }
                final long sendDate = SystemClock.elapsedRealtime();
                JsonHttpResponseHandler jsonHandler = new JsonHttpResponseHandler() {
                    @Override
                    public void onProgress(long bytesWritten, long totalSize) {
                        // mute this
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        syncTime(response);
                        WonderPush.setNetworkAvailable(true);
                        if (handler != null) {
                            handler.onSuccess(statusCode, new Response(response));
                        }
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                        WonderPush.logError("Unexpected JSONArray answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + response.length() + ") " + response.toString());
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                        WonderPush.logError("Error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: " + errorResponse);
                        syncTime(errorResponse);
                        WonderPush.logDebug("Request Error: " + errorResponse);
                        WonderPush.setNetworkAvailable(errorResponse != null);
                        if (handler != null) {
                            handler.onFailure(throwable, new Response(errorResponse));
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
                        WonderPush.logError("Unexpected JSONArray error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + errorResponse.length() + ") " + errorResponse.toString());
                        this.onFailure(statusCode, headers, errorResponse.toString(), throwable);
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        WonderPush.logError("Unexpected string error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + responseString.length() + ") \"" + responseString + "\"");
                        WonderPush.setNetworkAvailable(false);
                        if (handler != null) {
                            handler.onFailure(throwable, new Response(responseString));
                        }
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, String responseString) {
                        WonderPush.logError("Unexpected string answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + responseString.length() + ") \"" + responseString + "\"");
                    }

                    private void syncTime(JSONObject data) {
                        long recvDate = SystemClock.elapsedRealtime();
                        if (data == null || !data.has("_serverTime")) {
                            return;
                        }
                        TimeSync.syncTimeWithServer(sendDate, recvDate, data.optLong("_serverTime"), data.optLong("_serverTook"));
                    }
                };
                // NO UNNECESSARY WORK HERE, because of timed request
                switch (request.getMethod()) {
                    case GET:
                        sClient.get(null, url, headers, request.getParams(), jsonHandler);
                        break;
                    case PUT:
                        sClient.put(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case POST:
                        sClient.post(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case PATCH:
                        sClient.patch(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case DELETE:
                        sClient.delete(null, url, headers, request.getParams(), jsonHandler);
                        break;
                    default:
                        jsonHandler.sendFailureMessage(0, null, null, new UnsupportedOperationException("Unhandled method " + request.getMethod()));
                }
            }
        }, 0);
    }
961976
protected ServletFileUpload createServletFileUpload(final HttpServletRequest request) {
        final DiskFileItemFactory fileItemFactory = createDiskFileItemFactory();
        final ServletFileUpload upload = newServletFileUpload(fileItemFactory);
        upload.setHeaderEncoding(request.getCharacterEncoding());
        upload.setSizeMax(getSizeMax());
        return upload;
    }
1288755
public static Message buildRequest(ByteBuffer request) {
    Request req = Request.newBuilder()
                         .setRequest(ByteString.copyFrom(request))
                         .build();

    return Message.newBuilder().setType(MessageType.REQUEST)
                               .setRequest(req)
                               .build();
  }
812082
void postSuccess(final DownloadRequest request) {
    downloadPoster.execute(new Runnable() {
      @Override public void run() {
        request.downloadCallback().onSuccess(request.downloadId(), request.destinationFilePath());
      }
    });
  }
69701
protected S createNewStatus(R request)
    {
        Job currentJob = this.jobContext.getCurrentJob();
        JobStatus currentJobStatus = currentJob != null ? currentJob.getStatus() : null;
        return (S) new DefaultJobStatus<R>(getType(), request, currentJobStatus, this.observationManager,
            this.loggerManager);
    }
452110
public CreateResponse create(CreateRequest request) {
    return call(
      new PostRequest(path("create"))
        .setParam("name", request.getName())
        .setParam("organization", request.getOrganization()),
      CreateResponse.parser());
  }
1231609
public synchronized void setRequest(HttpServletRequest request) {

        if (perThreadRequest == null) {
            perThreadRequest = new ThreadLocal<HttpServletRequest>();
        }
        perThreadRequest.set(request);
    }
343842
@Override
    public ContentPattern<?> forRequest(Request request) {
        final String mimeType = request.getHeaders().getContentTypeHeader().mimeTypePart();
        if (mimeType != null) {
            if (mimeType.contains("json")) {
                return new EqualToJsonPattern(request.getBodyAsString(), ignoreArrayOrder, ignoreExtraElements);
            } else if (mimeType.contains("xml")) {
                return new EqualToXmlPattern(request.getBodyAsString());
            } else if (mimeType.equals("multipart/form-data")) {
                // TODO: Need to add a matcher that can handle multipart data properly. For now, just always match
                return new AnythingPattern();
            } else if (!determineIsTextFromMimeType(mimeType)) {
                return new BinaryEqualToPattern(request.getBody());
            }
        }

        return new EqualToPattern(request.getBodyAsString(), caseInsensitive);
    }