/** * Builds the signature base string from the data this instance was * configured with. * * @return the signature base string * @throws OAuthMessageSignerException */ public String generate() throws OAuthMessageSignerException { try { String normalizedUrl = normalizeRequestUrl(); String normalizedParams = normalizeRequestParameters(); return request.getMethod() + '&' + OAuth.percentEncode(normalizedUrl) + '&' + OAuth.percentEncode(normalizedParams); } catch (Exception e) { throw new OAuthMessageSignerException(e); } }
@Test public void shouldNormalizeRequestUrl() throws Exception { // must include scheme and authority in lowercase letters, // plus non HTTP(S) port, plus path, // but must ignore query params and fragment when(httpGetMock.getRequestUrl()) .thenReturn("HTTP://www.Example.Com:123/test?q=1#fragment"); assertEquals("http://www.example.com:123/test", new SignatureBaseString(httpGetMock, OAUTH_PARAMS).normalizeRequestUrl()); // must exclude HTTP(S) default ports when(httpGetMock.getRequestUrl()).thenReturn("http://example.com:80"); assertEquals("http://example.com/", new SignatureBaseString(httpGetMock, EMPTY_PARAMS) .normalizeRequestUrl()); when(httpGetMock.getRequestUrl()).thenReturn("https://example.com:443"); assertEquals("https://example.com/", new SignatureBaseString(httpGetMock, EMPTY_PARAMS) .normalizeRequestUrl()); }
/** * Builds the signature base string from the data this instance was * configured with. * * @return the signature base string * @throws OAuthMessageSignerException */ public String generate() throws OAuthMessageSignerException { try { String normalizedUrl = normalizeRequestUrl(); String normalizedParams = normalizeRequestParameters(); return request.getMethod() + '&' + OAuth.percentEncode(normalizedUrl) + '&' + OAuth.percentEncode(normalizedParams); } catch (Exception e) { throw new OAuthMessageSignerException(e); } }