From b55efd4f3e3014f9c7d78ed90802368dad31f881 Mon Sep 17 00:00:00 2001 From: John Yeary Date: Mon, 9 Oct 2017 18:27:49 -0400 Subject: [PATCH] Initial code commit from 2016 project that has been updated. --- nb-configuration.xml | 21 +++ pom.xml | 169 ++++++++++++++++++ .../jersey/ApplicationImpl.java | 33 ++++ .../jersey/model/ValueHolder.java | 90 ++++++++++ .../resource/FormDataParamResource.java | 93 ++++++++++ src/main/webapp/META-INF/context.xml | 2 + src/main/webapp/WEB-INF/beans.xml | 5 + src/main/webapp/WEB-INF/jboss-web.xml | 4 + src/main/webapp/index.html | 21 +++ 9 files changed, 438 insertions(+) create mode 100644 nb-configuration.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/bluelotussoftware/jersey/ApplicationImpl.java create mode 100644 src/main/java/com/bluelotussoftware/jersey/model/ValueHolder.java create mode 100644 src/main/java/com/bluelotussoftware/jersey/resource/FormDataParamResource.java create mode 100644 src/main/webapp/META-INF/context.xml create mode 100644 src/main/webapp/WEB-INF/beans.xml create mode 100644 src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 src/main/webapp/index.html diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..0bc69ee --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,21 @@ + + + + + + 1.7-web + gfv3ee6 + default_platform + ide + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a387e50 --- /dev/null +++ b/pom.xml @@ -0,0 +1,169 @@ + + + 4.0.0 + com.bluelotussoftware + jaxrs-form-data-parameters + 1.0.0 + war + Jersey MOXy Form Parameters (jaxrs-form-data-parameter) + An example JAX-RS (Jersey 2.x) application that demonstrates how to use MOXy and HTML forms. + + ${project.build.directory}/endorsed + UTF-8 + 2.26 + + 2016 + + Blue Lotus Software, LLC. + http://bluelotussoftware.com + + + + jyeary + John Yeary + jyeary@bluelotussoftware.com + Blue Lotus Software, LLC. + http://www.bluelotussoftware.com + http://javaevangelist.blogspot.com + -6 + + Principal + Architect + Developer + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:git:git://github.com/jyeary/jaxrs-form-data-parameter.git + scm:git:ssh://github.com/jyeary/jaxrs-form-data-parameter.git + https://github.com/jyeary/jaxrs-form-data-parameter + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + provided + + + org.glassfish.jersey.core + jersey-common + ${jersey.version} + + + org.glassfish.jersey.core + jersey-server + ${jersey.version} + + + org.glassfish.jersey.containers + jersey-container-servlet + ${jersey.version} + + + org.glassfish.jersey.media + jersey-media-moxy + ${jersey.version} + + + javax + javaee-web-api + 7.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + ${endorsed.dir} + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + validate + + copy + + + ${endorsed.dir} + true + + + javax + javaee-endorsed-api + 7.0 + jar + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + attach-javadocs + + jar + + + + + true + + http://docs.oracle.com/javase/8/docs/api/ + http://docs.oracle.com/javaee/7/api/ + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + + + diff --git a/src/main/java/com/bluelotussoftware/jersey/ApplicationImpl.java b/src/main/java/com/bluelotussoftware/jersey/ApplicationImpl.java new file mode 100644 index 0000000..a9b02df --- /dev/null +++ b/src/main/java/com/bluelotussoftware/jersey/ApplicationImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Blue Lotus Software, LLC. + * Copyright 2017 John Yeary . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.bluelotussoftware.jersey; + +import javax.ws.rs.ApplicationPath; +import org.glassfish.jersey.server.ResourceConfig; + +/** + * + * @author John Yeary + * @version 1.0.0 + */ +@ApplicationPath("ws") +public class ApplicationImpl extends ResourceConfig { + + public ApplicationImpl() { + packages("com.bluelotussoftware.jersey.resource"); + } +} diff --git a/src/main/java/com/bluelotussoftware/jersey/model/ValueHolder.java b/src/main/java/com/bluelotussoftware/jersey/model/ValueHolder.java new file mode 100644 index 0000000..fde850f --- /dev/null +++ b/src/main/java/com/bluelotussoftware/jersey/model/ValueHolder.java @@ -0,0 +1,90 @@ +/* + * Copyright 2017 Blue Lotus Software, LLC. + * Copyright 2017 John Yeary . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.bluelotussoftware.jersey.model; + +import java.util.Objects; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author John Yeary + */ +@XmlRootElement +public class ValueHolder { + + private String name; + private String value; + + public ValueHolder() { + } + + public ValueHolder(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 29 * hash + Objects.hashCode(this.name); + hash = 29 * hash + Objects.hashCode(this.value); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ValueHolder other = (ValueHolder) obj; + if (!Objects.equals(this.name, other.name)) { + return false; + } + if (!Objects.equals(this.value, other.value)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "ValueHolder{" + "name=" + name + ", value=" + value + '}'; + } + +} diff --git a/src/main/java/com/bluelotussoftware/jersey/resource/FormDataParamResource.java b/src/main/java/com/bluelotussoftware/jersey/resource/FormDataParamResource.java new file mode 100644 index 0000000..068279d --- /dev/null +++ b/src/main/java/com/bluelotussoftware/jersey/resource/FormDataParamResource.java @@ -0,0 +1,93 @@ +/* + * Copyright 2017 Blue Lotus Software, LLC. + * Copyright 2017 John Yeary . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.bluelotussoftware.jersey.resource; + +import com.bluelotussoftware.jersey.model.ValueHolder; +import java.text.MessageFormat; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +/** + * A form parameter contained within a request entity body to a resource method + * parameter example. + * + * @author John Yeary + * @version 1.0.0 + */ +@Path("frm") +public class FormDataParamResource { + + @Context + private UriInfo context; + + /** + * Creates a new instance of FormDataParamResource + */ + public FormDataParamResource() { + } + + /** + * Retrieves representation of an instance of + * resources.FormDataParamResource + * + * @return an empty JSON String. + */ + @GET + @Produces({MediaType.APPLICATION_JSON}) + public Response get() { + return Response.ok("{}", MediaType.APPLICATION_JSON).build(); + } + + /** + * PUT method for updating or creating an instance of FormDataParamResource + * + * @param content representation for the resource + * @return A 202 - Accepted response. + */ + @PUT + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + public Response put(String content) { + return Response.accepted().build(); + } + + @POST + @Produces({MediaType.APPLICATION_JSON}) + @Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.MULTIPART_FORM_DATA}) + public Response post( + @FormParam(value = "name") String name, + @FormParam(value = "value") String value) { + try { + ValueHolder vh = new ValueHolder(name, value); + System.out.println(MessageFormat.format("Submitted values: {0}", vh)); + return Response.status(Response.Status.CREATED).entity(vh).type(MediaType.APPLICATION_JSON).build(); + } catch (Exception ex) { + throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR); + } + } + +} diff --git a/src/main/webapp/META-INF/context.xml b/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000..02fdeed --- /dev/null +++ b/src/main/webapp/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..cc7c587 --- /dev/null +++ b/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,5 @@ + + + diff --git a/src/main/webapp/WEB-INF/jboss-web.xml b/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..f01ffc8 --- /dev/null +++ b/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + /jaxrs-form-data-parameter + diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000..7a6049f --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,21 @@ + + + + Form Data Parameter Example + + + + +

Form Data Parameter Example

+

+ This will return a JSON response with the data submitted if successful. +

+
+ +
+ +
+ +
+ +