forked from spring-attic/spring-social-linkedin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Use a request factory wrapper to put 'x-li-format' header in requests…
… when used with Spring 3.0 that doesn't support request intercepters.
- Loading branch information
Showing
10 changed files
with
167 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
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
80 changes: 80 additions & 0 deletions
80
...ain/java/org/springframework/social/linkedin/api/impl/JsonFormatHeaderRequestFactory.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,80 @@ | ||
/* | ||
* Copyright 2011 the original author or authors. | ||
* | ||
* 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.springframework.social.linkedin.api.impl; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.URI; | ||
|
||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.client.ClientHttpRequest; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
|
||
/** | ||
* @author Craig Walls | ||
*/ | ||
class JsonFormatHeaderRequestFactory implements ClientHttpRequestFactory { | ||
|
||
private final ClientHttpRequestFactory delegate; | ||
|
||
public JsonFormatHeaderRequestFactory(ClientHttpRequestFactory delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { | ||
return new JsonFormatWrappedRequest(delegate.createRequest(uri, httpMethod)); | ||
} | ||
|
||
private static class JsonFormatWrappedRequest implements ClientHttpRequest { | ||
|
||
private final ClientHttpRequest delegate; | ||
|
||
private ByteArrayOutputStream bodyOutputStream; | ||
|
||
public JsonFormatWrappedRequest(ClientHttpRequest delegate) { | ||
this.delegate = delegate; | ||
this.bodyOutputStream = new ByteArrayOutputStream(); | ||
} | ||
|
||
public ClientHttpResponse execute() throws IOException { | ||
byte[] bufferedOutput = bodyOutputStream.toByteArray(); | ||
delegate.getBody().write(bufferedOutput); | ||
delegate.getHeaders().set("x-li-format", "json"); | ||
return delegate.execute(); | ||
} | ||
|
||
public URI getURI() { | ||
return delegate.getURI(); | ||
} | ||
|
||
public HttpMethod getMethod() { | ||
return delegate.getMethod(); | ||
} | ||
|
||
public HttpHeaders getHeaders() { | ||
return delegate.getHeaders(); | ||
} | ||
|
||
public OutputStream getBody() throws IOException { | ||
return bodyOutputStream; | ||
} | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.