我正在构建一个REST API.我的问题是,在使用Jersey时,我的服务构建和返回Response对象或返回bean或集合之间有什么区别.我只关心成功的电话,我正在为错误和特殊情况抛出适当的例外.
这是一个例子:
@Produces(MediaType.APPLICATION_JSON)
public Response search(FooBean foo){
List<FooBean> results = bar.search(foo);
return Response.ok(results).build();
}
Run Code Online (Sandbox Code Playgroud)
与
@Produces(MediaType.APPLICATION_JSON)
public List<FooBean> search(FooBean foo){
List<FooBean> results = bar.search(foo);
return results;
}
Run Code Online (Sandbox Code Playgroud)
我已经看过两个例子,我更喜欢第二种情况,只是为了更容易识别服务方法.我已经检查了对这两种方法的反应,看起来它们是相同的.
思考?
我正在尝试向我的EBS经典负载均衡器添加HTTPS侦听器.我使用CLI upload-certificate工具上传我的证书(使用GUI从未导致证书在负载均衡器表单上显示为选项.没有错误,日志,事件).
我根据AWS文档设置了监听器.
- 对于Listener端口,键入传入流量端口,通常为443.
- 对于Listener协议,请选择HTTPS.
- 对于Instance port,键入80.
- 对于Instance协议,请选择HTTP.
- 对于SSL证书,请选择您的证书.
我选择我的证书(Lets Encrypt),保存,我看到带有Pending Create标签的新听众.它永远不会从该状态转换,如果我刷新页面,记录就会消失.没有错误,没有日志,没有事件.真的想让AWS工作,但是Beanstalk非常错误.有什么建议?
ssl amazon-web-services amazon-elastic-beanstalk elastic-load-balancer
我在servlet中使用HttpClient来调用一些资源,我在一些操作之后作为servlets响应返回.
我的HttpClient使用PoolingHttpClientConnectionManager.
我像这样创建客户端:
private CloseableHttpClient getConfiguredHttpClient(){
return HttpClientBuilder
.create()
.setDefaultRequestConfig(config)
.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
.setConnectionManagerShared(true)
.setConnectionManager(connManager)
.build();
}
Run Code Online (Sandbox Code Playgroud)
我在servlets服务方法中的Try With Resource中使用此客户端,因此它是自动关闭的.要停止关闭连接管理器,我设置setConnectionManagerShared为true.
我见过其他代码示例没有关闭HttpClient.我不应该关闭这个资源吗?
谢谢
在渲染循环中,这两种方法之间应该有什么区别?
苹果有这个说....
关于update() 视图控制器调用其委托的glkViewControllerUpdate:方法.您的代理人应更新不涉及将结果呈现到屏幕的帧数据.
关于drawInRect: GLKView对象使其OpenGL ES上下文成为当前上下文,并将其framebuffer绑定为OpenGL ES呈现命令的目标.然后,您的委托方法应该绘制视图的内容.
所以基本上,当我在我的视图控制器中创建一个GLKView时,该控制器就变成了一个delate,所以我正在并排查看这些方法.
我假设update()应该包含任何变换或其他逻辑.
我正在学习几个不同的 Unity 教程,每个教程中游戏对象的移动方式都略有不同。
这些方法各自的优缺点是什么,对于第一人称 RPG 来说哪种方法更受青睐?
// Here I use MovePosition function on the rigid body of this component
Rigidbody.MovePosition(m_Rigidbody.position + movement);
//Here I apply force to the rigid body and am able to choose force mode
Rigidbody.AddForce(15 * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
// Here I directly change a transforms position value, in this case the cam
Transform.transform.position = playerTransform.position + cameraOffset;
Run Code Online (Sandbox Code Playgroud)
谢谢!!
编辑;
我注意到的一点是,施加的力似乎适用于 memic 轮式车辆,而位置会改变 memic 步行/跑步。
我有一个 SpringBoot 应用程序,可以很好地部署到 AWS Beanstalk,并且默认的 nginx 代理可以正常工作,允许我通过端口 80 进行连接。
按照此处的说明进行操作: https: //docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-singleinstance.html,并使用我的另一个使用此确切配置的项目进行验证,Beanstalk 无法部署应用程序错误:
2020/05/29 01:27:56.418780 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle
我的war文件的内容是这样的:
app.war
-.ebextensions
-nginx/conf.d/https.conf
-https-instance-single.config
-https-instance.config
-web-inf/
Run Code Online (Sandbox Code Playgroud)
我的配置文件作为有效的 yaml 文件传递。(这些文件与 AWS 文档中的文件以及在我的其他项目中使用的文件相同。)
我使用的是单个实例,端口 443 设置为开放。
这些是各个日志文件中报告的错误:
----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2020/05/29 01:37:53.054366 [ERROR] /usr/bin/id: healthd: no such user
...
2020/05/29 01:37:53.254965 [ERROR] Created symlink …Run Code Online (Sandbox Code Playgroud) amazon-ec2 amazon-web-services spring-boot amazon-elastic-beanstalk
这有点奇怪。springdoc-openapi-ui v1.2.32,生成的文档仅包含控制器内的一些映射。
例子:
@Operation(
summary = "Foo",
description = "Foo"
)
@PostMapping(path="/v1/foo")
public ResponseEntity<ResponseObject> postFoo(@RequestBody FooRequestObject searchRequest, HttpServletRequest request){ ... }
@Operation(
summary = "Bar",
description = "Bar"
)
@GetMapping(path="/v1")
public ResponseEntity<ResponseObject> getBar(@RequestBody BarRequestObject request, HttpServletRequest request){ ... }
@Operation(
summary = "Bar",
description = "Bar"
)
@PostMapping(path="/v1")
public ResponseEntity<ResponseObject> postBar(@RequestBody BarRequestObject request, HttpServletRequest request){ ... }
Run Code Online (Sandbox Code Playgroud)
postBar仅针对和服务生成文档getBar,其他路径将被忽略。
我尝试过的:
post. 我重命名是为了避免冲突。如果我向控制器添加另一个服务(带或不带注释标记),它也不会显示在生成的 Swagger 中。例如:
@GetMapping(path="/test")
public String getTest(){
return "test"; …Run Code Online (Sandbox Code Playgroud) 我试图将不同的名称空间分配给不同的 xsd 文件,并使用 jaxb2-maven 插件来构建由这些 xsd 文件定义的工件。
Maven 无法生成源并出现以下错误:The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'
这是我的配置:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:bindings schemaLocation="xsd/TheRequest.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.package.request" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="xsd/TheResponse.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.package.response" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://company.services.com"
xmlns:tns="http://company.services.com"
elementFormDefault="unqualified">
<xsd:complexType name="FindSomething">
<xsd:sequence>
<xsd:element name="TestMode" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="Channel" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="UserId" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="Role" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="Format" …Run Code Online (Sandbox Code Playgroud) 我在 SpringBoot 中部署 websocket 时遇到问题。我已经尝试了很多基于https://spring.io/blog/2013/05/23/spring-framework-4-0-m1-websocket-support的方法,使用Java API for WebSocket(JSR-356)与 Spring Boot等没有任何运气。
这是我正在尝试的:
网络套接字:
@ServerEndpoint(value="/socket/{name}", configurator = SpringConfigurator.class)
public class TestSocket {
public ApiSocket(){}
@OnOpen
public void onOpen(
Session session,
@PathParam("name") String name) throws IOException {
session.getBasicRemote().sendText("Hi " + name);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.属性:
server.contextPath=/api
Run Code Online (Sandbox Code Playgroud)
主要类别:
@SpringBootApplication
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
根据上面的博客文章,这应该就是所需要的。我还尝试了所描述的第二种方法,该方法涉及一个没有运气的豆:
@Bean
public ServerEndpointExporter endpointExporter() {
return new ServerEndpointExporter();
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试打开到 ws://localhost:8080/api/socket/John 的连接,并期望收到带有路径名的响应:
var socket = …Run Code Online (Sandbox Code Playgroud) 下面我展示了父 vue,其中包含一个用于添加新记录(在本例中为用户)的对话框+表单。当表单被取消时,我希望清除输入字段,在本例中,我使用 v-model 将这些字段绑定到数据方法中的用户模板。
我想从父级控制这一点,因为这是对 API 的调用发生的地方,如果保存时出现错误,我想保留对话框表单并显示错误消息,否则我会清除对话框上的表单用于按钮单击。
看过不少例子,似乎都不太靠谱。看起来这应该很简单,但我还没有弄清楚。
父vue
...
<AddUser
:visible="isAddDialogVisible"
:error="error"
v-on:onConfirmed="onAddUserConfirmed"
v-on:onCancelled="onAddUserCancelled"
/>
...
onAddClick: function() {
this.isAddDialogVisible = true;
}
...
onAddUserCancelled () {
this.isAddDialogVisible = false;
}
Run Code Online (Sandbox Code Playgroud)
对话框组件
data() {
return {
user: {}
}
},
props: {
error: {},
visible: {
type: Boolean,
default: false,
}
},
...
onCancel() {
this.$emit("onCancelled");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从XSD-> POJO-> JSON转到要区分大小写的UPS跟踪API。我在生成的JSON中使用Jackson 2.6.7。当我在下面看到时,我看到了骆驼箱的名称:
"TrackRequest": {
"InquiryNumber": "1Z12345E6205277936"
}
生成的Java bean的注释如下:
@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
Run Code Online (Sandbox Code Playgroud)
我尝试了一些映射功能设置,例如USE_WRAPPER_NAME_AS_PROPERTY_NAME和USE_STD_BEAN_NAMING,它们似乎并没有达到预期的效果。
我正在生成JSON,如下所示:
ObjectMapper mapper = new ObjectMapper();
String jsonRequest = mapper.writeValueAsString(upsRequest);
Run Code Online (Sandbox Code Playgroud)
upsRequest bean看起来像这样:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"upsSecurity",
"trackRequest"
})
@XmlRootElement(name = "Request")
public class Request {
@XmlElement(name = "UPSSecurity")
protected UPSSecurity upsSecurity;
@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
/**
* Gets the value of the upsSecurity property.
*
* @return
* possible object is
* {@link UPSSecurity }
* …Run Code Online (Sandbox Code Playgroud) 是否可以在响应中返回错误响应的验证注释消息?我认为这是可能的,但我注意到我们的项目没有给出详细的错误请求消息。
@NotNull(message="idField is required")
@Size(min = 1, max = 15)
private String idField;
Run Code Online (Sandbox Code Playgroud)
如果发出缺少 idField 的请求,我希望看到“需要 idField”。我正在使用球衣 2.0。我看到的回应是这样的......
{
"timestamp": 1490216419752,
"status": 400,
"error": "Bad Request",
"message": "Bad Request",
"path": "/api/test"
}
Run Code Online (Sandbox Code Playgroud) java ×3
spring-boot ×3
jersey ×2
xsd ×2
3d ×1
amazon-ec2 ×1
game-physics ×1
glkit ×1
httpclient ×1
ios ×1
jackson ×1
jax-rs ×1
jaxb ×1
jersey-2.0 ×1
json ×1
jsr356 ×1
maven ×1
openapi ×1
opengl-es ×1
rest ×1
servlets ×1
spring ×1
springdoc ×1
ssl ×1
swagger ×1
vue.js ×1
vuejs2 ×1
vuetify.js ×1
websocket ×1
xjb ×1