小编Pau*_*tha的帖子

使用Jersey 2.0进行依赖注入

从头开始没有任何以前的Jersey 1.x知识,我很难理解如何在我的Jersey 2.0项目中设置依赖注入.

我也明白HK2可用于Jersey 2.0,但我似乎无法找到有助于Jersey 2.0集成的文档.

@ManagedBean
@Path("myresource")
public class MyResource {

    @Inject
    MyService myService;

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/getit")
    public String getIt() {
        return "Got it {" + myService + "}";
    }
}

@Resource
@ManagedBean
public class MyService {
    void serviceCall() {
        System.out.print("Service calls");
    }
}
Run Code Online (Sandbox Code Playgroud)

的pom.xml …

java dependency-injection jersey jersey-2.0 hk2

106
推荐指数
4
解决办法
9万
查看次数

Angular中的Subject vs BehaviorSubject vs ReplaySubject

我一直在寻找那些3:

主题,行为主体重播主题.我想使用它们,知道何时以及为什么,使用它们有什么好处,虽然我已阅读文档,观看教程和搜索谷歌,但我没有对此有任何意义.

那他们的目的是什么?一个真实的案例将是非常感谢它甚至不必编码.

我更喜欢一个干净的解释,而不只是"a + b => c,你订阅了......"

谢谢

javascript reactive-programming rxjs angular2-observables angular

89
推荐指数
6
解决办法
3万
查看次数

angular2 testing:无法绑定到'ngModel',因为它不是'input'的已知属性

我正在尝试测试angular2双向绑定以进行控制input.这是错误:

Can't bind to 'ngModel' since it isn't a known property of 'input'.
Run Code Online (Sandbox Code Playgroud)

app.component.html

<input id="name" type="text" [(ngModel)]="name" />
<div id="divName">{{name}}</div>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'  
})
export class AppComponent implements OnInit {
  name: string;    
}
Run Code Online (Sandbox Code Playgroud)

