生成HTTP请求签名字符串

@param urlString
@param body
@param contentType
@return
772581
public String signRequestV2(String urlString, String method, byte[] body, String contentType) {
        URI uri = URI.create(urlString);

        Mac mac = createMac();
        StringBuilder sb = new StringBuilder();

        sb.append(String.format("%s %s", method, uri.getPath()));
        if (uri.getQuery() != null) {
            sb.append(String.format("?%s", uri.getQuery()));
        }

        sb.append(String.format("\nHost: %s", uri.getHost()));
        if (uri.getPort() > 0) {
            sb.append(String.format(":%d", uri.getPort()));
        }

        if (contentType != null) {
            sb.append(String.format("\nContent-Type: %s", contentType));
        }

        // body
        sb.append("\n\n");
        if (body != null && body.length > 0 && !StringUtils.isNullOrEmpty(contentType)) {
            if (contentType.equals(Client.FormMime)
                    || contentType.equals(Client.JsonMime)) {
                sb.append(new String(body));
            }
        }

        mac.update(StringUtils.utf8Bytes(sb.toString()));

        String digest = UrlSafeBase64.encodeToString(mac.doFinal());
        return this.accessKey + ":" + digest;
    }
400215
public HttpRequestBase getHttpRequest(HttpServletRequest req, String urlString)
	{	 // Prepare a request object
		HttpRequestBase httpget = null;
		String method = req.getMethod();
		if (GET.equalsIgnoreCase(method))
			httpget = new HttpGet(urlString);
		else if (POST.equalsIgnoreCase(method))
			httpget = new HttpPost(urlString);
		else if (PUT.equalsIgnoreCase(method))
			httpget = new HttpPut(urlString);
		else if (DELETE.equalsIgnoreCase(method))
			httpget = new HttpDelete(urlString);
		else if (HEAD.equalsIgnoreCase(method))
			httpget = new HttpHead(urlString);
		else if (OPTIONS.equalsIgnoreCase(method))
			httpget = new HttpOptions(urlString);
		else if (TRACE.equalsIgnoreCase(method))
			httpget = new HttpTrace(urlString);
		return httpget;
	}
28006
public String createQueryStringFromNode(Node node, @Nullable Class<?> domainType) {
		return createQueryStringFromNode(node, 0, domainType);
	}
100736
public MuleMessage doHttpSendRequest(String url, String method, String payload, String contentType) {    	

		Map<String, String> properties = new HashMap<String, String>();
    	properties.put("http.method",    method);
    	properties.put("Content-Type",   contentType);

    	MuleMessage response = send(url, payload, properties);
    	
    	return response;
	}
295187
private HttpUriRequest makeRequest(URI uri, final String requestBody)
    {
        HttpPost post = new HttpPost(uri);
        post.setEntity(new StringEntity(requestBody, m_contentType));
        return post;
    }
626922
public static String getURLProtocol(String urlString) {
        String protocol = null;
        int firstColon = urlString.indexOf(':');
        if (firstColon >= 0) {
            String specifiedProtocol = urlString.substring(0, firstColon);
            if (FindBugs.knownURLProtocolSet.contains(specifiedProtocol)) {
                protocol = specifiedProtocol;
            }
        }
        return protocol;
    }
678407
public static String urlNonFormEncode(final String s)
        {
        if (StringUtils.isBlank(s))
            {
            LOG.warn("Could not encode blank string");
            throw new IllegalArgumentException("Blank string");
            }
        try
            {
            // We use the HttpClient encoder because the java URLEncoder
            // class uses form encoding.
            return URIUtil.encodeQuery(s, "UTF-8");
            }
        catch (final URIException e)
            {
            LOG.error ("Could not encode: " + s, e);
            
            // This really should never happen.
            assert false;
            return s;
            }
        }
1332586
public PactDslRequestWithPath body(Supplier<String> body, ContentType mimeType) {
        return body(body, mimeType.toString());
    }
661714
public KieServerHttpRequest contentType(final String contentType, final String charset ) {
        if( charset != null && charset.length() > 0 ) {
            final String separator = "; " + PARAM_CHARSET + '=';
            return header(CONTENT_TYPE, contentType + separator + charset);
        } else
            return header(CONTENT_TYPE, contentType);
    }
