如何使用Swagger 2.0注释定义基本身份验证并将其显示在swagger UI中.
在我拥有的资源中:
@ApiOperation(value = "Return list of categories", response=Category.class, responseContainer="List", httpMethod="GET", authorizations = {@Authorization(value="basicAuth")})
public Response getCategories();
Run Code Online (Sandbox Code Playgroud)
我看了看这里:
https://github.com/swagger-api/swagger-core/wiki/Annotations#authorization-authorizationscope
并且它说"一旦你声明并配置了你在API中支持的授权方案,你就可以使用这些注释来记录资源或特定操作需要哪种授权方案"但我找不到任何谈论的内容.在哪里声明和配置授权方案.
更新:
我找到了有关如何声明架构的代码,但我仍然没有在UI中看到有关身份验证架构的任何信息.我不确定我错过了什么
@SwaggerDefinition
public class MyApiDefinition implements ReaderListener {
public static final String BASIC_AUTH_SCHEME = "basicAuth";
@Override
public void beforeScan(Reader reader, Swagger swagger) {
}
@Override
public void afterScan(Reader reader, Swagger swagger) {
BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
swagger.addSecurityDefinition(BASIC_AUTH_SCHEME, basicAuthDefinition);
}
}
Run Code Online (Sandbox Code Playgroud) 我想做的很简单.将包含json对象的此数组解析为Javascript数组.
var merchantsJson = JSON.parse('[{"id":61693,"name":"Más"},{"id":61690,"name":"\u0027\u0022\u003C/div\u003E"}]');
Run Code Online (Sandbox Code Playgroud)
但unicode字符似乎打破了解析器.在chrome控制台中,我看到"Uncaught SyntaxError:Unexpected token <"
多一点信息.以上是代码评估的内容.实际上,代码包含一个jsp表达式.
var merchantsJson = JSON.parse('${jsonArr}');
Run Code Online (Sandbox Code Playgroud)
如果我删除单引号,没有问题,但eclipse给我一个"缺少分号"错误消息.是否有可能用我正在尝试的引号解析数组?
我正在使用springfox的swagger实现.我想修改swagger-ui.html以获取自定义标头值.如何修改此文件?或者告诉spring fox使用备用文件?
是否可以创建@RequestMapping仅在某个配置文件处于活动状态时才映射的方法级别?
我知道仅当特定配置文件处于活动状态时才可以创建控制器,但我特指@RequestMapping方法级别的方法
我正在尝试调试 Spring Cloud 配置中遇到的一些问题,但我不确定如何正确设置它的日志记录级别。我尝试将日志记录级别设置"org.springframework.cloud为跟踪,但这似乎没有任何效果。记录 Spring Cloud 的正确包是什么?
更新 我希望看到基本信息,例如是否找到属性。
Update2 这个问题原来与我的 JBoss Appender 有关。我正在设置正确包的日志级别,但控制台附加程序的日志记录级别设置为信息,因此没有记录任何云配置信息。
返回 Hibernate 唯一结果的最简洁方法是null什么?
这个解决方案有什么问题吗:
public Category getCategoryById(int id) {
Object result = currentSession.createCriteria(Category.class)...uniqueResult();
return (Category) result;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点?
我正在使用 Spring MVC,我想从请求标头中获取一些参数,并将它们存储在当前请求期间应用程序中任何位置可用的对象中。想象一个应用程序范围的元数据类。
我想避免使用 RequestContextHolder 因为控制器下面的应用程序的其他部分不应该关心这些值来自请求。它应该是可用的。
我还考虑过使用请求范围的 bean,但随后我必须将它连接到我想要使用它的任何地方。I 反对“只要有它可用”
任何关于从哪里开始的信息都会很棒。
更新:
这是我的想法。我担心当其他请求到来时,他们会设置上一个请求的transactionId。
连接请求作用域 bean:
<bean id="metaDataContextHolder" class="com.yp.common.context.MetadataContextHolder" scope="request">
<aop:scoped-proxy/>
</bean>
Run Code Online (Sandbox Code Playgroud)
这是请求作用域的 bean
public class MetadataContextHolder {
private static String transactionId;
//removed other properties for brevity
public static String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
}
Run Code Online (Sandbox Code Playgroud)
捕获要存储的过滤器中的请求标头以供整个应用程序使用:
public class RequestMetatDataFilter implements Filter
{
@Autowired
MetadataContextHolder metaDataHolder;
@Override
public void init(FilterConfig arg0) throws ServletException
{
}
/**
* This filter will add common request …Run Code Online (Sandbox Code Playgroud) 我想利用邮递员来测试需要使用 RSA 加密对输入字段之一进行加密的 REST API。
我看到邮递员提供了require('crypto-js')使用 AES 加密进行加密的功能,但我该库不提供 RSA 加密。如何使用邮递员自动执行 RSA 加密?
流程如下所示:
调用返回 RSA 公钥的 REST API
将 RSA 公钥存储在变量中
在发送之前使用该公钥加密以下请求中的值
我在spring 4应用程序中添加了一个简单的jaxws配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client name="https://testecommerce.credibanco.com/vpos2/services/VPOSWS20SOAP/authorize" createdFromAPI="true">
<!-- Uncomment if using WS-SecPolicy method -->
<jaxws:properties>
<entry key="ws-security.username" value="myuser"/>
<entry key="ws-security.callback-handler" value-ref="mypassword"/>
</jaxws:properties>
</jaxws:client>
<bean id="myPasswordCallback" class="com..core.ws.security.PWHandler"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]
Run Code Online (Sandbox Code Playgroud)
我能找到的所有信息都说包括我已经完成的依赖:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我也包括这些cxf罐子:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-hc</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.wss4j</groupId>
<artifactId>wss4j-ws-security-common</artifactId>
<version>2.1.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我正在使用jboss EAP 7.我也尝试在JBoss EAP 6.4中运行该应用程序并遇到了同样的问题.我也尝试在jboss-deployment-structure中排除Web服务模块,但这会导致其他错误.
假设我有 2 台使用 Hazelcasts 分布式缓存的服务器。如果在服务器 #1 上,我将 2 个项目存储在该分布式缓存中的地图中。其中一个将保存在本地备份中,另一个将存储在其他服务器 Hazelcast 实例的备份中(如果不正确,请纠正我)。
我的问题是,如果我尝试从缓存中检索第二个项目(存储在服务器 #2 的备份中),将进行 TCP 调用来检索该数据。这比调用数据库快多少?
我正在尝试让当控制器方法响应类型为时spring自动返回HTTP Status 204 void。例如:
假设我有一个像这样的控制器方法:
@DeleteMapping(value = "/{heroId}")
public void delete(@PathVariable Long heroId) {
heroService.delete(heroId);
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种无需使用注释方法即可自动返回204的方法@ResponseStatus(value = HttpStatus.NO_CONTENT)。
是否可以使用处理程序或AOP或其他工具来执行此操作?
PS。我看到了这个答案,使用spring @RestController在null上返回HTTP 204,但是没有回答我的特定问题,即如何对具有void返回类型的方法实现此问题。同样,此方法应与没有输入参数的方法一起使用。
spring ×5
spring-mvc ×3
java ×2
caching ×1
cxf ×1
hazelcast ×1
hibernate ×1
javascript ×1
jboss ×1
jboss7.x ×1
jquery ×1
json ×1
jsp ×1
postman ×1
rsa ×1
spring-boot ×1
spring-cloud ×1
springfox ×1
swagger ×1
swagger-2.0 ×1
swagger-ui ×1
web-services ×1