Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 65ABB187B0 for ; Fri, 19 Jun 2015 16:50:59 +0000 (UTC) Received: (qmail 99598 invoked by uid 500); 19 Jun 2015 16:50:59 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 99543 invoked by uid 500); 19 Jun 2015 16:50:59 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 99534 invoked by uid 99); 19 Jun 2015 16:50:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jun 2015 16:50:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F27E3E0427; Fri, 19 Jun 2015 16:50:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <9b91a4206c2a4f16b16452128bbc0d56@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: Adding a grant MBW Date: Fri, 19 Jun 2015 16:50:58 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 0abaf3cbe -> fb39ed65c Adding a grant MBW Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fb39ed65 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fb39ed65 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fb39ed65 Branch: refs/heads/3.0.x-fixes Commit: fb39ed65c83655763208755383b66f739b50ba92 Parents: 0abaf3c Author: Sergey Beryozkin Authored: Fri Jun 19 17:49:15 2015 +0100 Committer: Sergey Beryozkin Committed: Fri Jun 19 17:50:41 2015 +0100 ---------------------------------------------------------------------- .../oauth2/client/AccessTokenGrantWriter.java | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/fb39ed65/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenGrantWriter.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenGrantWriter.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenGrantWriter.java new file mode 100644 index 0000000..5654a71 --- /dev/null +++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AccessTokenGrantWriter.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.cxf.rs.security.oauth2.client; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; + +import org.apache.cxf.jaxrs.utils.FormUtils; +import org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant; + +@Produces(MediaType.APPLICATION_FORM_URLENCODED) +public class AccessTokenGrantWriter implements MessageBodyWriter { + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return true; + } + + @Override + public long getSize(AccessTokenGrant t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType) { + return -1; + } + + @Override + public void writeTo(AccessTokenGrant t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + OutputStream entityStream) throws IOException, WebApplicationException { + String form = FormUtils.formToString(new Form(t.toMap())); + entityStream.write(form.getBytes()); + } + +}