当前位置: 首页>>代码示例>>Java>>正文


Java MimeTypeUtils类代码示例

本文整理汇总了Java中org.springframework.util.MimeTypeUtils的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeUtils类的具体用法?Java MimeTypeUtils怎么用?Java MimeTypeUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MimeTypeUtils类属于org.springframework.util包,在下文中一共展示了MimeTypeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: signUp

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@ApiOperation(value = "signup", notes = "create a new account", response = UserDetailsResponse.class)
@RequestMapping(value = "/auth/signup", method = RequestMethod.POST, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<UserDetailsResponse> signUp(@RequestBody  Map<String, String> data) {
    if (!securityConfigurationProperties.getMongo().isEnableSignup()) {
        return ResponseEntity.badRequest().build();
    }
    // Public access
    final String login = data.get("login"),
            password = data.get("password"),
            mail = data.get("email");
    if ( StringUtils.isNoneBlank(login, password, mail) && emailValidator.isValid(mail)) {
        return ResponseEntity.ok(UserDetailsResponse.wrap(accountService.createAccount(login, mail, password)));
    } else {
        return ResponseEntity.badRequest().build();
    }

}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:18,代码来源:UserWebservice.java

示例2: testSendBinaryDataWithContentType

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void testSendBinaryDataWithContentType() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=image/jpeg")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		byte[] data = new byte[] { 0, 1, 2, 3 };
		source.output().send(MessageBuilder.withPayload(data)
				.build());
		Message<byte[]> message = (Message<byte[]>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
						.includes(MimeTypeUtils.IMAGE_JPEG));
		assertThat(message.getPayload()).isEqualTo(data);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:ContentTypeTests.java

示例3: updateConversation

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@ApiOperation(value = "update a conversation", response = Conversation.class)
@RequestMapping(value = "{id}", method = RequestMethod.PUT, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateConversation(
        AuthContext authContext,
        @PathVariable("id") ObjectId id,
        @RequestBody Conversation conversation
) {
    final Conversation storedC = authenticationService.assertConversation(authContext, id);

    // make sure the id is the right one
    conversation.setId(storedC.getId());
    final Client client = authenticationService.assertClient(authContext, conversation.getOwner());

    //TODO: check that the
    // * the user is from the client the stored conversation as as owner
    return ResponseEntity.ok(conversationService.update(client, conversation,true, null));
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:18,代码来源:ConversationWebservice.java

示例4: handleErrorFrameWithConversionException

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void handleErrorFrameWithConversionException() throws Exception {

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
	accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
	accessor.addNativeHeader("foo", "bar");
	accessor.setLeaveMutable(true);
	byte[] payload = "{'foo':'bar'}".getBytes(UTF_8);

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	when(this.sessionHandler.getPayloadType(stompHeaders)).thenReturn(Map.class);

	this.session.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));

	verify(this.sessionHandler).getPayloadType(stompHeaders);
	verify(this.sessionHandler).handleException(same(this.session), same(StompCommand.ERROR),
			eq(stompHeaders), same(payload), any(MessageConversionException.class));
	verifyNoMoreInteractions(this.sessionHandler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultStompSessionTests.java

示例5: handleMessageFrame

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void handleMessageFrame() throws Exception {

	this.session.afterConnected(this.connection);

	StompFrameHandler frameHandler = mock(StompFrameHandler.class);
	String destination = "/topic/foo";
	Subscription subscription = this.session.subscribe(destination, frameHandler);

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE);
	accessor.setDestination(destination);
	accessor.setSubscriptionId(subscription.getSubscriptionId());
	accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
	accessor.setMessageId("1");
	accessor.setLeaveMutable(true);
	String payload = "sample payload";

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	when(frameHandler.getPayloadType(stompHeaders)).thenReturn(String.class);

	this.session.handleMessage(MessageBuilder.createMessage(payload.getBytes(UTF_8), accessor.getMessageHeaders()));

	verify(frameHandler).getPayloadType(stompHeaders);
	verify(frameHandler).handleFrame(stompHeaders, payload);
	verifyNoMoreInteractions(frameHandler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:DefaultStompSessionTests.java

示例6: toNativeHeadersMessageFrame

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void toNativeHeadersMessageFrame() {

	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
	headers.setSubscriptionId("s1");
	headers.setDestination("/d");
	headers.setContentType(MimeTypeUtils.APPLICATION_JSON);
	headers.updateStompCommandAsServerMessage();

	Map<String, List<String>> actual = headers.toNativeHeaderMap();

	assertEquals(actual.toString(), 4, actual.size());
	assertEquals("s1", actual.get(StompHeaderAccessor.STOMP_SUBSCRIPTION_HEADER).get(0));
	assertEquals("/d", actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER).get(0));
	assertEquals("application/json", actual.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER).get(0));
	assertNotNull("message-id was not created", actual.get(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER).get(0));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:StompHeaderAccessorTests.java

示例7: getShortLogMessage

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void getShortLogMessage() {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
	accessor.setDestination("/foo");
	accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
	accessor.setSessionId("123");
	String actual = accessor.getShortLogMessage("payload".getBytes(Charset.forName("UTF-8")));
	assertEquals("SEND /foo session=123 application/json payload=payload", actual);

	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < 80; i++) {
		sb.append("a");
	}
	final String payload = sb.toString() + " > 80";
	actual = accessor.getShortLogMessage(payload.getBytes(UTF_8));
	assertEquals("SEND /foo session=123 application/json payload=" + sb + "...(truncated)", actual);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:StompHeaderAccessorTests.java

示例8: sendWebSocketBinary

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void sendWebSocketBinary() throws Exception {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
	accessor.setDestination("/b");
	accessor.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
	byte[] payload = "payload".getBytes(UTF_8);

	getTcpConnection().send(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));

	ArgumentCaptor<BinaryMessage> binaryMessageCaptor = ArgumentCaptor.forClass(BinaryMessage.class);
	verify(this.webSocketSession).sendMessage(binaryMessageCaptor.capture());
	BinaryMessage binaryMessage = binaryMessageCaptor.getValue();
	assertNotNull(binaryMessage);
	assertEquals("SEND\ndestination:/b\ncontent-type:application/octet-stream\ncontent-length:7\n\npayload\0",
			new String(binaryMessage.getPayload().array(), UTF_8));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:WebSocketStompClientTests.java

示例9: serve

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Override
public Response serve(IHTTPSession session) {
    
    Method m = session.getMethod();
    switch(m)
    {
    
      case GET:
        return doGet(session);
      case POST:
        return doPost(session);
      default:
        return newFixedLengthResponse(Status.NOT_IMPLEMENTED, MimeTypeUtils.TEXT_PLAIN_VALUE,"HTTP "+m);
    
    }
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:17,代码来源:SimpleHttpServerBean.java

示例10: read

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
public void read(String mimeType, InputStream is) throws IOException {
    Assert.hasText(mimeType, "MimeType string is null or empty.");
    Assert.notNull(is, "InputStream is null or empty.");
    MimeType mimeTypeObj = MimeTypeUtils.parseMimeType(mimeType);
    if(MimeTypeUtils.APPLICATION_JSON.equals(mimeTypeObj)) {
        Assert.hasText(mimeType, "MimeType '" + mimeType + "' is not supported.");
    }
    AppConfigObject aco = objectMapper.readValue(is, AppConfigObject.class);
    final String version = aco.getVersion();
    if(!VERSION.equals(version)) {
        throw new RuntimeException("Unsupported version of config: " + version);
    }

    ConfigReadContext ctx = new ConfigReadContext();
    Map<String, Object> map = aco.getData();
    Assert.notNull(map, "config has empty map");
    for(Map.Entry<String, Object> oe : map.entrySet()) {
        String name = oe.getKey();
        ReConfigurableAdapter ca = adapters.get(name);
        Assert.notNull(ca, "Can not find adapter with name: " + name);
        Object value = oe.getValue();
        Assert.notNull(value, "Config object is null for name: " + name);
        ca.setConfig(ctx, value);
    }
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:26,代码来源:AppConfigService.java

示例11: getConfig

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@RequestMapping(path = "config", method = RequestMethod.GET)
public ResponseEntity<StreamingResponseBody> getConfig() {
    HttpHeaders headers = new HttpHeaders();
    // 'produces' in annotation does not work with stream
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"cluman_config.json\"");
    return new ResponseEntity<>((os) -> {
        appConfigService.write(MimeTypeUtils.APPLICATION_JSON_VALUE, os);
    }, headers, HttpStatus.OK);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:11,代码来源:ConfigurationApi.java

示例12: uploadImage

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
/**
 * Uploads a byte array using FileResource and ExternalFileResource
 *
 * @param name  name of the file to be stored
 * @param bytes the byte array representing the file to be stored
 * @return url pointing to the uploaded resource
 * @throws IOException
 */
private String uploadImage( String name, byte[] bytes )
    throws IOException
{
    FileResource fileResource = new FileResource(
        name,
        MimeTypeUtils.IMAGE_PNG.toString(), // All files uploaded from PushAnalysis is PNG.
        bytes.length,
        ByteSource.wrap( bytes ).hash( Hashing.md5() ).toString(),
        FileResourceDomain.PUSH_ANALYSIS
    );

    fileResourceService.saveFileResource( fileResource, bytes );

    ExternalFileResource externalFileResource = new ExternalFileResource();

    externalFileResource.setFileResource( fileResource );
    externalFileResource.setExpires( null );

    String accessToken = externalFileResourceService.saveExternalFileResource( externalFileResource );

    return systemSettingManager.getInstanceBaseUrl() + "/api/externalFileResources/" + accessToken;

}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:32,代码来源:DefaultPushAnalysisService.java

示例13: addNewPlusOne

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@RequestMapping(value = "/{kudosId}/plusOnes", method = RequestMethod.POST, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseMessage addNewPlusOne(@RequestBody @Valid NewPlusOneRequest newPlusOneRequest, BindingResult result, @PathVariable("kudosId") Long kudosId) {
    logger.info("New request " + newPlusOneRequest.toString());
    if (result.hasErrors()) {
        throw new IllegalArgumentException("Invalid request data " + result.toString());
    }
    Kudos kudos = kudosRepository.findOne(kudosId);
    if(kudos == null) {
        throw new IllegalArgumentException("There is no kudos with id=" + kudosId);
    }

    PlusOne plusOne = new PlusOne(
            slackUsersProvider.mapSlackUserNameToUserId(newPlusOneRequest.getUserName()),
            newPlusOneRequest.getDescription(),
            kudos
    );
    plusOneRepository.save(plusOne);
    kudos.addPlusOne(plusOne);

    return new ResponseMessage("ok");
}
 
开发者ID:softwaremill,项目名称:janusz-backend,代码行数:22,代码来源:KudosRestController.java

示例14: testOneRequiredGroup

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void testOneRequiredGroup() throws Exception {
	B binder = getBinder();
	PP producerProperties = createProducerProperties();
	DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));

	String testDestination = "testDestination" + UUID.randomUUID().toString().replace("-", "");

	producerProperties.setRequiredGroups("test1");
	Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination, output, producerProperties);

	String testPayload = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());

	QueueChannel inbound1 = new QueueChannel();
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(testDestination, "test1", inbound1,
			createConsumerProperties());

	Message<?> receivedMessage1 = receive(inbound1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String((byte[]) receivedMessage1.getPayload())).isEqualTo(testPayload);

	producerBinding.unbind();
	consumerBinding.unbind();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:26,代码来源:PartitionCapableBinderTests.java

示例15: testSendWithDefaultContentType

import org.springframework.util.MimeTypeUtils; //导入依赖的package包/类
@Test
public void testSendWithDefaultContentType() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false")) {

		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		User user = new User("Alice");
		source.output().send(MessageBuilder.withPayload(user).build());
		Message<String> message = (Message<String>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		User received = mapper.readValue(message.getPayload(), User.class);
		assertThat(
				message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
						.includes(MimeTypeUtils.APPLICATION_JSON));
		assertThat(user.getName()).isEqualTo(received.getName());
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:20,代码来源:ContentTypeTests.java


注:本文中的org.springframework.util.MimeTypeUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。