小编рüф*_*ффп的帖子

如何模拟 Jersey REST 客户端以抛出 HTTP 500 响应?

我正在编写一个 Java 类,它在底层使用Jersey将 HTTP 请求发送到 RESTful API(第 3 方)。

我还想编写一个 JUnit 测试来模拟 API 发送回 HTTP 500 响应。作为泽西岛的新手,我很难知道我必须做些什么来模拟这些 HTTP 500 响应。

到目前为止,这是我最好的尝试:

// The main class-under-test
public class MyJerseyAdaptor {
    public void send() {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        String uri = UriBuilder.fromUri("http://example.com/whatever").build();
        WebResource service = client.resource(uri);

        // I *believe* this is where Jersey actually makes the API call...
        service.path("rest").path("somePath")
                .accept(MediaType.TEXT_HTML).get(String.class);
    }
}

@Test
public void sendThrowsOnHttp500() {
    // GIVEN
    MyJerseyAdaptor adaptor = new MyJerseyAdaptor(); …
Run Code Online (Sandbox Code Playgroud)

java rest jersey mockito

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

MZ(DOS,16位).EXE标头中的页数和最后页大小的重要性

我试图学习如何使用程序集(NASM)创建Dos .EXE文件,手动构建标头并将文件组装为二进制文件.我的页面选项有问题(页面总数和最后一页的字节数).无论我设置初始值多小,该程序都可以工作.

作为极端情况,即使设置1个1字节的页面,以下程序也会起作用:

;
; the smallest possible "Hello, World!" .EXE (DOS MZ) file
; assemble with:
; nasm -f bin -w+all -O0 smallest_hello_exe.asm -o ASM.EXE
;

bits 16
cpu 8086

;
; by setting cs:ip=-10h:100h instead of 0h:0h inside the .EXE header
; (identical assignments), we achieve the following two advantages:
; 1) ds==cs, so no "push cs pop ds" is needed in order for ds:dx
; to point to the message string
; 2) we can exit by …
Run Code Online (Sandbox Code Playgroud)

assembly dos 16-bit

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

Karaf中的Aries Blueprint - 蓝图可以引用外部属性文件

我正在使用ActiveMQ蓝图来设置JMS连接池.我还使用Camel来提供一些功能.

我使用它org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer来允许在设置文件时使用外部属性camel-context文件.

是否有使用蓝图的类似功能?

基本上,我想用以下配置中的属性文件中的属性替换$ {server.address}:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
        xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
        xmlns:amq="http://activemq.apache.org/schema/core">

        <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
             <property name="brokerURL"
                       value="nio://${server.address}" />
        </bean>

        <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
             <property name="maxConnections" value="8" />
             <property name="connectionFactory" ref="activemqConnectionFactory" />
        </bean>

        <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
             <property name="connectionFactory" ref="pooledConnectionFactory" />
             <property name="concurrentConsumers" value="5" />
        </bean>

        <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager"
             init-method="recoverResource">
             <property name="transactionManager" ref="transactionManager" />
             <property name="connectionFactory" ref="activemqConnectionFactory" />
             <property name="resourceName" value="activemq.localhost" />
        </bean>

        <bean id="xaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
             <argument value="nio://${server.address}" />
        </bean>

        <bean id="connectionFactory" class="org.fusesource.jms.pool.JcaPooledConnectionFactory"
             init-method="start" destroy-method="stop">
             <property name="connectionFactory" ref="pooledConnectionFactory" />
             <property …
Run Code Online (Sandbox Code Playgroud)

apache-camel apache-karaf blueprint-osgi

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

使用 JQuery 或 Javascript 获取设备 ID

有没有办法使用 JQuery/JavaScript 获取设备的唯一 ID。

我知道可以检测正在使用的用户代理和设备类型,但这不是必需的。我需要知道正在使用的唯一 ID。

话虽如此,我也知道浏览器是机器上运行的特权最低的应用程序,它应该能够获得该 ID。

但是还是要问有没有办法?

javascript jquery web-applications signalr hybrid-mobile-app

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

如何在Shiro和CAS中使用单独的领域进行身份验证和授权?

我正在使用一个Web应用程序,其中多个应用程序通过CAS SSO服务器进行身份验证。但是,每个应用程序应保持各自的角色,并且这些角色存储在特定于该应用程序的数据库中。因此,我需要有2个领域,一个领域用于CAS(用于authc),另一个领域用于DB(用于authz)。

这是我当前的Shiro配置。我正在重定向到CAS,但工作正常,但是登录的用户(Subject)似乎没有加载角色/权限(例如,SecurityUtil.isPermitted()不能按预期工作)

<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
        <property name="name" value="jdbcRealm" />
        <property name="dataSource" ref="dataSource" />
        <property name="authenticationQuery"
            value="SELECT password FROM system_user_accounts WHERE username=? and status=10" />
        <property name="userRolesQuery"
            value="SELECT role_code FROM system_roles r, system_user_accounts u, system_user_roles ur WHERE u.user_id=ur.user_id AND r.role_id=ur.role_id AND u.username=?" />
        <property name="permissionsQuery"
            value="SELECT code FROM system_roles r, system_permissions p, system_role_permission rp WHERE r.role_id=rp.role_id AND p.permission_id=rp.permission_id AND r.role_code=?" />

        <property name="permissionsLookupEnabled" value="true"></property>
        <property name="cachingEnabled" value="true" />
        <property name="credentialsMatcher" ref="passwordMatcher" />
    </bean>

    <!-- For CAS -->
    <bean id="casRealm" class="org.apache.shiro.cas.CasRealm"> …
