小编Ami*_*imi的帖子

使用 OkHttp 连接到 HTTPS 代理

我们的环境只允许 HTTPS 连接,因此他们为我们提供了 HTTPS 代理,这是连接到外部世界的唯一方式。我们必须通过此代理以及我们的 Java 应用程序(使用 OkHttp 作为其 HTTP 客户端)路由所有流量。

我们已经像这样设置了代理:

Authenticator proxyAuthenticator = new Authenticator() {
    @Override
    public Request authenticate(Route route, Response response) throws IOException {
        String credential = Credentials.basic(username, password);
        return response.request().newBuilder()
                .header("Proxy-Authorization", credential)
                .build();
    }
};

return builder
        .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)))
        .proxyAuthenticator(proxyAuthenticator)
        .build();
Run Code Online (Sandbox Code Playgroud)

我们使用鱿鱼(作为 HTTP 代理)对其进行了测试。但我们发现这在真实环境中行不通。因为代理是 HTTPS(SSL 或 TLS 隧道?)而不是 HTTP。

我们可以通过设置以下环境变量来强制所有其他 Linux 应用程序(例如wget)使用 https 代理:

export https_proxy='http://domain\user:password@prox-server:port'
Run Code Online (Sandbox Code Playgroud)

但 Java 应用程序无法工作,也无法使用此代理路由流量。

顺便说一句,我们无法通过设置系统属性等来配置 JVM 通过代理http.proxyHost路由http.proxyPort所有https.proxyHost流量https.proxyPort

有没有简单直接的方法来为 …

java ssl tunneling http-proxy okhttp

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

从ASP.NET MVC 3中的RequiredAttribute加入时,客户端验证不起作用?

我在ASP.NET MVC3中创建了一个这样的继承属性:

public sealed class RequiredFromResourceAttribute : RequiredAttribute
{
    public RequiredFromResourceAttribute(string errorResourceName, string errorResourceTypeName)
    {
        this.ErrorMessageResourceName = errorResourceName;
        this.ErrorMessageResourceType = Type.GetType(errorResourceTypeName);
    }
}
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

[RequiredFromResource("Title", "Resources.Resource, MyProject.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
public string Title { get; set; }
Run Code Online (Sandbox Code Playgroud)

它不起作用,MVC忽略了它.然后我创建一个更简单的类,它继承自RequiredAttribute,如下所示:

public class MyRequiredAttribute : RequiredAttribute
{
}
Run Code Online (Sandbox Code Playgroud)

我就像我说的那样使用它.但它没有再起作用.

尽管如此,所有这些方式都完美地适用于"DisplayNameAtrribute".

问题是什么?

asp.net-mvc data-annotations asp.net-mvc-3

5
推荐指数
1
解决办法
1609
查看次数

WPF MDI应用程序中的组合根目录在哪里?

在传统的MDI应用程序中,当命令发生时(例如按下功能区按钮)将创建一些对象(表单),因此它可能是一个组合点.我对这些应用程序中的组合根感到困惑.我在某处读到我们可以使用看起来像Service Locator模式的ViewModelLocator.如您所知,服务定位器模式遭到某些人的谴责.

现在请告诉我这个问题.

提前致谢.

wpf mdi dependency-injection inversion-of-control composition

4
推荐指数
1
解决办法
1123
查看次数

C#代码样式:从"这个"切换.前缀为"下划线"

我一直在使用"这个".前缀约两年(StyleCop SA1102规则).但是现在我正在改变主意并使用"下划线"前缀来表示静态和实例私有字段并删除"this".字首.

在这里我的理由是从"这个"切换."强调":

  1. 容易打破:你团队中的任何人都不会总是使用"这个".前缀所以当你看到一个遵循这种风格的项目时你就不会看到"这个".所有实例成员的前缀.
  2. 无用区分:区分实例和静态字段有什么好处?你有没有获得任何相关的东西?
  3. 噪音:如果你照顾使用"这个".前缀,你会在每个地方看到"这个".例如,我们在一个类中有77次"this"关键字,但在更改我们的样式后,我们只有9个下划线,我认为代码更具可读性(您可以轻松地遵循代码逻辑).
  4. 剃刀:使用"这个"似乎很难看.Razor C#代码中的前缀.例如,你将有"@ this.Html.Something"而不是"@ Html.Something".我们喜欢在所有C#代码中应用的一般规则.

你有什么想法?

忽略StyleCop SA1102规则("this."前缀)并使用"下划线"前缀来区分类字段是否合理?

c# stylecop naming-conventions this

3
推荐指数
1
解决办法
2712
查看次数

如何将存储库注入UnitOfWork?

我已经实现了我的UnitOfWork,以便它保留对所有存储库的引用.

public interface IUnitOfWork
{
   void Commit();
   void RollBack();
}

public interface IMyUnitOfWork : IUnitOfWork
{
   IFooRepository Foos { get; }
   IBarRepository Bars { get; }
   // Other repositories ...
}
Run Code Online (Sandbox Code Playgroud)

请注意,存储库实现了一般类型的存储库接口.

public interface IFooRepository : IRepository<Entities.Foo>
{
    // FooRepository specific methods goes here.
}

public interface IRepository<T> : IRepository
    where T : class
{
}
Run Code Online (Sandbox Code Playgroud)

现在我该如何将这些存储库注入我的UnitOfWork.当然我希望它们具有延迟加载行为.例如:

public class ConcreteUnitOfWork : IMyUnitOfWork
{
   private readonly IUnityContainer unityContainer;
   private IFooRepository fooRepository;

   public ConcreteUnitOfWork(IUnityContainer unityContainer)
   {
      this.repositoryFactory = repositoryFactory;
   }

   public IFooRepository …
Run Code Online (Sandbox Code Playgroud)

dependency-injection repository unit-of-work

3
推荐指数
1
解决办法
312
查看次数