-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from TylerMcCraw/master
Enable additional body types for POST authorization
- Loading branch information
Showing
3 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/com/pusher/client/util/ConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.pusher.client.util; | ||
|
||
/** | ||
* Abstract factory to be used for | ||
* building HttpAuthorizer connections | ||
*/ | ||
public abstract class ConnectionFactory { | ||
private String channelName; | ||
private String socketId; | ||
|
||
public ConnectionFactory() { | ||
} | ||
|
||
public abstract String getBody(); | ||
|
||
public abstract String getCharset(); | ||
|
||
public abstract String getContentType(); | ||
|
||
public String getChannelName() { | ||
return channelName; | ||
} | ||
|
||
public void setChannelName(String channelName) { | ||
this.channelName = channelName; | ||
} | ||
|
||
public String getSocketId() { | ||
return socketId; | ||
} | ||
|
||
public void setSocketId(String socketId) { | ||
this.socketId = socketId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/pusher/client/util/UrlEncodedConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.pusher.client.util; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Form URL-Encoded Connection Factory | ||
* | ||
* Allows HttpAuthorizer to write URL parameters to the connection | ||
*/ | ||
public class UrlEncodedConnectionFactory extends ConnectionFactory { | ||
|
||
private Map<String, String> mQueryStringParameters = new HashMap<String, String>(); | ||
|
||
/** | ||
* Create a Form URL-encoded factory | ||
*/ | ||
public UrlEncodedConnectionFactory() { | ||
} | ||
|
||
/** | ||
* Create a Form URL-encoded factory | ||
* | ||
* @param queryStringParameters extra parameters that need to be added to query string. | ||
*/ | ||
public UrlEncodedConnectionFactory(final Map<String, String> queryStringParameters) { | ||
this.mQueryStringParameters = queryStringParameters; | ||
} | ||
|
||
@Override | ||
public String getCharset() { | ||
return "UTF-8"; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return "application/x-www-form-urlencoded"; | ||
} | ||
|
||
public String getBody() { | ||
final StringBuffer urlParameters = new StringBuffer(); | ||
try { | ||
urlParameters.append("channel_name=").append(URLEncoder.encode(getChannelName(), getCharset())); | ||
urlParameters.append("&socket_id=").append(URLEncoder.encode(getSocketId(), getCharset())); | ||
|
||
// Adding extra parameters supplied to be added to query string. | ||
for (final String parameterName : mQueryStringParameters.keySet()) { | ||
urlParameters.append("&").append(parameterName).append("="); | ||
urlParameters.append(URLEncoder.encode(mQueryStringParameters.get(parameterName), getCharset())); | ||
} | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); | ||
} | ||
return urlParameters.toString(); | ||
} | ||
} |