小编Leo*_* Le的帖子

如何使用Tor与Java结合使用

更新了我的问题

我正在用Java构建一个爬虫系统来在线比较价格.但是,我担心我的IP地址可以被禁止.所以我打算使用代理来更改IP动态或使用一些工具自动轮换IP.

许多人说TOR是一种强大的IP轮换工具.但是,我不知道如何使用Tor以及如何将Tor集成到Java Web Application?

我搜索谷歌找到示例,但仍然没有找到任何有用的东西.

任何人都可以帮助我.

java tor autorotate

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

在 Spring Security 中使用 OAuth2 而不支持 Spring boot

我在不使用 Sprint 启动支持的情况下构建了一个 Web 应用程序。前端是 AngularJS。后端是 Spring MVC restful API。现在我需要使用 OAuth2 和 Spring Security 配置来保护资源并验证用户的凭据。

我花了 2 天多的时间研究如何集成。但是所有示例都显示了构建 Spring Boot Web 安全项目和添加 OAuth2 依赖项(此处此处)的简便性。

问题是我现有的项目确实使用了 Spring Boot。我对大量的 oauth2 和 spring 安全配置感到困惑。

请拯救我的日子。谢谢大家!

java spring spring-security oauth-2.0 angularjs

7
推荐指数
0
解决办法
3540
查看次数

Mockito在春天的间谍对象

当我尝试在单元测试中窥探一个对象时,我得到了一个例外.这是我的单元测试文件:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/applicationContext.xml" })
public class BookingSuperManTest {
    BookInfoParams bookInfoParams; 
    HttpAttributeParams httpAttributeParams;
    AbstractRequester requester;
    public void beforeStartTest(){
        bookInfoParams = Mockito.spy(new BookInfoParams());
        httpAttributeParams = Mockito.spy(new HttpAttributeParams());
    }
    @Test
    public void step1GoToHomePage() throws BookingException{
        beforeStartTest();

        requester = new Step1HomePage(bookInfoParams, httpAttributeParams);
        requester.executeRequest();

        Assert.assertNotNull(httpAttributeParams.getResponseGetRequest());
    }
}
Run Code Online (Sandbox Code Playgroud)

我在链接分配bookInfoParams spy时得到了异常:

java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor
    at org.powermock.api.mockito.internal.mockmaker.PowerMockMaker.<init>(PowerMockMaker.java:43)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:379)
    at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:61)
    at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:24)
    at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:13)
    at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:12)
    at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:23)
    at org.mockito.internal.MockitoCore.<init>(MockitoCore.java:40)
    at org.mockito.Mockito.<clinit>(Mockito.java:1103)
    at ive.core.test.webbot.book.vietjet.BookingSuperManTest.beforeStartTest(BookingSuperManTest.java:46)
    at ive.core.test.webbot.book.vietjet.BookingSuperManTest.step1GoToHomePage(BookingSuperManTest.java:54) …
Run Code Online (Sandbox Code Playgroud)

java spring powermock maven

5
推荐指数
2
解决办法
9040
查看次数

在 JavaMailSender 中设置发件人名称

我正在使用 JavaMailSender 通过我的 Gmail 帐户向我的客户发送电子邮件。在我的 Gmail 帐户设置中,我可以将值设置为“发送邮件为”,以便在我的客户电子邮件中显示我的自定义名称。例如,如果我用 gmail 发送电子邮件,我的客户电子邮件将显示以下内容:

来自:这是我的自定义名称(不是我的电子邮件地址)

至:client-email@mail.com

主题 ...

身体 ...

如何在 Spring 中设置 JavaMailSender 的配置?

这是我的配置文件:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  <property name="host" value="smtp.gmail.com" />
    <property name="port" value="587" />
    <property name="username" value="myemailaddress@gmail.com" />
    <property name="password" value="mypassword@gmail.com" />

    <property name="javaMailProperties">
       <props>
              <prop key="mail.smtp.auth">true</prop>
              <prop key="mail.smtp.starttls.enable">true</prop>
           </props>
    </property>
 </bean>
