我有一点时间在restlet中设置一个cookie,这是我到目前为止所拥有的::
public class CookieTestResource extends ServerResource {
@Post
public Representation post(Representation representation){
CookieSetting cS = new CookieSetting(
1,
"cookieName",
"cookieValue"
);
Series<CookieSetting> cookies = new Series<CookieSetting>(); //<--PROBLEM
cookies.add(cS);
this.setCookieSettings(cookies);
// SEND RESPONSE
setStatus(Status.SUCCESS_OK);
return new StringRepresentation("");
}
}
Run Code Online (Sandbox Code Playgroud)
我现在遇到的问题是我无法实例化一个类型为"org.restlet.util.Series"的类,我找不到任何可以实例化的子类.这似乎是一个愚蠢的问题.但我不知道该怎么做.另外,我似乎经常使用Restlet来解决这个问题.通常我无法弄清楚如何使用API中的这个工具,当我搜索示例时,我找不到.还有其他方法我应该引用Restlets的文档吗?
在restlet中寻找guice支持我遇到了这篇文章 - http://wiki.restlet.org/developers/172-restlet/257-restlet/284-restlet.html
但是 2.0(稳定版)和 2.1(候选发布版)都不包含 org.restlet.ext.guice.jar
所以,我的问题是它的状态是什么?我在哪里可以下载它?我正在使用restlet 2.0
谢谢。
我正在尝试在NetSuite中开发一个简单的表单portlet,提交到后端的RESTlet.这是我的表单portlet:
function workManagerPortlet(portlet, column) {
portlet.setTitle('Portlet');
portlet.addField(....)
// INSERT HERE ALL THE FORM FIELDS
portlet.setSubmitButton(nlapiResolveURL('RESTLET', 'customscript_gw_ss_form_backend', 'customdeploy_wm_form_backend', true), 'Submit', '_hidden');
}
Run Code Online (Sandbox Code Playgroud)
当我点击提交时,我可以在Chrome的开发者控制台中看到状态为206 Partial Content,但我提交的记录没有存储在数据库中,而且在控制台中没有对此请求的响应.
因此,我决定调查与RESTlet的连接.我的问题是我无法通过RESTlet身份验证.这是我的NLAuth标题:
User-Agent:SuiteScript-Call
授权:NLAuth
nlauth_account:TSTDRV1291212
nlauth_email:$ email
nlauth_signature:$ password
nlauth_role:administrator
内容类型:application/json
显然,将'$ email'和'$ password'替换为相应的值.
'nlauth_role'值是Netsuite中的角色ID.
我正在使用Postman来测试这个并且我总是得到" 401 Authorization Required "状态并出现以下错误.
{
"error":
{
"code":"USER_ERROR",
"message":"标题不是NLAuth方案[NLAuth]"
}
}
关于我做错了什么的任何想法?
通过RESTlet创建电话通话活动时出现错误,即使我发送正确的格式也是如此。
Invalid date value (must be M/D/YYYY)
Run Code Online (Sandbox Code Playgroud)
它在Suitescript 1.0中正常工作。电话具有许多标准日期字段,也可以具有自定义日期字段。
如果需要在Restlet中将这些日期字段转换为可接受的格式,则需要标识所有日期和时间类型字段。
还有其他方法可以进行吗?
JSON格式
{
"title":"test",
"startdate":"01/08/2019",
"resourceType":"phonecall"
}
Run Code Online (Sandbox Code Playgroud)
在suitescript 1.0中工作正常
function post(datain) {
var record = nlapiCreateRecord(datain.resourceType);
for (var fieldname in datain) {
if (datain.hasOwnProperty(fieldname)) {
if (fieldname != 'resourceType' && fieldname != 'id') {
var value = datain[fieldname];
record.setFieldValue(fieldname, value);
}
}
}
var recordId = nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG', 'id=' + recordId);
var nlobj = nlapiLoadRecord(datain.resourceType, recordId);
return nlobj;
}
Run Code Online (Sandbox Code Playgroud)
在Suitescript 2.0中不起作用
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/record'],function(record) {
function …Run Code Online (Sandbox Code Playgroud) Restlet框架应该处理自动内容协商; 但是,它似乎没有做得好.
当客户端使用带有值的Accept标头发送HTTP GET请求时,Restlet不会自动协商内容.
有谁知道如何处理Accept标头?
我需要解析以下URL中的参数:http: //mysite.com/customer/token/name/customerName
所以在上面的例子中有两个参数,customer => token和name => customerName.如何从上面的url中检索参数(键的名称)?
谢谢.
我正在使用restlet,我想创建一个登录机制,密码和用户名存储在MysqlDatabase中.
public class zeus extends Application {
@Override
public Restlet createInboundRoot() {
// ?????????? ??? router.
Router router = new Router(getContext());
router.attach("/customers", CustomersResource.class);
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "login required");
UserVerifier verifier = new UserVerifier();
verifier.verify(identifier, secret); // where do i get the identifier ?
guard.setVerifier(verifier);
guard.setNext(router);
return guard;
}
}
Run Code Online (Sandbox Code Playgroud)
和我的用户验证器类
public class UserVerifier extends SecretVerifier {
@Override
public boolean verify(String identifier, char[] secret) {
System.out.println(identifier);
System.out.println(secret);
//TODO compare with the Database
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我找不到如何获取标识符.
我正在尝试使用Restlet 框架获取 POST 发送的参数,但找不到方法。
这是我使用 GET 所做的工作:
@Get
public StringRepresentation represent() {
String search = getQuery().getValues("search");
String folder = getQuery().getValues("folder");
LinkedHashMap<String, String> list = search(search, folder);
return new StringRepresentation(JSONObject.toJSONString(list), MediaType.APPLICATION_JSON);
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能从POST中获取数据?
更新尝试此操作后
仍然无法获取 415 Unsupported Media Type:
@Post("json")
public StringRepresentation represent(Representation entity) {
final Form form = new Form(entity);
String name = form.getFirstValue("search");
return new StringRepresentation(name, MediaType.APPLICATION_JSON);
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,我将使用cURL通过 PHP 发出 POST 请求。
更新 2
通过删除,("json")我不再收到错误消息,但name变量为空。
更新 3
这是我正在使用的 …
我的Restlet似乎在删除循环中的订单项时遇到问题。如果似乎有一条记录总是被跳过。因此,如果三个订单项的ID为111,则只会删除两个。此代码可能是什么问题:
var itemcount = update_record.getLineItemCount('item');
for (var j = 1; j <= itemcount; j++)
{
var lineid = update_record.getLineItemValue('item', 'custcol_line_id', j);
if (lineid == 111)
{
update_record.removeLineItem('item', j);
}
}Run Code Online (Sandbox Code Playgroud)
我有一个使用 Spring Boot 和 Apache Camel 构建的 Web 应用程序,我正在实现一个 REST 接口。目前,使用 Camel 默认Servlet或Restlet组件,我没有在响应中获得 HTTP 状态代码原因。
这是我在将 HTTP 状态代码设置为 403 时得到的示例响应:
< HTTP/1.1 403
< Date: Mon, 19 Feb 2018 10:01:21 GMT
< Server: Restlet-Framework/2.4.0
< Content-Type: application/json
< Content-Length: 75
Run Code Online (Sandbox Code Playgroud)
应该如何:
< HTTP/1.1 403 Forbidden
< Date: Mon, 19 Feb 2018 10:01:21 GMT
< Server: Restlet-Framework/2.4.0
< Content-Type: application/json
< Content-Length: 75
Run Code Online (Sandbox Code Playgroud)
如何配置 Camel/Restlet/Servlet 以在 HTTP 状态代码中包含原因?
我目前的配置:
应用程序.java
@SpringBootApplication
public class Application extends SpringBootServletInitializer { …Run Code Online (Sandbox Code Playgroud) restlet ×10
java ×4
netsuite ×3
restlet-2.0 ×3
javascript ×2
apache-camel ×1
cookies ×1
guice ×1
rest ×1
spring-boot ×1