http代理服务器(十四)jira bitbucket confluence 修复
十三后 有三个问题:
1 jira上传文件不行
2 git 删除分支不行
3 confluence edit 后save不行
解决:
1 一开始猜测拖入文件上传这个功能与前端有关系,后来发现点击浏览上传文件也有相同错误
那么问题就可以猜测为 Content-type 或者http request body 没传或传错之类的问题
查看代码,发现往后端发送body时,用的竟然是StringEntity,改为同包下ByteArrayEntity后,点击上传,拖入上传和粘贴板上传都修复
2 confluence edit 后save不行
2.1 最初报错
The server didn't respond. You may retry your request when the server comes back up.
发现日志
https://xxx:443/bitbucket/rest/branch-utils/latest/projects/~xxx/repos/xxx/branches
java.lang.RuntimeException: 7DELETE
at com.jds.test.httpproxy.miniserver.HttpServerJob$ProxySender.send(HttpServerJob.java:510)
at com.jds.test.httpproxy.miniserver.HttpServerJob$ReqQueue$Customer.run(HttpServerJob.java:204)
at java.base/java.lang.Thread.run(Thread.java:834)
原来是因为没有处理DELETE代码直接抛异常了
(可以注意到git有超过5次重试,该日志打了5次)
2.2 在post中加入delete代码
if ("HEAD".equals(method) || "GET".equals(method)) {
httpUriRequest = new HttpGet(url);
} else if ("POST".equals(method) || "DELETE".equals(method)) {
httpUriRequest = new HttpPost(url);
HttpPost httpPost = (HttpPost) httpUriRequest;
try {
httpPost.setEntity(new ByteArrayEntity(originHttp.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new RuntimeException(open.intValue() + method);
}
报错:A branch 'startPoint' must be supplied.
然后我想到 delete应该用httpdelete去请求
2.3 加入处理delete代码
if ("HEAD".equals(method) || "GET".equals(method) || "DELETE".equals(method)) {
if("DELETE".equals(method))
httpUriRequest = new HttpDelete(url);
if("GET".equals(method))
httpUriRequest = new HttpGet(url);
if("HEAD".equals(method))
httpUriRequest = new HttpHead(url);
} else if ("POST".equals(method)) {
httpUriRequest = new HttpPost(url);
HttpPost httpPost = (HttpPost) httpUriRequest;
try {
httpPost.setEntity(new ByteArrayEntity(originHttp.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new RuntimeException(open.intValue() + method);
}
发现居然还有HttpHead
继续报错:
No content to map to Object due to end of input
这个时候已经猜测 这个delete有body,抓包后果然有,要删的东西放在body了而没有像get那样放在url
2.4 改为有body的HttpDelete
https://daweini.wordpress.com/2013/12/20/apache-httpclient-send-entity-body-in-a-http-delete-request/ HTTP DELETE does not forbid a entity body, although it is not a common practice.
private static class MyHttpDelete extends HttpEntityEnclosingRequestBase {
public static final String METHOD_NAME = "DELETE";
@Override
public String getMethod() {
return METHOD_NAME;
}
public MyHttpDelete(final String uri) {
super();
setURI(URI.create(uri));
}
}
if ("HEAD".equals(method) || "GET".equals(method)) {
if("DELETE".equals(method))
httpUriRequest = new HttpDelete(url);
if("GET".equals(method))
httpUriRequest = new HttpGet(url);
if("HEAD".equals(method))
httpUriRequest = new HttpHead(url);
} else if ("POST".equals(method) || "DELETE".equals(method)){
if("POST".equals(method))
httpUriRequest = new HttpPost(url);
if("DELETE".equals(method))
httpUriRequest = new MyHttpDelete(url);
HttpPost httpPost = (HttpPost) httpUriRequest;
try {
httpPost.setEntity(new ByteArrayEntity(originHttp.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new RuntimeException(open.intValue() + method);
}
报错 The server didn't respond. You may retry your request when the server comes back up.
日志显示
java.lang.ClassCastException: class com.jds.test.httpproxy.miniserver.HttpServerJob$MyHttpDelete cannot be cast to class org.apache.http.client.methods.HttpPost (com.jds.test.httpproxy.miniserver.HttpServerJob$MyHttpDelete and org.apache.http.client.methods.HttpPost are in unnamed module of loader 'app')
at com.jds.test.httpproxy.miniserver.HttpServerJob$ProxySender.send(HttpServerJob.java:504)
at com.jds.test.httpproxy.miniserver.HttpServerJob$ReqQueue$Customer.run(HttpServerJob.java:207)
2.5
HttpEntityEnclosingRequestBase httpPost = (HttpEntityEnclosingRequestBase) httpUriRequest;
3 confluence报错
Unable to communicate with server. Saving is not possible at the moment.
日志显示
https://xxx/confluence/rest/api/content/xx?status=current
java.lang.RuntimeException: 100PUT
at com.jds.test.httpproxy.miniserver.HttpServerJob$ProxySender.send(HttpServerJob.java:511)
at com.jds.test.httpproxy.miniserver.HttpServerJob$ReqQueue$Customer.run(HttpServerJob.java:207)
at java.base/java.lang.Thread.run(Thread.java:834)
那么把put放上
if ("HEAD".equals(method) || "GET".equals(method)) {
if("DELETE".equals(method))
httpUriRequest = new HttpDelete(url);
if("GET".equals(method))
httpUriRequest = new HttpGet(url);
if("HEAD".equals(method))
httpUriRequest = new HttpHead(url);
} else if ("POST".equals(method) || "DELETE".equals(method) || "PUT".equals(method)){
if("POST".equals(method))
httpUriRequest = new HttpPost(url);
if("DELETE".equals(method))
httpUriRequest = new MyHttpDelete(url);
if("PUT".equals(method))
httpUriRequest = new HttpPut(url);
HttpEntityEnclosingRequestBase httpPost = (HttpEntityEnclosingRequestBase) httpUriRequest;
try {
httpPost.setEntity(new ByteArrayEntity(originHttp.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new RuntimeException(open.intValue() + method);
}
成功
,
浙公网安备 33010602011771号