小编Jay*_*ran的帖子

每隔几分钟(或几秒钟)运行@Schedule注释

我想尝试以下列方式使用@Schedule注释:

public class MyTestServlet extends HttpServlet {
    private static JcanLogger LOG = JcanLoggerFactory.getLogger(ServiceTestServlet.class);

    @EJB CronService cronService;

    public void service(HttpServletRequest req, HttpServletResponse resp) throws .... {
    ....
    cronService.iLive(); 
}
---
    @Local // because the ejb is in a servlet (there is no other jvm)
public interface CronService {

    public void iLive();
    public void runsEveryMinute();
}
---
@Singleton
public class CronServiceBean implements CronService {
    private static final JcanLogger LOG = JcanLoggerFactory.getLogger(CronServiceBean.class);

    @Schedule(minute="*")
    public void runsEveryMinute() {
        LOG.info(" runs EveryMinute ");
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java schedule ejb

23
推荐指数
2
解决办法
3万
查看次数

Azure共享访问签名 - 签名不匹配

我收到这个错误:

<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:6c3fc9a8-cdf6-4874-a141-10282b709022 Time:2014-07-30T10:48:43.8634735Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was rwl 2014-07-31T04:48:20Z /acoustie/$root 2014-02-14
</AuthenticationErrorDetail>
</Error>
Run Code Online (Sandbox Code Playgroud)

我在生成sas(共享访问签名)时得到它,然后将容器uri末尾的sas粘贴到浏览器中.这是生成的sas的完整地址:

https://acoustie.blob.core.windows.net/mark?sv=2014-02-14&sr=c&sig=E6w%2B3B8bAXK8Lhvvr62exec5blSxsA62aSWAg7rmX4g%3D&se=2014-07-30T13%3A30%3A14Z&sp=rwl
Run Code Online (Sandbox Code Playgroud)

我已经搜索了SO和谷歌,并尝试了很多组合,据我所知,我正在做的一切正确,我知道我不是,我只是看不到它...真的希望有人可以提供帮助: - \

为了清楚起见,我在容器上生成一个sas,而不是特定的blob,而不是在根容器上.blob上的访问被定义为Public Blob.我的最终目标是简单地允许使用sas写入容器,而'debugging'我已经为SharedAccessBlobPolicy添加了大部分权限.

我尝试在容器名称的开头和结尾添加\ .没变.

这是我用来生成sas的代码:

    var blobClient = storageAccount.CreateCloudBlobClient();
    //Get a reference to the blob container 
    var container = blobClient.GetContainerReference(containerName);

    // Do not set start time so the sas becomes valid …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-storage-blobs

16
推荐指数
1
解决办法
2万
查看次数

如何获得访问令牌?(Reddit API)

我想知道是否有可能在Reddit上获得永久访问令牌供个人使用?它只会是我使用的应用程序.

对于用户,访问令牌在1小时后到期.

我使用以下有关我的客户端ID和秘密的信息,我尝试尝试获取访问令牌.(MessageBox显示" 错误401 ")

如果用户将获得令牌,则必须在浏览器中单击"允许".这里描述得很好.https://github.com/reddit/reddit/wiki/OAuth2 这不是我追求的.我只是通过代码追求个人使用的访问令牌.这可能吗?

            String requestUrl = "https://ssl.reddit.com/api/v1/access_token";

        RestSharp.RestClient rc = new RestSharp.RestClient();
        RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST);
        request.AddHeader("Content-Type", "application/json");
        //request.AddHeader("Authorization", ""); //???
        request.AddHeader("x-li-format", "json");

        request.AddParameter("client_id", "abcdefg");
        request.AddParameter("client_secret", "abc123-456");
        request.AddParameter("grant_type", "abc123-456");
        request.AddParameter("scope", "identity");
        request.AddParameter("state", "adhasegw"); //whatever value
        request.AddParameter("duration", "permanent");
        request.AddParameter("redirect_uri", "http://mywebsite.co");

        request.RequestFormat = RestSharp.DataFormat.Json;

        RestSharp.RestResponse restResponse = (RestSharp.RestResponse)rc.Execute(request);
        RestSharp.ResponseStatus responseStatus = restResponse.ResponseStatus;