Run Code Online (Sandbox Code Playgroud)

security spring cas shiro

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

是否可以覆盖子类测试脚本中的 junit 规则?

我有一个基本的测试类,我所有的其他测试用例都从它继承而来。

在超类中,我通过以下方式设置了一个全局计时器:

@Rule 
public Timeout globalTimeout = new Timeout(30000);
Run Code Online (Sandbox Code Playgroud)

但是,对于子类中的某些方法,我希望超时时间更长。

例如:

@test(timeout=alongtime)
private void sometTest()
Run Code Online (Sandbox Code Playgroud)

但这似乎根本不影响全局计时器,我通过在全局设置非常短的超时和在子类中设置非常长的超时进行了测试。

有没有办法让 JUnit 遵守在方法上定义的超时?

java junit

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

推动没有阴影和停电的动画

我有一个简单的基于iOS NavigationController的应用程序.二UICollectionViews,一个接一个.如果单击"第一个集合"上的元素,则将打开"第二个集合".非常简单.

重要的提示:

"两者UICollectionViews都有透明背景.使用了一般背景颜色navigationController.(继承类来自UINavigationController) "

问题: 如果理解正确,NavigationController按照算法推送工作方法:

  1. 推送视图已创建.
  2. 推视图上创建透明灰色叠加.
  3. NavigationController使用标准动画推送视图.(仍然有灰色覆盖)
  4. 灰色叠加消失.

(如果推视图具有透明背景,则可以看到灰色垂直线)

截图

下一步: 我试图通过重写push方法来解决这个问题.这是我得到的:

- (void)pushViewController:(UIViewController *)viewController 
                           animated:(BOOL)animated
{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.45;
    transition.timingFunction = [CAMediaTimingFunction 
           functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    transition.fillMode = kCAFillModeForwards;
    transition.delegate = self;
    [self.view.layer addAnimation:transition forKey:nil];

    [super pushViewController:viewController animated:animated];
}
Run Code Online (Sandbox Code Playgroud)

这种方式创建了自己的推送动画,但是使用了另一种标准动画,我无法删除.(在显示和隐藏视图时停电)

Screenshots_1_and_2

问题: "我如何推送ViewController,没有淡入淡出,停电和其他动画过滤器?"

主题名称的解决方案(在 …

objective-c ios ios7

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

Eclipse - 为什么"显示空白"工具栏项在XML编辑器中显示为灰色而在Java编辑器中不显示?

XML:

Xml已选中

Java的:

已选择Java文件

这是一个错误还是一个功能?

不用说,选择XML文件时,快捷方式(Ctrl+ Shift+ Alt+ W)可以正常工作.

使用的软件版本:

面向Web开发人员的Eclipse Java EE IDE.

版本:Luna M7版本(4.4.0M7)版本号:20140508-1440

eclipse eclipse-luna

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

在测试Camel路由时如何正确使用Mocks?

我正在尝试编写一个Camel测试,检查以确保基于内容的路由器正确地路由XML文件.以下是我的blueprint.xml中的enpoints和路由:

<endpoint uri="activemq:queue:INPUTQUEUE" id="jms.queue.input" />
<endpoint uri="activemq:queue:QUEUE1" id="jms.queue.1" />
<endpoint uri="activemq:queue:QUEUE2" id="jms.queue.2" />

<route id="general-jms.to.specific-jms">
    <from ref="jms.queue.input" />
    <choice>
      <when>
        <xpath>//object-type = '1'</xpath>
        <log message="Sending message to queue: QUEUE1" />
        <to ref="jms.queue.1" />
      </when>
      <when>
        <xpath>//object-type = '2'</xpath>
        <log message="Sending message to queue: QUEUE2" />
        <to ref="jms.queue.2" />
      </when>
      <otherwise>
        <log message="No output was able to be determined based on the input." />
      </otherwise>
    </choice>
</route>
Run Code Online (Sandbox Code Playgroud)

现在,我要做的就是发送一个1的示例源文件<object-type>并验证它是否路由到正确的队列(QUEUE1)并且是正确的数据(应该只将整个XML文件发送到QUEUE1) .这是我的测试代码:

public class RouteTest extends CamelBlueprintTestSupport {

    @Override
    protected String getBlueprintDescriptor() …
Run Code Online (Sandbox Code Playgroud)

apache-camel

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

在ServiceMix 6.1.0中使用命令feature:install或features:install时找不到错误的命令

下载Apache ServiceMix 6.1.0并解压缩后。然后启动服务组合。然后输入命令feature:install或features:install。我一直找不到错误命令。从servicemix 6.1.0中删除了执行feature:*或feature:*命令。用以下命令替换了以下功能:*或功能:?如果我们要使用以下命令功能:或功能:*,如何将其添加到服务组合6.1.0中。

command-line-interface apache-servicemix

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