我想为现有的一组RESTful API构建Swagger文档.我有以下要求:
到目前为止使用上面的插件我能够实现第1点.所以对于现有的REST方法:
/**
* <p>
* Gets the {@link DisplayPreferenceModel} with the name as provided in the parameter. The preference with the given name defined at the tenant or master level is returned.
* This API gives us the preference if it is eligible for unauthorized access If it is not eligible it throws an Exception saying Authorization required.
* </p>
* @param preferenceName
* - The name of the preference.
* @return {@link …Run Code Online (Sandbox Code Playgroud) 我试图实现Spring Condition org.springframework.context.annotation.Condition如下:
public class APIScanningDecisionMaker implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
// Not able to read the property "swagger.scanner.can.run". It is always NULL.
String canRunFlagInStr = context.getEnvironment().getProperty("swagger.scanner.can.run");
// Ignore the rest of the code.
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如上面的代码所示,当我读取属性"swagger.scanner.can.run"时,它总是为NULL.在我的属性文件中,我将其设置为"swagger.scanner.can.run = false".
我也尝试使用@Value("${swagger.scanner.can.run}")但是甚至返回NULL.当我在这个方法中调试时,我可以看到它正被调用.
只是为了完成我使用APIScanningDecisionMaker如下:
@Configuration
@EnableSwagger
@Conditional(APIScanningDecisionMaker.class)
public class CustomSwaggerConfig {
// Ignore the rest of the code
}
Run Code Online (Sandbox Code Playgroud)
是否有任何理由将"swagger.scanner.can.run"检索为NULL?
我正在使用Spring Swagger库v1.0.2
Maven的:
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>1.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我能够扫描我的REST API并在Swagger UI上查看它.我甚至已经实施了OAuth,它运行良好.
但是,我需要实现一个功能.我想隐藏一些REST API.我需要在类级别以及方法级别执行此操作.我在@Api注释中读到了一个'隐藏'属性.我将它设置为'true'但我仍然可以看到我的类及其所有方法都显示在Swagger UI中.
例:
@Api(
description="This class is not covered by Spring security.",
value="/unauthorize",
hidden=true)
@RequestMapping("/unauthorize")
@Controller
public class UnauthorizeResource {}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何阻止显示"UnauthorizeResource"类吗?
我正在使用像@NotEmpty这样的Hibernate验证器来查看类中的特定属性是否为空.课程如下所示:
@Entity
@Table(name="emergency_messages")
public class EmergencyMessages implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id", nullable=false)
private Integer id;
@NotEmpty(message="Home message cannot be empty")
@Column(name="home_page_message")
private String homePageMessage;
@Range(min=0, max=1, message="Please select one of the display announcement value")
@Column(name="messages_enabled")
private Integer messagesEnabled;
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.每当属性"homePageMessage"为空时,我都可以在浏览器中看到表单中的正确错误消息.
现在情况发生了变化.新要求是,只有当其他属性"messagesEnabled"设置为1时,属性"homePageMessage"才可以为空.如果设置为0,则"homePageMessage"不应进行空检查.简单来说,"homePageMessage"的验证现在应该依赖于"messagesEnabled"值.
我的问题:这可能与注释有关吗?如果没有,那么我将不得不拆除我的hibernate验证器机制并创建我自己的验证类.
我手上有个问题。我不懂 Java 的同事正在使用 OpenSSL 命令对文件进行签名,如下所示:
openssl smime -binary -sign -certfile WWDR.pem -signer passcertificate.pem \
-inkey passkey.pem -in manifest.json -out signature -outform DER \
-passin pass:12345
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这里有三个文件提供给 openssl 命令来生成签名。
现在我们想使用 Java 复制相同的功能,因为我们假设要签名的内容将是动态的并且本质上是服务器端的。我读到 BouncyCastle 是最佳选择。但我不确定如何使用该库。我对密码技术也不是很熟悉。我无法理解如何使用上面的所有三个文件来签署manifest.json.
如果有人可以引导我找到正确的代码或给我一个开始,我将非常感谢您的努力。
我正在Android Jelly Beans OS上创建一个警告对话框.一切都运作良好,但我想要的是,而不是警报对话框的黑色背景,我想要一个透明的背景.我在stackoverflow上阅读了很多文章和用户的问题,但没有一个能帮助我.
这是我的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomAlertDialog);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int which) {
gActivityResult = REQUEST_PICK_CONTACT;
onResume();
return;
} });
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int which) {
return;
} });
View view = getLayoutInflater().inflate(R.layout.alert_dialog, null);
builder.setTitle(R.string.gender_age);
builder.setInverseBackgroundForced(false);
builder.setView (view);
dialog = builder.create ();
Run Code Online (Sandbox Code Playgroud)
这是我的CustomAlertDialog,它在res/values/styles.xml中定义
<style name="CustomAlertDialog" parent="@android:style/Theme.Dialog">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item …Run Code Online (Sandbox Code Playgroud) android android-layout android-alertdialog android-4.2-jelly-bean
Android有没有为垂直搜索栏提供内置配置的原因?我不得不使用http://560b.sakura.ne.jp/android/VerticalSlidebarExample.zip中的代码来使其工作.
我在stackoverflow上读了几个线程,他们建议如下,这显然不适用于我的三星S4和Droid Razr4:
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="270"/>
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?请让我知道你的意见.
谢谢Raj
我有一个 Spring @Configuration 类,它创建并注册 RabbitMQ 队列,如下所示:
@Amqp
@Configuration
public class AmqpConfiguration {
@Bean
ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(HOST);
connectionFactory.setUsername(USERNAME);
connectionFactory.setPassword(PASSWORD);
connectionFactory.addConnectionListener(brokerListener);
return connectionFactory;
}
@Bean
SimpleMessageListenerContainer messageListenerContainer2(ConnectionFactory connectionFactory) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueues(activityQueue());
container.setMessageListener(listener);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setPrefetchCount(Props.getInt(ACTIVITY_QUEUE_PREFETCH_COUNT));
return container;
}
@Bean
AmqpAdmin amqpAdmin() {
return new RabbitAdmin(connectionFactory());
}
@Bean
Queue activityQueue() {
return new Queue(ACITVITY_QUEUE);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。我可以毫无问题地创建一个 ActivityQueue 。
但是,现在我需要动态创建多个活动队列。所以我将代码更改如下(仅显示相关部分):
@Bean
SimpleMessageListenerContainer messageListenerContainer2(ConnectionFactory connectionFactory) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueues(getAllQueues());
container.setMessageListener(listener);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setPrefetchCount(Props.getInt(ACTIVITY_QUEUE_PREFETCH_COUNT)); …Run Code Online (Sandbox Code Playgroud) java ×5
android ×2
spring-mvc ×2
swagger ×2
bouncycastle ×1
cryptography ×1
hibernate ×1
maven ×1
seekbar ×1
spring ×1
spring-amqp ×1
swagger-ui ×1