Skip to content

Commit 6d29fd6

Browse files
committed
Initial code drop.
0 parents  commit 6d29fd6

File tree

787 files changed

+107915
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

787 files changed

+107915
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# maven noise
2+
target/
3+
4+
# osx noise
5+
.DS_Store
6+
profile
7+
8+
#IntelliJ Idea noise
9+
*.iws
10+
*.ipr
11+
*.iml
12+
nbactions.xml
13+
/nb-configuration.xml

archetypes/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Jersey archetypes.

bundles/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Jersey distribution bundles.

connectors/pom.xml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2011-2012 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
45+
<modelVersion>4.0.0</modelVersion>
46+
47+
<parent>
48+
<groupId>org.glassfish.jersey</groupId>
49+
<artifactId>project</artifactId>
50+
<version>2.0-SNAPSHOT</version>
51+
</parent>
52+
53+
<groupId>org.glassfish.jersey.connectors</groupId>
54+
<artifactId>project</artifactId>
55+
<packaging>pom</packaging>
56+
<name>jersey-connectors</name>
57+
58+
<description>Jersey client connection providers umbrella project module</description>
59+
60+
<modules>
61+
<!--module></module-->
62+
</modules>
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.glassfish.jersey.core</groupId>
67+
<artifactId>jersey-common</artifactId>
68+
<version>${project.version}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.glassfish.jersey.core</groupId>
72+
<artifactId>jersey-client</artifactId>
73+
<version>${project.version}</version>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>javax.ws.rs</groupId>
78+
<artifactId>javax.ws.rs-api</artifactId>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>junit</groupId>
83+
<artifactId>junit</artifactId>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
87+
</project>

containers/grizzly2-http/pom.xml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2011-2012 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
45+
<modelVersion>4.0.0</modelVersion>
46+
47+
<parent>
48+
<groupId>org.glassfish.jersey.containers</groupId>
49+
<artifactId>project</artifactId>
50+
<version>2.0-SNAPSHOT</version>
51+
</parent>
52+
53+
<artifactId>jersey-container-grizzly2-http</artifactId>
54+
<packaging>jar</packaging>
55+
<name>jersey-container-grizzly2-http</name>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.glassfish.grizzly</groupId>
60+
<artifactId>grizzly-http-server</artifactId>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<resources>
66+
<resource>
67+
<directory>${basedir}/src/main/java</directory>
68+
<includes>
69+
<include>META-INF/**/*</include>
70+
</includes>
71+
</resource>
72+
<resource>
73+
<directory>${basedir}/src/main/resources</directory>
74+
<filtering>true</filtering>
75+
</resource>
76+
</resources>
77+
</build>
78+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.glassfish.jersey.grizzly2.GrizzlyHttpContainerProvider
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.grizzly2;
41+
42+
import org.glassfish.grizzly.http.server.HttpHandler;
43+
import org.glassfish.grizzly.http.server.Request;
44+
import org.glassfish.grizzly.http.server.Response;
45+
import org.glassfish.grizzly.utils.Charsets;
46+
import org.glassfish.jersey.message.internal.Requests;
47+
import org.glassfish.jersey.server.Application;
48+
import org.glassfish.jersey.server.ContainerResponseWriter;
49+
50+
import javax.ws.rs.core.HttpHeaders;
51+
import javax.ws.rs.core.Request.RequestBuilder;
52+
import javax.ws.rs.core.UriBuilder;
53+
import java.io.IOException;
54+
import java.io.OutputStream;
55+
import java.net.URI;
56+
import java.net.URISyntaxException;
57+
import java.util.List;
58+
import java.util.Map;
59+
60+
/**
61+
*
62+
* Grizzly 2 Jersey HTTP Container Prototype
63+
*
64+
* @author Jakub Podlesak
65+
*/
66+
public final class GrizzlyHttpContainer extends HttpHandler {
67+
68+
private final static class Writer implements ContainerResponseWriter {
69+
70+
final Response grizzlyResponse;
71+
72+
Writer(final Response response) {
73+
this.grizzlyResponse = response;
74+
}
75+
76+
@Override
77+
public void finish() throws IOException {
78+
}
79+
80+
@Override
81+
public OutputStream writeStatusAndHeaders(final long contentLength,
82+
final javax.ws.rs.core.Response jaxrsResponse) throws IOException {
83+
84+
grizzlyResponse.setStatus(jaxrsResponse.getStatus());
85+
86+
for (final Map.Entry<String, List<String>> e : jaxrsResponse.getHeaders().asMap().entrySet()) {
87+
for (final String value : e.getValue()) {
88+
grizzlyResponse.addHeader(e.getKey(), value);
89+
}
90+
}
91+
92+
final String contentType = jaxrsResponse.getHeaders().getHeader(HttpHeaders.CONTENT_TYPE);
93+
if (contentLength > 0 && contentType != null) {
94+
grizzlyResponse.setContentType(contentType);
95+
}
96+
97+
return grizzlyResponse.getOutputStream();
98+
}
99+
}
100+
//
101+
private Application application;
102+
103+
/**
104+
* Creates a new Grizzly container.
105+
*
106+
* @param application Jersey application to be deployed on Grizzly container.
107+
*/
108+
GrizzlyHttpContainer(final Application application) {
109+
this.application = application;
110+
}
111+
112+
// HttpRequestProcessor
113+
@Override
114+
public void service(final Request request, final Response response) {
115+
application.apply(toJaxrsRequest(request), new Writer(response));
116+
response.finish();
117+
}
118+
119+
private URI getBaseUri(final Request request) {
120+
try {
121+
return new URI(request.getScheme(), null, request.getServerName(),
122+
request.getServerPort(), getBasePath(request), null, null);
123+
} catch (final URISyntaxException ex) {
124+
throw new IllegalArgumentException(ex);
125+
}
126+
}
127+
128+
private String getBasePath(final Request request) {
129+
final String contextPath = request.getContextPath();
130+
131+
if (contextPath == null || contextPath.length() == 0) {
132+
return "/";
133+
} else if (contextPath.charAt(contextPath.length() - 1) != '/') {
134+
return contextPath + "/";
135+
} else {
136+
return contextPath;
137+
}
138+
}
139+
140+
private javax.ws.rs.core.Request toJaxrsRequest(Request grizzlyRequest) {
141+
142+
final URI baseUri = getBaseUri(grizzlyRequest);
143+
144+
// TODO: this is terrible, there must be a way to obtain the original request URI!
145+
String originalURI = UriBuilder.fromPath(
146+
grizzlyRequest.getRequest().getRequestURIRef().getOriginalRequestURIBC().toString(Charsets.DEFAULT_CHARSET)).build().toString();
147+
148+
String queryString = grizzlyRequest.getQueryString();
149+
if (queryString != null) {
150+
originalURI = originalURI + "?" + queryString;
151+
}
152+
153+
final URI requestUri = baseUri.resolve(originalURI);
154+
155+
final String method = grizzlyRequest.getMethod().getMethodString();
156+
157+
RequestBuilder rb = Requests.from(baseUri, requestUri, method).entity(grizzlyRequest.getInputStream());
158+
159+
for (String name : grizzlyRequest.getHeaderNames()) {
160+
for (String value : grizzlyRequest.getHeaders(name)) {
161+
rb.header(name, value);
162+
}
163+
}
164+
165+
return rb.build();
166+
}
167+
}

0 commit comments

Comments
 (0)