Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.
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
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -138,6 +138,8 @@ private T convert(String value) {
return paramConverter.fromString(value);
} catch (WebApplicationException wae) {
throw wae;
} catch (IllegalArgumentException iae) {
throw iae;
} catch (Exception ex) {
throw new ExtractorException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ private static abstract class AbstractStringReader<T> implements ParamConverter<

@Override
public T fromString(final String value) {
if (value == null) {
throw new IllegalArgumentException("Supplied value is null");
}
try {
return _fromString(value);
} catch (final InvocationTargetException ex) {
Expand Down Expand Up @@ -197,6 +200,9 @@ public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type gen

@Override
public T fromString(final String value) {
if (value == null) {
throw new IllegalArgumentException("Supplied value is null");
}
try {
return rawType.cast(HttpDateFormat.readDate(value));
} catch (final ParseException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -78,18 +78,16 @@ public SingleValueExtractor(ParamConverter<T> converter, String parameterName, S
@Override
public T extract(MultivaluedMap<String, String> parameters) {
String v = parameters.getFirst(getName());
if (v != null) {
try {
return fromString(v);
} catch (WebApplicationException ex) {
throw ex;
} catch (ProcessingException ex) {
throw ex;
} catch (Exception ex) {
throw new ExtractorException(ex);
}
} else {
try {
return fromString(v);
} catch (WebApplicationException ex) {
throw ex;
} catch (ProcessingException ex) {
throw ex;
} catch (IllegalArgumentException ex) {
return defaultValue();
} catch (Exception ex) {
throw new ExtractorException(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type gen

return (ParamConverter<T>) new ParamConverter<URI>() {
public URI fromString(final String value) {
return URI.create(value);
try {
return URI.create(value);
} catch(IllegalArgumentException iae) {
throw new ExtractorException(iae);
}
}

@Override
Expand Down Expand Up @@ -265,6 +269,9 @@ public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type gen
public static class MyAbstractParamConverter implements ParamConverter<MyBean> {
@Override
public MyBean fromString(final String value) throws IllegalArgumentException {
if (value == null) {
throw new IllegalArgumentException("Supplied value is null");
}
if ("fail".equals(value)) {
throw new RuntimeException("fail");
}
Expand Down
94 changes: 94 additions & 0 deletions tests/integration/jersey-2612/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.

The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
http://glassfish.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.

When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.

GPL Classpath Exception:
Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the GPL Version 2 section of the License
file that accompanied this code.

Modifications:
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyright [year] [name of copyright owner]"

Contributor(s):
If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license." If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above. However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.jersey.tests.integration</groupId>
<artifactId>project</artifactId>
<version>2.14-SNAPSHOT</version>
</parent>

<artifactId>jersey-2612</artifactId>
<packaging>war</packaging>
<name>jersey-tests-integration-jersey-2612</name>

<description>Servlet integration test - JERSEY-2612 - SingleValueExtractor makes it impossible to support java.util.Optional (or Guava Optional).</description>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>17.0</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-external</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/

package org.glassfish.jersey.tests.integration.jersey2612;

import org.glassfish.jersey.server.ResourceConfig;

/**
* JAX-RS application for the JERSEY-2612 reproducer test.
*/
public class Jersey2612 extends ResourceConfig {

public Jersey2612() {
register(Resource.class);
register(OptionalParamFeature.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.jersey.tests.integration.jersey2612;

import javax.inject.Singleton;
import javax.ws.rs.ext.ParamConverterProvider;

import org.glassfish.hk2.utilities.binding.AbstractBinder;

final class OptionalParamBinder extends AbstractBinder {

@Override
protected void configure() {
// Param converter providers
bind(OptionalParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}
}
Loading