/*
* JBoss, Home of Professional Open Source
*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* 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 org.picketlink.oauth.messages;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.PropertyNamingStrategy;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Base class for OAuth Request and Response messages
*
* @author anil saldhana
* @since Mar 6, 2013
*/
public abstract class OAuthMessage implements Serializable {
private static final long serialVersionUID = 5685834408814739226L;
/**
* Represent the message as JSON
*
* @return
*/
public abstract String asJSON();
/**
* Represent the message as Query Parameters
*
* @return
*/
public abstract String asQueryParams();
protected String encode(String elem) {
try {
return URLEncoder.encode(elem, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
protected ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
return mapper;
}
}