mirror of https://github.com/apache/jclouds.git
Using an RFC 2068-compliant header for 'trusted' requestors and integration-test-specific settings for the local RunAtCloudServer
This commit is contained in:
parent
0448fcaa9f
commit
d8443bec4d
|
@ -3,6 +3,7 @@ package org.jclouds.demo.tweetstore.config.utils;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.inject.name.Names.bindProperties;
|
||||
import static java.lang.String.format;
|
||||
import static org.jclouds.demo.tweetstore.controller.StoreTweetsController.AUTHORIZED_REQUEST_ORIGINATOR_HEADER;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -31,8 +32,6 @@ public class HttpRequestTask implements Runnable {
|
|||
}
|
||||
|
||||
public static class Factory {
|
||||
private static final String HTTP_REQUEST_ORIGINATOR_HEADER = "X-RUN@cloud-Originator";
|
||||
|
||||
protected final HttpCommandExecutorService httpClient;
|
||||
protected final String originator;
|
||||
|
||||
|
@ -56,7 +55,7 @@ public class HttpRequestTask implements Runnable {
|
|||
public HttpRequestTask create(HttpRequest request) {
|
||||
HttpRequest requestWithSubmitter = request.toBuilder().headers(
|
||||
copyOfWithEntry(request.getHeaders(),
|
||||
HTTP_REQUEST_ORIGINATOR_HEADER, originator)).build();
|
||||
AUTHORIZED_REQUEST_ORIGINATOR_HEADER, originator)).build();
|
||||
return new HttpRequestTask(httpClient, requestWithSubmitter);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ import com.google.common.base.Function;
|
|||
*/
|
||||
@Singleton
|
||||
public class StoreTweetsController extends HttpServlet {
|
||||
public static final String AUTHORIZED_REQUEST_ORIGINATOR_HEADER = "X-RUNatcloud-Originator";
|
||||
|
||||
private static final class StatusToBlob implements Function<Status, Blob> {
|
||||
private final BlobMap map;
|
||||
|
@ -109,8 +110,8 @@ public class StoreTweetsController extends HttpServlet {
|
|||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
if (request.getHeader("X-RUN@cloud-Submitter") != null
|
||||
&& request.getHeader("X-RUN@cloud-Submitter").equals("twitter")) {
|
||||
if (request.getHeader(AUTHORIZED_REQUEST_ORIGINATOR_HEADER) != null
|
||||
&& request.getHeader(AUTHORIZED_REQUEST_ORIGINATOR_HEADER).equals("twitter")) {
|
||||
try {
|
||||
String contextName = checkNotNull(request.getHeader("context"), "missing header context");
|
||||
logger.info("retrieving tweets");
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.demo.tweetstore.integration;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.demo.tweetstore.controller.StoreTweetsController.AUTHORIZED_REQUEST_ORIGINATOR_HEADER;
|
||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||
|
@ -173,13 +174,13 @@ public class TweetStoreLiveTest {
|
|||
}
|
||||
|
||||
@BeforeTest(dependsOnMethods = "clearAndCreateContainers")
|
||||
@Parameters({ "warfile", "bees.address", "bees.port", "bees.environment", "bees.basedir" })
|
||||
@Parameters({ "warfile", "bees.address", "bees.port", "bees.basedir" })
|
||||
public void startDevAppServer(final String warfile, final String address, final String port,
|
||||
String environments, String serverBaseDirectory) throws Exception {
|
||||
String serverBaseDirectory) throws Exception {
|
||||
url = new URL(String.format("http://%s:%s", address, port));
|
||||
|
||||
server = new RunAtCloudServer();
|
||||
server.writePropertiesAndStartServer(address, port, warfile, environments,
|
||||
server.writePropertiesAndStartServer(address, port, warfile, "itest",
|
||||
serverBaseDirectory, props);
|
||||
}
|
||||
|
||||
|
@ -202,7 +203,7 @@ public class TweetStoreLiveTest {
|
|||
for (String context : blobstores) {
|
||||
System.out.println("storing at context: " + context);
|
||||
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection();
|
||||
connection.addRequestProperty("X-RUN@cloud-Submitter", "twitter");
|
||||
connection.addRequestProperty(AUTHORIZED_REQUEST_ORIGINATOR_HEADER, "twitter");
|
||||
connection.addRequestProperty("context", context);
|
||||
InputStream i = connection.getInputStream();
|
||||
String string = Strings2.toStringAndClose(i);
|
||||
|
|
Loading…
Reference in New Issue