app.component.spec.ts

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { AppService } from './app.service';
describe('App: Cli', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      providers:[AppService]
    });
  });

  it('divName', async(() => {
    let …
Run Code Online (Sandbox Code Playgroud)

testing angular-cli angular2-testing angular

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

How to handle CORS using JAX-RS with Jersey

I'm developing a java script client application, in server-side I need to handle CORS, all the services I had written in JAX-RS with JERSEY. My code:

@CrossOriginResourceSharing(allowAllOrigins = true)
@GET
@Path("/readOthersCalendar")
@Produces("application/json")
public Response readOthersCalendar(String dataJson) throws Exception {  
     //my code. Edited by gimbal2 to fix formatting
     return Response.status(status).entity(jsonResponse).header("Access-Control-Allow-Origin", "*").build();
}
Run Code Online (Sandbox Code Playgroud)

As of now, i'm getting error No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access."

Please assist me with this. …

java rest jax-rs jersey cors

63
推荐指数
3
解决办法
7万
查看次数

文件上传以及Jersey restful Web服务中的其他对象

我想通过上传图像和员工数据来在系统中创建员工信息.我能够使用球衣进行不同的休息呼叫.但我希望在一次休息电话中实现.我提供下面的结构.请帮我解决这方面的问题.

@POST
@Path("/upload2")
@Consumes({MediaType.MULTIPART_FORM_DATA,MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response uploadFileWithData(
        @FormDataParam("file") InputStream fileInputStream,
        @FormDataParam("file") FormDataContentDisposition contentDispositionHeader,
        Employee emp) {

//..... business login

}
Run Code Online (Sandbox Code Playgroud)

每当我想要做的时候,我都会在Chrome邮递员中出错.我的Employee json的简单结构如下所示.

{
    "Name": "John",
    "Age": 23,
    "Email": "john@gmail.com",
    "Adrs": {
        "DoorNo": "12-A",
        "Street": "Street-11",
        "City": "Bangalore",
        "Country": "Karnataka"
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我可以通过进行两次不同的调用来实现,但我希望在一次休息调用中实现,这样我就可以接收文件以及员工的实际数据.

请求您在这方面提供帮助.

java multipartform-data jax-rs jersey postman

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

使用routerLink进行Angular 2单元测试组件

我试图用angular 2 final测试我的组件,但是我得到一个错误,因为组件使用了该routerLink指令.我收到以下错误:

无法绑定到'routerLink',因为它不是'a'的已知属性.

这是ListComponent模板的相关代码

<a 
  *ngFor="let item of data.list" 
  class="box"
  routerLink="/settings/{{collectionName}}/edit/{{item._id}}">
Run Code Online (Sandbox Code Playgroud)

这是我的考验.

import { TestBed } from '@angular/core/testing';

import { ListComponent } from './list.component';
import { defaultData, collectionName } from '../../config';
import { initialState } from '../../reducers/reducer';


const data = {
  sort: initialState.sort,
  list: [defaultData, defaultData],
};

describe(`${collectionName} ListComponent`, () => {
  let fixture;
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        ListComponent,
      ],
    }).compileComponents(); // compile template and css;
    fixture = TestBed.createComponent(ListComponent);
    fixture.componentInstance.data = data;
    fixture.detectChanges(); …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-routing angular2-testing angular

55
推荐指数
3
解决办法
4万
查看次数

MULTIPART_FORM_DATA:找不到类型为public javax.ws.rs.core.Response的参数的注入源

我正在使用基于Jersey的restful Service实施策略来构建将用于上传文件的服务.我的服务类名是:UploadFileService.java(参见下面的代码)

 package com.jerser.service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;

@Path("/fileUpload")
public class UploadFileService {

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "d://uploaded/" + fileDetail.getFileName();

        // save it
        writeToFile(uploadedInputStream, uploadedFileLocation);

        String output = "File uploaded to : " + uploadedFileLocation;

        return Response.status(200).entity(output).build();

    }

    // save uploaded file to new location
    private void writeToFile(InputStream …
Run Code Online (Sandbox Code Playgroud)

java rest multipartform-data jersey jersey-2.0

43
推荐指数
3
解决办法
5万
查看次数

@PathParam和@PathVariable有什么区别

据我所知,两者都有同样的目的.除了@PathVariable来自Spring MVC并@PathParam来自JAX-RS 的事实.有什么见解吗?

jax-rs spring-mvc restful-url path-parameter

38
推荐指数
3
解决办法
6万
查看次数

如何测试Angular2的router.navigate?

<router-outlet>在其他单元测试中遇到了丢失的消息,但是为了得到一个很好的隔离示例,我创建了一个AuthGuard,用于检查用户是否已登录以执行某些操作.

这是代码:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (!this.authService.isLoggedIn()) {
        this.router.navigate(['/login']);
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

现在我想为此编写一个单元测试.

这就是我开始测试的方式:

beforeEach(() => {
    TestBed.configureTestingModule({
        imports: [
            RouterTestingModule.withRoutes([
                {
                    path: 'login',
                    component: DummyComponent
                }
            ])
        ],
        declarations: [
            DummyComponent
        ],
        providers: [
            AuthGuardService,
            {
                provide: AuthService,
                useClass: MockAuthService
            }
        ]
    });
});
Run Code Online (Sandbox Code Playgroud)

我创建了一个什么都不做的DummyComponent.现在我的考试.假设服务返回false并触发this.router.navigate(['/login']):

it('should not let users pass when not logged in', (): void => {
    expect(authGuardService.canActivate(<any>{}, <any>{})).toBe(false);
});
Run Code Online (Sandbox Code Playgroud)

这将引发"无法找到要加载的主要插座"的异常.显然我可以使用toThrow()而不是toBe(false),但这似乎不是一个非常明智的解决方案.由于我在这里测试服务,因此没有模板可以放置<router-outlet>标签.我可以模拟路由器并创建自己的导航功能,但那么RouterTestingModule有什么意义呢?也许你甚至想检查导航是否有效.

unit-testing angular2-testing angular

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

Angular 2最终释放路由器单元测试

如何使用karma和jasmine对Angular 2.0.0版中的路由器进行单元测试?

这是我的旧单元测试在版本2.0.0-beta.14中的样子

import {
  it,
  inject,
  injectAsync,
  beforeEach,
  beforeEachProviders,
  TestComponentBuilder
} from 'angular2/testing';

import { RootRouter } from 'angular2/src/router/router';
import { Location, RouteParams, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT } from 'angular2/router';
import { SpyLocation } from 'angular2/src/mock/location_mock';
import { provide } from 'angular2/core';

import { App } from './app';

describe('Router', () => {

  let location, router;

  beforeEachProviders(() => [
    RouteRegistry,
    provide(Location, {useClass: SpyLocation}),
    provide(Router, {useClass: RootRouter}),
    provide(ROUTER_PRIMARY_COMPONENT, {useValue: App})
  ]);

  beforeEach(inject([Router, Location], (_router, _location) => {
    router = _router;
    location = …
Run Code Online (Sandbox Code Playgroud)

javascript karma-jasmine angular2-routing angular2-testing angular

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