forked from jhunters/JProtobuf-rpc-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
客户端发布API增加对 jprotobuf [https://github.com/jhunters/JProtobuf] 的@protobuf
- Loading branch information
Showing
14 changed files
with
443 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.class |
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
Binary file not shown.
Binary file not shown.
89 changes: 89 additions & 0 deletions
89
src/main/java/com/baidu/jprotobuf/rpc/client/AbstractProxyFactoryBean.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,89 @@ | ||
/* | ||
* Copyright 2002-2007 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 com.baidu.jprotobuf.rpc.client; | ||
|
||
/** | ||
* | ||
* @author xiemalin | ||
* @since 1.1.0 | ||
*/ | ||
public abstract class AbstractProxyFactoryBean { | ||
|
||
/** | ||
* service url | ||
*/ | ||
private String serviceUrl; | ||
|
||
/** | ||
* connection time out | ||
*/ | ||
private int connectTimeout = -1; | ||
|
||
/** | ||
* read time out | ||
*/ | ||
private int readTimeout = -1; | ||
|
||
/** | ||
* set serviceUrl value to serviceUrl | ||
* @param serviceUrl the serviceUrl to set | ||
*/ | ||
public void setServiceUrl(String serviceUrl) { | ||
this.serviceUrl = serviceUrl; | ||
} | ||
|
||
/** | ||
* set connectTimeout value to connectTimeout | ||
* @param connectTimeout the connectTimeout to set | ||
*/ | ||
public void setConnectTimeout(int connectTimeout) { | ||
this.connectTimeout = connectTimeout; | ||
} | ||
|
||
/** | ||
* set readTimeout value to readTimeout | ||
* @param readTimeout the readTimeout to set | ||
*/ | ||
public void setReadTimeout(int readTimeout) { | ||
this.readTimeout = readTimeout; | ||
} | ||
|
||
/** | ||
* get the serviceUrl | ||
* @return the serviceUrl | ||
*/ | ||
protected String getServiceUrl() { | ||
return serviceUrl; | ||
} | ||
|
||
/** | ||
* get the connectTimeout | ||
* @return the connectTimeout | ||
*/ | ||
protected int getConnectTimeout() { | ||
return connectTimeout; | ||
} | ||
|
||
/** | ||
* get the readTimeout | ||
* @return the readTimeout | ||
*/ | ||
protected int getReadTimeout() { | ||
return readTimeout; | ||
} | ||
|
||
|
||
} |
145 changes: 145 additions & 0 deletions
145
src/main/java/com/baidu/jprotobuf/rpc/client/AnnotationProxyFactoryBean.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,145 @@ | ||
/* | ||
* Copyright 2002-2007 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 com.baidu.jprotobuf.rpc.client; | ||
|
||
import org.springframework.beans.factory.FactoryBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
import com.baidu.bjf.remoting.protobuf.Codec; | ||
import com.baidu.bjf.remoting.protobuf.IDLProxyObject; | ||
import com.baidu.bjf.remoting.protobuf.ProtobufProxy; | ||
|
||
/** | ||
* | ||
* @author xiemalin | ||
* @since 1.1.0 | ||
*/ | ||
public class AnnotationProxyFactoryBean<I, O> extends AbstractProxyFactoryBean implements | ||
FactoryBean<ClientInvoker<I, O>>, InitializingBean { | ||
|
||
private IDLHttpClientInvoker invoker; | ||
|
||
private Codec<? extends Object> inputCodec; | ||
private Codec<? extends Object> outputCodec; | ||
|
||
ClientInvoker<I, O> proxy = new ClientInvoker<I, O>() { | ||
|
||
@Override | ||
public I getInput() { | ||
if (inputClass == null) { | ||
return null; | ||
} | ||
try { | ||
return (I) inputClass.newInstance(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public O invoke(I input) throws Exception { | ||
IDLProxyObject inputObject = null; | ||
if (inputClass != null) { | ||
inputObject = new IDLProxyObject(inputCodec, input, inputClass); | ||
} | ||
|
||
IDLProxyObject result = invoker.invoke(inputObject); | ||
if (result == null) { | ||
return null; | ||
} | ||
return (O) result.getTarget(); | ||
} | ||
|
||
}; | ||
|
||
private Class<I> inputClass; | ||
private Class<O> outputClass; | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see org.springframework.beans.factory.FactoryBean#getObject() | ||
*/ | ||
@Override | ||
public ClientInvoker<I, O> getObject() throws Exception { | ||
return proxy; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see org.springframework.beans.factory.FactoryBean#getObjectType() | ||
*/ | ||
@Override | ||
public Class<?> getObjectType() { | ||
return IDLHttpClientInvoker.class; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see org.springframework.beans.factory.FactoryBean#isSingleton() | ||
*/ | ||
@Override | ||
public boolean isSingleton() { | ||
return true; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see | ||
* org.springframework.beans.factory.InitializingBean#afterPropertiesSet() | ||
*/ | ||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
IDLProxyObject inputIDLProxyObject = null; | ||
if (inputClass != null) { | ||
inputCodec = ProtobufProxy.create(inputClass); | ||
I input = inputClass.newInstance(); | ||
inputIDLProxyObject = new IDLProxyObject(inputCodec, input, inputClass); | ||
} | ||
IDLProxyObject outputIDLProxyObject = null; | ||
if (outputClass != null) { | ||
outputCodec = ProtobufProxy.create(outputClass); | ||
O output = outputClass.newInstance(); | ||
outputIDLProxyObject = new IDLProxyObject(outputCodec, output, outputClass); | ||
} | ||
|
||
invoker = new IDLHttpClientInvoker(getServiceUrl(), inputIDLProxyObject, outputIDLProxyObject); | ||
invoker.setConnectTimeout(getConnectTimeout()); | ||
invoker.setReadTimeout(getReadTimeout()); | ||
|
||
} | ||
|
||
/** | ||
* set inputClass value to inputClass | ||
* @param inputClass the inputClass to set | ||
*/ | ||
public void setInputClass(Class<I> inputClass) { | ||
this.inputClass = inputClass; | ||
} | ||
|
||
/** | ||
* set outputClass value to outputClass | ||
* @param outputClass the outputClass to set | ||
*/ | ||
public void setOutputClass(Class<O> outputClass) { | ||
this.outputClass = outputClass; | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.