Run Code Online (Sandbox Code Playgroud)

预先感谢

java email spring

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

无法使用过滤器标签运行 rspec

我有规格

RSpec.describe SearchFlight::Jet::SearchFlightRequest do
  describe 'send search ticket request to Jetstar website', http_request: true do
    context 'search ticket round trip successfully' do
      # initialize
      it 'return status 200' do
        # my expects here ...
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

当我在 iterm 上运行 rspec 时,它无法运行

bundle exec rspec -t ~http_request
zsh: no such user or named directory: http_request
Run Code Online (Sandbox Code Playgroud)

也许它与 zsh 命令行(issue)有关。我尝试从 iTerms 2 中删除 zsh,但没有成功。Rails dev 的任何替代外壳?谢谢

ruby rspec zsh ruby-on-rails

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

Web应用程序ASP.NET MVC的调度程序

我已经构建了一个ASP.NET MVC的网站应用程序,可以帮助用户获取RSS新闻.当然,它完美无缺.但是,我想在每天早上6点将网站自动发送热门新闻的功能扩展到用户的电子邮件中.

我在互联网上找到了解决方案,但我仍然混淆在Windows中使用Quartz.NET,Windows服务和Schedule.

请告诉我应该从哪里开始!

非常感谢 !

asp.net-mvc windows-services web-applications quartz.net

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

rails 5 - 通过ActionCable为每个对话创建频道

我是一个新的Rails开发人员,并开始在Rails 5中使用ActionCable来创建一个聊天应用程序.

问题是因特网上有许多使用ActionCable的聊天示例,但所有这些都非常简单.他们创建了一个频道,所有连接到此频道的用户都可以发送或阅读来自他人的消息.

例如,他们创建一个聊天频道,如下所示:

class ChatChannel < ApplicationCable::Channel
  def subscribed
    stream_from 'messages'
  end

  def speak(data)
    ActionCable.server.broadcast('messages',
      message: render_message(data['message']))
  end

  private

  def render_message(message)
    ApplicationController.render(partial: 'messages/message',
                                 locals: { message: message })
  end
end
Run Code Online (Sandbox Code Playgroud)

在客户端,他们连接到该频道

App.chat = App.cable.subscriptions.create "ChatChannel",
  received: (data) ->
    $('#messages').append(data.message)

  speak: (msg) ->
    @perform 'speak', message: msg
Run Code Online (Sandbox Code Playgroud)

如何在2个用户之间为每个对话创建一个频道?

chat ruby-on-rails websocket actioncable

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

获取Orchard CMS中PartialView的链接

我想在Orchard CMS中将RazorView渲染为字符串,但我不知道如何获取链接到部分视图以获取字符串.

public string RenderRazorViewToString(string viewName, object model)
        {
            ViewData.Model = model;
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
Run Code Online (Sandbox Code Playgroud)

如果在另一个MVC项目 - 而不是Orchard - 它可以正常使用代码:

string result = RenderRazorViewToString("~/Views/Home/PartialViewEmail.cshtml", null);
Run Code Online (Sandbox Code Playgroud)

但是在Orchard CMS中,它不知道从哪里获得部分视图.

我该怎么办 ?

非常感谢 !

asp.net-mvc content-management-system asp.net-mvc-partialview orchardcms razor

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

在 rspec 中运行测试组

我的应用程序有一些使用 httparty 服务从另一个网站获取数据的功能。所以运行http函数的测试需要很多时间。

- spec
-- services
--- http_request
---- test_http_a_spec.rb
---- test_http_b_spec.rb
--- component
---- test_component_c_spec.rb
---- test_component_d_spec.rb
--- models
---- test_model_e_spec.rb
Run Code Online (Sandbox Code Playgroud)

那么如何为除http_request文件夹中的测试之外的所有测试运行 rspec 测试?谢谢

ruby rspec ruby-on-rails

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