我已经设置了一些亚马逊AWS CLI工具(EC2,Auto Scaling,MOnitoring和ELB).工具设置正确,工作完美.我的环境变量都已设置,与此Q相关的是:
export EC2_REGION=eu-west-1
export EC2_URL=https://ec2.$EC2_REGION.amazonaws.com
export AWS_ELB_URL=https://elasticloadbalancing.$EC2_REGION.amazonaws.com
Run Code Online (Sandbox Code Playgroud)
当我ec2-describe-instance-status i-XXXXXXXX为任何实例运行时,我得到:
Client.InvalidInstanceID.NotFound: The instance ID 'i-XXXXXXXX' does not exist
Run Code Online (Sandbox Code Playgroud)
我知道实例ID存在,我将其从AWS Web控制台复制出来,它位于eu-west-1区域,我的env vars设置为此区域.
对于我的生活,我无法弄清楚为什么它找不到我的实例.我做错了有什么明显的明显吗?
更新:由于某种原因,重新创建x509 cert/pk解决了这个问题.
我使用PHP连接到apns以向多个设备发送一些通知,尽管问题更具概念性,因此它不必特定于PHP.
我将同时发送大约7000个设备(并且正在增长).我的进程每天运行ONCE并广播到所有设备,因此我不会不断重新打开连接.
目前,我可以轻松地一次发送到2个设备,并且消息将成功传送.但是,当我尝试发送到完整的7000个设备时,消息似乎无法提供.
我的代码的伪逻辑是:
open connection to apple
loop over device-tokens
write to socket connection per device
end loop
close connection to apple.
Run Code Online (Sandbox Code Playgroud)
我已经看到某个地方我应该只执行一个SINGLE写入,并构造一个巨大的主体,换句话说,伪代码看起来像:
loop over device tokens
create payload aggregating all devices
end loop
open connection to apple
write to socket ONCE with whole payload for 7000 devices
close connection
Run Code Online (Sandbox Code Playgroud)
这很难测试,因为我显然无法通过测试消息向我的7000个生产用户发送垃圾邮件.有没有其他人有类似的问题?
谢谢
我有一个简单的博客应用程序与模型"发布".如果我删除Post模型中的所有条目,当我尝试引用按日期排序的帖子列表中的第一项时,我会收到错误,我这样做:
latest_post = Post.objects.order_by('-date_created')[0]
Run Code Online (Sandbox Code Playgroud)
错误是:IndexError:列表索引超出范围
作为修复,我现在得到这样的项目:
all_posts = Post.objects.order_by('-date_created')
latest_post = ()
if (all_posts):
latest_post = all_posts[0]
Run Code Online (Sandbox Code Playgroud)
如果我的模型"Post"中没有项目,并且没有抛出异常,则此方法有效.但对我来说,这似乎是太多的代码来做一些相当简单的事情.我假设使用django QuerySet API有更好的方法,但在文档中找不到任何内容.
有任何想法吗?
编辑:奇怪的是,当Post模型中没有项目时,这不会引发错误:
latest_post_list = Post.objects.all().order_by('-date_created')[1:10]
Run Code Online (Sandbox Code Playgroud) 我在这个问题上看到了类似的问题,但它们与本机应用程序有关.我为浏览器(Safari)中运行的iPhone/iPad构建了Web应用程序.
我想知道是否有办法防止浏览器中的方向改变,也许是通过一些元标记.我知道视口元标记,它允许您指定缩放和缩放功能,因此可能会有类似的方向.
我怀疑这是可能的,但我想我只是在这里提出一个问题.
我们使用AWS EC2构建了一个网站,并在典型的LAMP堆栈(ubuntu)中自动扩展.
然而,缩放等工作得很好,因为实例是"临时的",我们的apache日志在加载峰值后不会被保留(因为我们不保留卷或实例).
是否有"最佳实践/最可靠"的方法来保留这些实例的apache日志?
一个想法是在关机期间将日志文件复制到S3,方法是编写一个bash脚本以使用该/etc/rc0.d功能执行(在关机时运行脚本).
我已经在互联网的深处搜索过,但在任何地方都找不到合适的答案。如何在 Spring 服务中访问 JWT 中的声明?
\n我们有一个发布 JWT 的独立身份验证服务。我正在构建一个单独的 spring 服务,需要使用这个 Jwt。我拥有用于签署 JWT 的私钥的公钥,并拼凑了足够的教程,以便能够验证 JWT(使用公钥)并允许访问我想要的控制器。
\n在我的服务中,我现在需要提取 JWT(以及其他)中的 userId \xe2\x80\x8bclaim ,以便我可以用它调用我的数据库等。
\nhttps://www.baeldung.com/spring-security-oauth-jwt(第 5.1 节)似乎是最相关的搜索结果:
\n@GetMapping("/user/info")\npublic Map<String, Object> getUserInfo(@AuthenticationPrincipal Jwt principal) {\n Map<String, String> map = new Hashtable<String, String>();\n map.put("user_name", principal.getClaimAsString("preferred_username"));\n map.put("organization", principal.getClaimAsString("organization"));\n return Collections.unmodifiableMap(map);\n}\nRun Code Online (Sandbox Code Playgroud)\n但是,当我的代码运行时,主体始终是null. 我假设我需要在某个地方实现一些其他接口。
我的应用程序中的所有路径都需要身份验证,因此我有:
\n@Configuration\n@EnableResourceServer\npublic class ResourceServerConfig extends ResourceServerConfigurerAdapter {\n@Override\npublic void configure(HttpSecurity http) throws Exception {\n // http.antMatcher("/**").authorizeRequests().anyRequest().permitAll();\n http.csrf().disable()\n .authorizeRequests()\n .antMatchers("/**").authenticated();\n}\nRun Code Online (Sandbox Code Playgroud)\n 我有一个 Spring Boot 微服务,用于验证 JWT(由不同服务颁发)进行身份验证。它运行良好,我可以像这样访问控制器中的 JWT 详细信息:
// build.gradle
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
// MyController.java
@RestController
@RequestMapping("/")
public class MyController {
@GetMapping()
public String someControllerMethod(@AuthenticationPrincipal Jwt jwt) {
int userId = Integer.parseInt(jwt.getClaim("userid"));
...
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好。我可以从 JWT 中提取我需要的内容,然后使用正确的用户 ID 等继续与我的数据库对话。
然而,我发现必须使用 Jwt 类型在每个控制器中获取这些值有点乏味。有没有办法可以注入不同的类型作为@AuthenticationPrincipal?
例如,我自己的类已经从 JWT 中提取了所需的内容,并公开了类似.getUserId()返回 int 的内容?这也让我可以集中解析声明或抛出异常(如果它们不符合预期)的逻辑。
更新
经过更多谷歌洞穴探险后,似乎我有两个选择
选项1:@ControllerAdvice和@ModelAttribute
正如这个答案中所解释的。我可以做类似的事情:
import com.whatever.CustomPrincipal; // a basic "data" class with some properties, getters, setters and constructor
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
@ControllerAdvice
public class SecurityControllerAdvice { …Run Code Online (Sandbox Code Playgroud) 我在这里拔掉我的头发。我想为我的 @ConfigurationProperties 使用 Java 记录,为未指定的配置属性提供默认值。这是一个非常简单的例子:
@ConfigurationProperties(prefix = "myconfig")
public record LoggingProperties (
String whatever,
String somethingToDefault
) {
public LoggingProperties(String whatever, String somethingToDefault) {
this.whatever = whatever;
this.somethingToDefault = somethingToDefault;
}
public LoggingProperties(String whatever) {
this(whatever, "whatever was specified, but not somethingToDefault");
}
public LoggingProperties() {
this("neither was specified", "neither was specified");
}
}
Run Code Online (Sandbox Code Playgroud)
看来,如果我声明一个 noargs 构造函数,spring 总是会调用它,无论我的配置文件(application.yml)中实际有什么
上面将产生一个实例,记录时显示:
LoggingProperties[whatever=neither was specified, somethingToDefault=neither was specified],尽管我的配置已指定。
如果我删除无参数构造函数,我会得到一个异常No default constructor found;
如果我将 @ConstructorBinding 添加到 allargs 构造函数中,我会得到:
LoggingProperties[whatever=value from file, somethingToDefault=null] …
我从谷歌了解到,使用XPath从XML中提取数据比使用DOM循环更有意义.
目前,我已经使用DOM实现了一个解决方案,但是代码很冗长,感觉不整洁且不可维护,所以我想切换到更清洁的XPath解决方案.
假设我有这样的结构:
<products>
<product>
<title>Some title 1</title>
<image>Some image 1</image>
</product>
<product>
<title>Some title 2</title>
<image>Some image 2</image>
</product>
...
</products>
Run Code Online (Sandbox Code Playgroud)
我希望能够为每个<product>元素运行for循环,并在for循环中提取标题和图像节点值.
我的代码看起来像这样:
InputStream is = conn.getInputStream();
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(is);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("/products/product");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList products = (NodeList) result;
for (int i = 0; i < products.getLength(); i++) {
Node n = products.item(i);
if (n != null && n.getNodeType() …Run Code Online (Sandbox Code Playgroud) 首先,如果它是相关的,我使用的是MySQL,虽然我认为解决方案适用于数据库产品.我的问题是:
我有一个单列的简单表.列没有约束.在这一列中有一些简单的数据,例如
a
a
b
c
d
d
Run Code Online (Sandbox Code Playgroud)
我需要获得仅出现一次的值的数量/数量.从上面的示例中可以看出2(因为只有b和c在列中出现一次).
希望很明显我不想要DISTINCT值,而是UNIQUE值.我之前实际上已经这样做了,通过在列上创建一个带有UNIQUE约束的附加表,并简单地从旧表中插入新表,相应地处理重复项.
我希望找到一个不需要临时表的解决方案,并且可以通过一个漂亮的SELECT完成.
我有一个基本的菜单,由一些div和锚建立.然而,在某些情况下,我需要使用表单<input type="submit">(它是移动设备的模板,因此我不能在这里使用javascript ,而不是锚点,我必须使用提交表单数据的提交按钮).
我一直在努力工作几个小时的问题是让输入与锚点具有完全相同的宽度.它们都设置为宽度:50%; 但输入略短于锚点.只是极少,但仍然很明显.我不知道为什么会这样.有人能帮忙解决这个问题吗?我的简化代码如下,问题可以在桌面chrome和firefox以及我测试过的各种手机上重现.
<html>
<head>
<style>
a.btn_bigfake{
display:block;
width:50%;
margin: 0px auto 5px auto;
background:#f5f5f5;
border:4px solid #282726;
text-align: center;
}
input.btn_bigfake{
width:50%;
display:block;
margin: 0px auto 5px auto;
background:#f5f5f5;
border:4px solid #282726;
text-align: center;
padding:0;
}
div{width:100%;}
</style>
</head>
<body style="width:100%; margin:0; padding:0;">
<div><a href="#" class="btn_bigfake">1. anchor</a></div>
<div><a href="#" class="btn_bigfake">2. anchor</a></div>
<div><input type="submit" class="btn_bigfake" value="3. input"/></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) spring ×3
spring-boot ×3
amazon-ec2 ×2
iphone ×2
amazon-elb ×1
autoscaling ×1
aws-cli ×1
css ×1
django ×1
html ×1
input ×1
ipad ×1
java ×1
java-record ×1
jwt ×1
logging ×1
mysql ×1
orientation ×1
php ×1
push ×1
retain ×1
rotation ×1
sql ×1
submit ×1
unique ×1
webkit ×1
width ×1
xpath ×1