        MessageBox.Show(restResponse.Content.ToString() + "," + responseStatus.ToString());
Run Code Online (Sandbox Code Playgroud)

c# api reddit access-token

15
推荐指数
2
解决办法
2万
查看次数

在哪里可以找到 Azure 应用服务的 docker 容器日志

我确实有一个运行 .net core 2 应用程序的 Docker 容器。

使用此代码配置日志记录 Program.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
            logging.AddDebug();
        })
        .UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)

appsettings.json文件

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
}
Run Code Online (Sandbox Code Playgroud)

日志好像还可以,直接运行Kestrel的时候,可以在终端看到日志。同样的事情,当容器化时:命令docker logs显示了我想要的。

在 Azure Web App 中作为容器运行时,生产中会出现问题。我找不到任何一致的 docker 日志。

我尝试通过 FTP 或通过 urlhttps://[mysite].scm.azurewebsites.net/api/logs/docker访问日志文件,例如,日志文件几乎为空 https://[mysite].scm.azurewebsites.net/api/vfs/LogFiles/2018_09_09_RD0003FF74F63E_docker.log,仅存在容器起始行 在此处输入图片说明

此外,我在通常的门户界面中也有相同的行。

问题是:Azure Web App 的 docker.log 文件中会自动输出 docker 日志吗?有什么我想念的吗?

c# azure docker azure-web-app-service azure-web-app-for-containers

13
推荐指数
2
解决办法
2万
查看次数

如何使用OWIN中间件在Web Api中实现OAuth2 Authorization_Code流程?

我正在尝试创建一个简单的概念验证OAuth启用的应用程序,但我坚持授权代码实现.我读到的每个地方看起来都是这样或那样,从来没有实际使用过授权代码流.我一直在使用以下资源获取信息:

我已经使用自定义OAuthAuthorizationServerProvider设置了web api和owin,以接受刷新令牌的密码授予类型以及为访问令牌交换刷新令牌的功能.这很好用,但我想设置一个场景,我将浏览器重定向到服务器以授权并使用授权代码重定向回客户端.然后,我希望客户端将授权代码发送到令牌端点以获取刷新令牌

在Web Server Apps下的第二个链接中,我正在尝试让我的web api应用程序显示来自请求的授权代码,例如http://127.0.0.1/auth?response_type=code&client_id=123&redirect_uri=http://validredirect .com&scope = access,但我一直得到404.

我已将owin配置如下:

var databaseContext = new AdnsfContext();

