Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use injected HttpClient for loader #122

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.fcrepo.apix.model.Ontologies.Service.PROP_IS_SERVICE_INSTANCE_OF;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
Expand All @@ -42,6 +43,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -95,6 +97,8 @@ public class LoaderIT extends ServiceBasedTest {

final AtomicReference<Object> serviceResponse = new AtomicReference<>();

final AtomicBoolean auth = new AtomicBoolean(false);

@Rule
public TestName name = new TestName();

Expand Down Expand Up @@ -149,6 +153,7 @@ public void setUp() {
ex.setOut(ex.getIn());
if ("OPTIONS".equals(ex.getIn().getHeader(Exchange.HTTP_METHOD))) {
ex.getOut().setBody(optionsResponse.get());
auth.set(ex.getIn().getHeader("Authorization") != null);
} else if ("GET".equals(ex.getIn().getHeader(Exchange.HTTP_METHOD))) {
ex.getOut().setBody(serviceResponse.get());
} else {
Expand All @@ -157,6 +162,22 @@ public void setUp() {
});
}

@Test
public void authTest() throws Exception {

final String SERVICE_CANONICAL = "test:" + name.getMethodName();
final String EXPOSED_AT = SERVICE_CANONICAL;

optionsResponse.set(triple("", RDF_TYPE, CLASS_EXTENSION) +
ltriple("", PROP_EXPOSES_SERVICE_AT, EXPOSED_AT) +
triple("", PROP_EXPOSES_SERVICE, SERVICE_CANONICAL));

attempt(60, () -> textPost(LOADER_URI, serviceEndpoint)).getHeaderValue("Location");

assertTrue(auth.get());

}

@Test
public void htmlMinimalTest() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
auth.http.${fcrepo.dynamic.test.port}.localhost.username = fedoraAdmin
auth.http.${fcrepo.dynamic.test.port}.localhost.password = secret3
auth.http.${apix.dynamic.test.port}.localhost.username = fedoraAdmin
auth.http.${apix.dynamic.test.port}.localhost.password = secret3
auth.http.${apix.dynamic.test.port}.localhost.password = secret3
auth.http.${services.dynamic.test.port}.127.0.0.1.username = fedoraAdmin
auth.http.${services.dynamic.test.port}.127.0.0.1.password = secret3
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void configure() throws Exception {
.setHeader(Exchange.HTTP_URI, header(HEADER_SERVICE_URI))
.setHeader("Accept", constant("text/turtle"))
.process(e -> LOG.info("Execution OPTIONS to service URI {}", e.getIn().getHeader(Exchange.HTTP_URI)))
.to("jetty:http://localhost")
.to("http://localhost?httpClient=#httpClient")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, that's smart. I didn't know you could throw bean refs at it using #

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the param name was the thing we weren't sure whether it was legit, but # works all over.

.process(DEPOSIT_OBJECTS)
.setHeader(HTTP_RESPONSE_CODE, constant(303));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
</cm:default-properties>
</cm:property-placeholder>

<reference id="httpClientFetcher" ext:proxy-method="classes"
interface="org.fcrepo.apix.registry.HttpClientFetcher" />

<bean id="httpClient" factory-ref="httpClientFetcher"
factory-method="getClient" />

<bean id="http" class="org.apache.camel.component.http4.HttpComponent" />
<bean id="https" class="org.apache.camel.component.http4.HttpComponent" />

<reference id="extensionRegistry"
interface="org.fcrepo.apix.model.components.ExtensionRegistry" />

Expand All @@ -31,7 +40,8 @@
<reference id="generalRegistry" filter="(org.fcrepo.apix.registry.role=default)"
interface="org.fcrepo.apix.model.components.Registry" />

<reference id="routing" interface="org.fcrepo.apix.model.components.RoutingFactory" />
<reference id="routing"
interface="org.fcrepo.apix.model.components.RoutingFactory" />

<bean id="loaderService" class="org.fcrepo.apix.loader.impl.LoaderService">
<property name="extensionRegistry" ref="extensionRegistry" />
Expand Down