这是我在Atlassian forums
上提出的问题的副本我一直在尝试使用var csv = require("fast-csv");
var path = require('path');
//Here file implies "example.csv"
csv.fromPath(file[0].path, {
headers:true
//objectMode: true
})
.on("json", function (data) {
Survey.push(data);
})
.on("end", function () {
console.log('data is added');
});
中的Seraph
与我的公司一起为SSO制作我自己的自定义身份验证插件(但是我迟迟不会这样做)但我不能这样做似乎进行远程服务呼叫,因为我找不到Confluence
。
以下是我迄今采取的粗略步骤:
现在我试图获得对RequestFactory SAL
的引用并尝试过,
RequestFactory SAL
ComponentLocator
xml标记(文档已过期且无效)所以,我的问题是,如何在Seraph中进行远程调用component-import
?{/ p>
使用下面的代码时,如果使用RequestFactory
方法,则返回null,当使用依赖注入时,它告诉我该类无法实例化
ComponentLocator
这是迄今为止的代码
定位Caused by: com.atlassian.seraph.config.ConfigurationException: Unable to instantiate class 'com.example.confluence.GluuAuthenticator' : java.lang.InstantiationException: com.example.confluence.MyCustomAuthenticator
at com.atlassian.seraph.config.SecurityConfigImpl.configureClass(SecurityConfigImpl.java:325)
at com.atlassian.seraph.config.SecurityConfigImpl.configureAuthenticator(SecurityConfigImpl.java:258)
at com.atlassian.seraph.config.SecurityConfigImpl.<init>(SecurityConfigImpl.java:194)
at com.atlassian.seraph.config.SecurityConfigFactory.loadInstance(SecurityConfigFactory.java:56)
... 131 more
Caused by: java.lang.InstantiationException: com.example.confluence.MyCustomAuthenticator
at java.lang.Class.newInstance(Class.java:427)
at com.atlassian.seraph.config.SecurityConfigImpl.configureClass(SecurityConfigImpl.java:320)
... 134 more
Caused by: java.lang.NoSuchMethodException: com.example.confluence.MyCustomAuthenticator.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
Confluence 6.4
import com.atlassian.confluence.user.ConfluenceAuthenticator;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.net.Request;
import com.atlassian.sal.api.net.RequestFactory;
import com.atlassian.sal.api.net.ResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.Principal;
public class MyCustomAuthenticator extends ConfluenceAuthenticator {
private static final Logger log = LoggerFactory.getLogger(ConfluenceAuthenticator.class);
private static final String CODE_PARAM_NAME = "code";
@ComponentImport
private final RequestFactory<?> requestFactory;
@Inject
public MyCustomAuthenticator(@ComponentImport RequestFactory<?> requestFactory) {
this.requestFactory = requestFactory;
}
public Principal getUser(HttpServletRequest request, HttpServletResponse response) {
log.debug("SMAuthenticator::getUser(HttpServletRequest request, HttpServletResponse response)");
Principal user = super.getUser(request, response);
String code = request.getParameter(CODE_PARAM_NAME);
if (user != null) {
log.debug("User is already logged in: " +
((user.getName() != null) ? user.getName() : "<None>") );
return (Principal) user;
}
if (code == null) {
log.debug("User is not logged in, and there is no code found in query params, will redirect to gluu");
return (Principal) user;
}
log.info("User is not logged in, but code is found in the query params. Will start the flow to create the user, " +
"starting with verifying the code: " + code);
try {
String s = requestFactory
.createRequest(Request.MethodType.GET, "http://scooterlabs.com/echo")
.addBasicAuthentication(CLIENT_ID, CLIENT_SECRET, "fooooo")
.execute();
log.info("results: " + s);
} catch (ResponseException e) {
e.printStackTrace();
}
return (Principal)user;
}
}
方法就是
ComponentLocator
但是,就像我说的那样,总是返回null也试过ComponentLocator.getComponent(RequestFactory.class);
并且它也返回null
修改
重新阅读Seraph article,我意识到Seraph无法使用依赖注入,并且在寻找其他组件时会有一些注意事项(如PluginSettingsFactory.class
)。
导致
RequestFactory
但是,现在错误已更改为
RequestFactory requestFactory = (RequestFactory)ContainerManager
.getComponent("requestFactory");
也试过
com.atlassian.spring.container.ComponentNotFoundException: Failed to find component: No bean named 'requestFactory' is defined
没有运气,说它无法找到
我可以获得其他组件,例如使用此处的示例,工作正常
RequestFactory requestFactory = (RequestFactory)ContainerManager
.getInstance()
.getContainerContext()
.getComponent(RequestFactory.class);
答案 0 :(得分:0)
所以,对于那些看这个的人来说有一些东西:
这样说,您可以使用HttpUrlConnection
中Java
中的内置版本。它的超级使用但完美。如果有人找到这个帖子,我会放弃在SAL
内使用seraph
的想法
这是一个开始的例子:
try
{
// create the HttpURLConnection
url = new URL(desiredUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// just want to do an HTTP GET here
connection.setRequestMethod("GET");
// uncomment this if you want to write output to this url
//connection.setDoOutput(true);
// give it 15 seconds to respond
connection.setReadTimeout(15*1000);
connection.connect();
// read the output from the server
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
stringBuilder.append(line + "\n");
}
return stringBuilder.toString();
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
来自
的复制/意大利面https://codereview.stackexchange.com/q/185129/157474
但是你可以在网上找到很多关于如何使用这个
的例子