WebApp.Start(
    new StartOptions("http://127.0.0.1:7000"),
    appBuilder =>
    {
        var httpConfig = new HttpConfiguration();
        httpConfig.MapHttpAttributeRoutes();
        httpConfig.SuppressDefaultHostAuthentication();
        httpConfig.Filters.Add(new HostAuthenticationFilter("Bearer"));

        appBuilder
            .UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
                {
                    AllowInsecureHttp = true,
                    ApplicationCanDisplayErrors = true,
                    AuthorizeEndpointPath = new PathString("/auth"),
                    TokenEndpointPath = new PathString("/token"),
                    AuthorizationCodeExpireTimeSpan = TimeSpan.FromMinutes(1),
                    AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(1),
                    Provider = new AuthServerProvider(),
                    AuthorizationCodeProvider = new AuthorizationCodeProvider(),
                    RefreshTokenProvider = new RefreshTokenProvider(),
                })
            .UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
                {
                    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
                    AuthenticationType …
Run Code Online (Sandbox Code Playgroud)

c# oauth-2.0 asp.net-web-api owin

10
推荐指数
1
解决办法
2万
查看次数

Azure ServiceBus消息序列化/反序列化

我正在使用应用程序(.Net Core)通过Azure服务总线发送对象并通过Web作业(.Net Core)接收

问题是如何serialize/deserializesend/receive的对象?

我找到了很多关于遗留BroakerMessage.GetBody()接收消息的参考,但不是新的.Net Core方法,请建议,谢谢.

发件人代码:

using Microsoft.Azure.ServiceBus;

MyClass object = new MyClass();
var message = new Message(object);
await queueClient.SendAsync(message);
Run Code Online (Sandbox Code Playgroud)

接收者代码:

using Microsoft.Azure.ServiceBus;

public void ProcessQueueMessage([ServiceBusTrigger("queue")] Message message, TextWriter log)
{
}
Run Code Online (Sandbox Code Playgroud)

c# azure azureservicebus azure-webjobs .net-core

10
推荐指数
1
解决办法
7264
查看次数

在Web API中创建自定义AuthorizeAttribute(.Net Framework)

我在我的WebAPI中使用OAuth2.0 Owin(密码授权).我的初始令牌响应如下所示

{
    "access_token": "_ramSlQYasdsRTWEWew.....................",
    "token_type": "bearer",
    "expires_in": 17999,
    "permissions": {
        "user": [
            "Add",
            "Update",
            "Delete"
        ],
        "Product": [
            "Read",
            "Create"
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

我通过创建一个名为" 持有相应用户权限" 的新密钥来自定义响应permissions.

从这里我需要Resource server通过检查用户是否具有使用授权属性调用API的足够权限来验证来自我的每个请求.

我在这里找到了一个类似的例子,它涉及Dot net Core,这不适合我的情况.

困难的部分是permissionJSON Key本身就是一个复杂的ArrayList

[CustomAuthorize(PermissionItem.Product, PermissionAction.Read)]
    public async Task<IActionResult> Index()
    {
        return View(Index);
    }

public class CustomAuthorize : AuthorizeAttribute {
    public AuthorizeAttribute (PermissionItem item, PermissionAction action) {
        //Need to initalize the Permission Enums
    }
    public override void OnAuthorization (HttpActionContext …
Run Code Online (Sandbox Code Playgroud)

c# authorize-attribute oauth-2.0 asp.net-web-api2

10
推荐指数
1
解决办法
8318
查看次数

除非调用Flush,否则TelemetryClient不会发送任何数据

我在我的代码中直接使用TelemetryClient(v0.17.0.576),看起来我只能在最后手动调用Flush时将数据推送到Azure,这感觉不对.我在这里错过了什么吗?

var configuration = TelemetryConfiguration.CreateDefault();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);

for (int i = 0; i < 10; i++)
{
   log.Information("Loop: {0} {1}", i, value);

   client.Track(new TraceTelemetry(value));
}
client.Flush();
Run Code Online (Sandbox Code Playgroud)

c# azure azure-application-insights

9
推荐指数
1
解决办法
5131
查看次数

如何到内心也许monad从purescript中的html按钮中提取类名?

我正在努力学习purescript.

我在某些HTML中有一个按钮,我正在尝试打印类名.我正在建设和browserifying使用pulp.

我正在使用的函数是querySelector:

import Web.DOM.ParentNode (querySelector)
Run Code Online (Sandbox Code Playgroud)

这会在两个"框"内返回我想要的项目Element:一个外部效果monad和一个嵌入的Maybe monad:

> :type querySelector
QuerySelector -> ParentNode -> Effect (Maybe Element)
Run Code Online (Sandbox Code Playgroud)

我的效果monad看起来像:

getBtn ::  Effect Unit
getBtn = do
  doc <- map toParentNode (window >>= document)
  button <- querySelector (wrap "#btn") doc
  ... Need to extract class name from 'button' here
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过在外部效果monad上调用bind(>> =)来到内部.我的第一个攻击计划是使用可能的功能手动取消装箱.以下是如何为简单的Int执行此操作:

> maybe 0 (\x -> x) $  Just 7
7
Run Code Online (Sandbox Code Playgroud)

对于一个可能的元素,我认为它看起来像:

unboxMaybeElement :: Maybe Element -> Element
unboxMaybeElement …
Run Code Online (Sandbox Code Playgroud)

html purescript

7
推荐指数
1
解决办法
133
查看次数

如何在 Azure Active Directory 中使用多个 OpenIdConnectAuthenticationOptions

在我们的项目中,我们想要显示两个选项(以员工身份登录和以客户身份登录)。根据选择,我们希望使用 Azure Active Directory B2B 或 Azure B2C 对用户进行身份验证。

我可以将身份验证模式设置为被动并在单击链接后打开登录页面。配置单个 OpenIdConnectAuthenticationOptions 时效果很好。但当我配置多个 OpenIdConnectAuthenticationOptions 时,这不起作用。

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Passive,
                MetadataAddress = String.Format(aadInstance2, tenant2, SignUpSignInPolicyId),
                ClientId = clientId2,
                RedirectUri = redirectUri2,
                PostLogoutRedirectUri = postLogoutRedirectUri,
            });

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Passive,
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,
            });

    public void Redirect()
    {
       HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "https://localhost/WebApp1/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
    }
Run Code Online (Sandbox Code Playgroud)

c# azure oauth-2.0 azure-active-directory openid-connect

6
推荐指数
1
解决办法
4443
查看次数