-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add http support #1746
Conversation
1、do not need to config in springboot env 2、import HttpAutoConfiguration bean for common spring env
Codecov Report
@@ Coverage Diff @@
## develop #1746 +/- ##
=============================================
+ Coverage 54.2% 54.21% +<.01%
- Complexity 2487 2489 +2
=============================================
Files 453 453
Lines 14888 14888
Branches 1755 1755
=============================================
+ Hits 8070 8071 +1
Misses 6045 6045
+ Partials 773 772 -1
|
@wxbty how to use ? DefaultHttpExecutor.get/post ? can you add some test case? |
see attachment
At 2019-10-11 16:24:29, "jimin" <notifications@github.com> wrote:
@wxbty how to use ? DefaultHttpExecutor.get/post ? can you add some test case?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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 io.seata.integration.motan;
import com.google.common.collect.Maps;
import io.seata.core.context.RootContext;
import io.seata.integration.http.DefaultHttpExecutor;
import org.apache.http.HttpResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Map;
/**
* @author jimin.jm@alibaba-inc.com
* @Date 2019/05/27
*/
class HttpTransactionFilterTest {
private static final String host = "http://127.0.0.1:8081";
private static final String path = "/index";
private static final String XID = "127.0.0.1:8081:87654321";
@test
void testGetProviderXID() {
RootContext.bind(XID);
providerStart();
consumerStart();
RootContext.unbind();
}
public void providerStart() {
}
private void consumerStart() {
DefaultHttpExecutor httpExecuter = DefaultHttpExecutor.getInstance();
Map<String, String> params = Maps.newHashMap();
params.put("name", "zhangsan");
try {
HttpResponse response = httpExecuter.excuteGet(null, path, null, HttpResponse.class);
String content = readStreamAsStr(response.getEntity().getContent());
Assertions.assertEquals(content, "hello world!");
} catch (IOException e) {
e.printStackTrace();
}
}
public static String readStreamAsStr(InputStream is) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
WritableByteChannel dest = Channels.newChannel(bos);
ReadableByteChannel src = Channels.newChannel(is);
ByteBuffer bb = ByteBuffer.allocate(4096);
while (src.read(bb) != -1) {
bb.flip();
dest.write(bb);
bb.clear();
}
src.close();
dest.close();
return new String(bos.toByteArray(), "UTF-8");
}
}
|
@wxbty Can you add the test case to this PR? |
if run, must be start a http server by oneself
if run, must be start a http server by oneself
Already added |
@wxbty please associate mail with your Github account.
After that,re-push your commits. |
Found a bug in the case of multiple requests, The reason for troubleshooting is that after the execution of the http interface method, the xid in the thread is not released. Since the tomcat uses the thread pool to handle the connection, the xid is reused, and the xid does not exist on the server. Repair method: release the xid after the interface method is finished, like dubbo
I only need to change the last commit, or close the PR to republish? |
The last commit. |
Already changed |
integration/http/src/test/java/io/seata/integration/http/IndexController.java
Outdated
Show resolved
Hide resolved
integration/http/src/test/java/io/seata/integration/http/HttpTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
integration/http/src/main/java/io/seata/integration/http/TransactionPropagationIntercepter.java
Outdated
Show resolved
Hide resolved
integration/http/src/main/java/io/seata/integration/http/TransactionPropagationIntercepter.java
Outdated
Show resolved
Hide resolved
integration/http/src/main/java/io/seata/integration/http/XidResource.java
Outdated
Show resolved
Hide resolved
integration/http/src/main/java/io/seata/integration/http/XidResource.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
this PR provide support for HTTP calls in global transaction
Ⅱ. Does this pull request fix one issue?
no
Ⅲ. Why don't you add test cases (unit test/integration test)?
1、refer to dubbo way,no test cases
2、need start a http server,It's a bit troublesome ,will be add later
Ⅳ. Describe how to verify it
in AT mode, use customize httpExcutor impl, verify like as dubbo call
Ⅴ. Special notes for reviews
1、do not need to config in springboot env
2、import HttpAutoConfiguration bean for common spring env
3、provider abstract way to expand http call process ,as headers, body,entity and result convert for sign or other features;
4、For the time being, only get and post is supported