Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from simonetripodi/master
Browse files Browse the repository at this point in the history
Jersey Upgrade
  • Loading branch information
jfarcand committed Sep 27, 2012
2 parents 3f185a7 + d966eac commit 0c840e5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 56 deletions.
61 changes: 20 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.sonatype.forge</groupId>
<artifactId>forge-parent</artifactId>
<version>6</version>
<version>12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.spice</groupId>
Expand All @@ -42,6 +42,11 @@
<name>Jeanfrancois Arcand</name>
<email>[email protected]</email>
</developer>
<developer>
<id>simonetripodi</id>
<name>Simone Tripodi</name>
<email>[email protected]</email>
</developer>
</developers>
<licenses>
<license>
Expand All @@ -55,16 +60,19 @@
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<jersey.version>1.14</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.5</version>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.5</version>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
Expand All @@ -75,7 +83,7 @@
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.6.4</version>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
Expand All @@ -98,13 +106,19 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.5</version>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -114,7 +128,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
Expand All @@ -135,7 +148,6 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.1</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>META-INF</manifestLocation>
Expand Down Expand Up @@ -163,7 +175,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>enforce-versions</id>
Expand All @@ -186,31 +197,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
<maxmem>1024m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
Expand All @@ -219,20 +212,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public AsyncHttpClient getHttpClient() {
* @return the {@link ClientResponse}
* @throws ClientHandlerException
*/
@Override
public ClientResponse handle(final ClientRequest cr)
throws ClientHandlerException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ protected void finalize(){
// Do not close the AHCClient.
super.destroy();
} finally {
super.finalize();
try {
super.finalize();
} catch (Throwable e) {
// TODO swallow?
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*******************************************************************************/
package org.sonatype.spice.jersey.client.ahc;

import static com.sun.jersey.api.client.ClientRequest.getHeaderValue;

import com.ning.http.client.PerRequestConfig;
import com.ning.http.client.Request;
import com.ning.http.client.RequestBuilder;
Expand Down Expand Up @@ -52,7 +54,7 @@ public void configureRequest(final RequestBuilder requestBuilder, final ClientRe
re.writeRequestEntity(new CommittingOutputStream(baos) {
@Override
protected void commit() throws IOException {
configureHeaders(cr.getMetadata(), requestBuilder);
configureHeaders(cr.getHeaders(), requestBuilder);
}
});
} catch (IOException ex) {
Expand All @@ -61,13 +63,12 @@ protected void commit() throws IOException {

final byte[] content = baos.toByteArray();
requestBuilder.setBody(new Request.EntityWriter() {
@Override
public void writeEntity(OutputStream out) throws IOException {
out.write(content);
}
});
} else {
configureHeaders(cr.getMetadata(), requestBuilder);
configureHeaders(cr.getHeaders(), requestBuilder);
}
}

Expand All @@ -78,7 +79,7 @@ private void configureHeaders(MultivaluedMap<String, Object> metadata, RequestBu
if (String.class.isAssignableFrom( o.getClass() )) {
requestBuilder.addHeader(e.getKey(), o.toString());
} else {
requestBuilder.addHeader(e.getKey(), headerValueToString(o));
requestBuilder.addHeader(e.getKey(), getHeaderValue(o));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractGrizzlyServerTester extends TestCase {
private SelectorThread selectorThread;

private int port = getEnvVariable("JERSEY_HTTP_PORT", 9997);

private static int getEnvVariable(final String varName, int defaultValue) {
if (null == varName) {
return defaultValue;
Expand All @@ -52,26 +52,26 @@ private static int getEnvVariable(final String varName, int defaultValue) {
public AbstractGrizzlyServerTester(String name) {
super(name);
}

public UriBuilder getUri() {
return UriBuilder.fromUri("http://localhost").port(port).path(CONTEXT);
}
public void startServer(Class... resources) {

public void startServer(Class<?>... resources) {
start(ContainerFactory.createContainer(Adapter.class, resources));
}

public void startServer(ResourceConfig config) {
start(ContainerFactory.createContainer(Adapter.class, config));
}

private void start(Adapter adapter) {
if (selectorThread != null && selectorThread.isRunning()){
stopServer();
}

System.out.println("Starting GrizzlyServer port number = " + port);

URI u = UriBuilder.fromUri("http://localhost").port(port).build();
try {
selectorThread = GrizzlyServerFactory.create(u, adapter);
Expand All @@ -91,13 +91,13 @@ private void start(Adapter adapter) {
}
}
}

public void stopServer() {
if (selectorThread.isRunning()) {
selectorThread.stopEndpoint();
}
}

@Override
public void tearDown() {
stopServer();
Expand Down

0 comments on commit 0c840e5

Please sign in to comment.