Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #558 from sonatype/NXCM-4737-include-custom-query-…

…strings-via-builder

[NXCM-4737] hack in query-string customizations via QueryStringBuilder s...
  • Loading branch information...
commit 10a2e32170c324772f42be96ade111cb0f5f3a7c 2 parents 26dae8b + 4ea1078
Jason Dillon jdillon authored
56 nexus/nexus-core-plugins/nexus-rrb-plugin/src/main/java/org/sonatype/nexus/plugins/rrb/QueryStrings.java
View
@@ -0,0 +1,56 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.plugins.rrb;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+// Duplicated from goodies-servlet to hack in fix for NXCM-4737
+
+public class QueryStrings
+{
+ public static final String FIELD_SEPARATOR = "&";
+
+ public static final String VALUE_SEPARATOR = "=";
+
+ // FIXME: Probably should be a Multimap
+
+ /**
+ * Parses a query-string into a map.
+ *
+ * @param input Query-string input ot parse; never null
+ * @return Ordered map of parsed query string parameters.
+ */
+ public static Map<String, String> parse(final String input) {
+ checkNotNull(input);
+ Map<String, String> result = Maps.newLinkedHashMap();
+ String[] fields = input.split(FIELD_SEPARATOR);
+ for (String field : fields) {
+ String key, value;
+ int i = field.indexOf(VALUE_SEPARATOR);
+ if (i == -1) {
+ key = field;
+ value = null;
+ }
+ else {
+ key = field.substring(0, i);
+ value = field.substring(i + 1, field.length());
+ }
+ result.put(key, value);
+ }
+ return result;
+ }
+}
31 ...us-core-plugins/nexus-rrb-plugin/src/main/java/org/sonatype/nexus/plugins/rrb/RemoteBrowserResource.java
View
@@ -13,15 +13,21 @@
package org.sonatype.nexus.plugins.rrb;
import java.net.URLDecoder;
+import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import com.ning.http.client.FluentStringsMap;
+import com.ning.http.client.filter.FilterContext;
+import com.ning.http.client.filter.FilterException;
+import com.ning.http.client.filter.RequestFilter;
import org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.util.StringUtils;
import org.restlet.Context;
import org.restlet.data.Reference;
import org.restlet.data.Request;
@@ -37,6 +43,7 @@
import org.sonatype.nexus.proxy.ResourceStore;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.repository.ProxyRepository;
+import org.sonatype.nexus.proxy.storage.remote.http.QueryStringBuilder;
import org.sonatype.nexus.rest.AbstractResourceStoreContentPlexusResource;
import org.sonatype.nexus.rest.repositories.AbstractRepositoryPlexusResource;
import org.sonatype.plexus.rest.resource.PathProtectionDescriptor;
@@ -63,6 +70,9 @@
@Requirement
private AhcProvider ahcProvider;
+ @Requirement
+ private QueryStringBuilder queryStringBuilder;
+
private final Logger logger = LoggerFactory.getLogger( RemoteBrowserResource.class );
@Override
@@ -155,6 +165,27 @@ protected AsyncHttpClient getHttpClient( final ProxyRepository proxyRepository )
clientConfigBuilder.setFollowRedirects( true );
clientConfigBuilder.setMaximumNumberOfRedirects( 3 );
clientConfigBuilder.setMaxRequestRetry( 2 );
+
+ // HACK: In query string parameters (see NXCM-4737)
+ // FIXME: This should probably be handled in the AhcProvider for all users of legacy AHC client
+ String queryString = queryStringBuilder.getQueryString( proxyRepository.getRemoteStorageContext(), proxyRepository );
+ if ( StringUtils.isNotBlank( queryString ) )
+ {
+ final Map<String,String> parsed = QueryStrings.parse( queryString );
+ clientConfigBuilder.addRequestFilter( new RequestFilter()
+ {
+ @Override
+ public FilterContext filter( final FilterContext filterContext ) throws FilterException {
+ FluentStringsMap queryParams = filterContext.getRequest().getQueryParams();
+ for ( Map.Entry<String,String> entry : parsed.entrySet() )
+ {
+ queryParams.add( entry.getKey(), entry.getValue() );
+ }
+ return filterContext;
+ }
+ });
+ }
+
final AsyncHttpClient client = new AsyncHttpClient( clientConfigBuilder.build() );
return client;
}
Please sign in to comment.
Something went wrong with that request. Please try again.