823784
public static String get(String url, String body) {
        return request(HttpRequest.get(replaceLocalHost(url)), body).body();
    }
737033
private URL createURL(final String urlString) throws MalformedURLException {

        URL url;
        try {
            url = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {

                @Override
                public URL run() throws MalformedURLException {
                    return new URL(urlString);
                }
            });
        } catch (PrivilegedActionException e) {
            throw (MalformedURLException) e.getCause();
        }

        return url;
    }
553833
public Observable<ServiceResponse<ImageList>> createWithServiceResponseAsync(String contentType, BodyModel bodyParameter) {
        if (this.client.baseUrl() == null) {
            throw new IllegalArgumentException("Parameter this.client.baseUrl() is required and cannot be null.");
        }
        if (contentType == null) {
            throw new IllegalArgumentException("Parameter contentType is required and cannot be null.");
        }
        if (bodyParameter == null) {
            throw new IllegalArgumentException("Parameter bodyParameter is required and cannot be null.");
        }
        Validator.validate(bodyParameter);
        String parameterizedHost = Joiner.on(", ").join("{baseUrl}", this.client.baseUrl());
        return service.create(contentType, bodyParameter, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImageList>>>() {
                @Override
                public Observable<ServiceResponse<ImageList>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImageList> clientResponse = createDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }
204597
protected MailMessage createMailMessage(Map<String, Object> messageHeaders, String body, String contentType) {
        return MailMessage.request(messageHeaders)
                .marshaller(marshaller)
                .from(messageHeaders.get(CitrusMailMessageHeaders.MAIL_FROM).toString())
                .to(messageHeaders.get(CitrusMailMessageHeaders.MAIL_TO).toString())
                .cc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_CC).toString())
                .bcc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_BCC).toString())
                .subject(messageHeaders.get(CitrusMailMessageHeaders.MAIL_SUBJECT).toString())
                .body(body, contentType);
    }
691135
public static void setEntity(HttpConnection connnection, String body, String contentType) {
        connnection.requestProperties.put("Content-type", contentType);
        connnection.setRequestBody(body);
    }
548290
public static boolean showDocument(String urlstring){
		try{
			URL url = new URL(urlstring);

			return showDocument(url);
		} catch (MalformedURLException e){
			logger.warn("malformed URL {}", urlstring, e);
			return false;
		}
	}
231437
private static ByteBuffer stringAsType(String content, AbstractType<?> type)
    {
        try
        {
            return type.fromString(content);
        }
        catch (MarshalException e)
        {
            throw new RuntimeException(e.getMessage());
        }
    }
1121439
public boolean renderURL(String urlstring, OutputStream out, Type type) throws IOException, SAXException
    {
        if (!urlstring.startsWith("http:") &&
            !urlstring.startsWith("https:") &&
            !urlstring.startsWith("ftp:") &&
            !urlstring.startsWith("file:"))
                urlstring = "http://" + urlstring;
        
        //Open the network connection 
        DocumentSource docSource = new DefaultDocumentSource(urlstring);
        
        //Parse the input document
        DOMSource parser = new DefaultDOMSource(docSource);
        Document doc = parser.parse();
        
        //create the media specification
        MediaSpec media = new MediaSpec(mediaType);
        media.setDimensions(windowSize.width, windowSize.height);
        media.setDeviceDimensions(windowSize.width, windowSize.height);

        //Create the CSS analyzer
        DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
        da.setMediaSpec(media);
        da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
        da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
        da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
        da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
        da.getStyleSheets(); //load the author style sheets
        
        BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
        contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
        contentCanvas.getConfig().setClipViewport(cropWindow);
        contentCanvas.getConfig().setLoadImages(loadImages);
        contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);

        if (type == Type.PNG)
        {
            contentCanvas.createLayout(windowSize);
            ImageIO.write(contentCanvas.getImage(), "png", out);
        }
        else if (type == Type.SVG)
        {
            setDefaultFonts(contentCanvas.getConfig());
            contentCanvas.createLayout(windowSize);
            Writer w = new OutputStreamWriter(out, "utf-8");
            writeSVG(contentCanvas.getViewport(), w);
            w.close();
        }
        
        docSource.close();

        return true;
    }