本文整理了Java中javax.ws.rs.core.Response.getMetadata
方法的一些代码示例,展示了Response.getMetadata
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getMetadata
方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:getMetadata
[英]See #getHeaders(). This method is considered deprecated. Users are encouraged to switch their code to use the getHeaders() method instead. The method may be annotated as Deprecated in a future release of JAX-RS API.
[中]请参阅#getHeaders()。这种方法被认为是不推荐的。建议用户切换代码,改用getHeaders()方法。在JAX-RSAPI的未来版本中,该方法可能会被注释为不推荐使用。
代码示例来源:origin: neo4j/neo4j
private void checkContentTypeCharsetUtf8( Response response )
{
assertTrue( response.getMetadata()
.getFirst( HttpHeaders.CONTENT_TYPE ).toString().contains( "UTF-8" ));
}
代码示例来源:origin: Netflix/eureka
@Test
public void testFullAppsGetGzipJsonHeaderType() throws Exception {
Response response = applicationsResource.getContainers(
Version.V2.name(),
MediaType.APPLICATION_JSON,
"gzip", // encoding
EurekaAccept.full.name(),
null, // uriInfo
null // remote regions
);
assertThat(response.getMetadata().getFirst("Content-Encoding").toString(), is("gzip"));
assertThat(response.getMetadata().getFirst("Content-Type").toString(), is(MediaType.APPLICATION_JSON));
}
代码示例来源:origin: Netflix/eureka
@Test
public void testFullAppsGetGzipXmlHeaderType() throws Exception {
Response response = applicationsResource.getContainers(
Version.V2.name(),
MediaType.APPLICATION_XML,
"gzip", // encoding
EurekaAccept.full.name(),
null, // uriInfo
null // remote regions
);
assertThat(response.getMetadata().getFirst("Content-Encoding").toString(), is("gzip"));
assertThat(response.getMetadata().getFirst("Content-Type").toString(), is(MediaType.APPLICATION_XML));
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToIndexNode()
{
Response response = service.createNode( null );
URI nodeUri = (URI) response.getMetadata()
.getFirst( "Location" );
Map<String, String> postBody = new HashMap<>();
postBody.put( "key", "mykey" );
postBody.put( "value", "my/key" );
postBody.put( "uri", nodeUri.toString() );
response = service.addToNodeIndex( "node", null, null, JsonHelper.createJsonFrom( postBody ) );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.getFirst( "Location" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotBeAbleToIndexRelationshipUniquelyWithRequiredParameterMissing()
{
URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" );
URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" );
Map<String, Object> body = new HashMap<>();
body.put( "key", "mykey" );
body.put( "value", "my/key" );
body.put( "start", start.toString() );
body.put( "end", end.toString() );
body.put( "type", "knows" );
for ( String key : body.keySet() )
{
Map<String, Object> postBody = new HashMap<>( body );
postBody.remove( key );
Response response = service.addToRelationshipIndex( "unique-relationships", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( "unexpected response code with \"" + key + "\" missing.", 400, response.getStatus() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToIndexRelationshipUniquely()
{
URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" );
URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" );
Map<String, String> postBody = new HashMap<>();
postBody.put( "key", "mykey" );
postBody.put( "value", "my/key" );
postBody.put( "start", start.toString() );
postBody.put( "end", end.toString() );
postBody.put( "type", "knows" );
for ( int i = 0; i < 2; i++ )
{
Response response = service.addToNodeIndex( "unique-relationships", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 201 - i, response.getStatus() );
if ( i == 0 )
{
assertNotNull( response.getMetadata().getFirst( "Location" ) );
}
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotBeAbleToIndexNodeUniquelyWithRequiredParameterMissing()
{
service.createNode( null ).getMetadata().getFirst( "Location" );
Map<String, Object> body = new HashMap<>();
body.put( "key", "mykey" );
body.put( "value", "my/key" );
for ( String key : body.keySet() )
{
Map<String, Object> postBody = new HashMap<>( body );
postBody.remove( key );
Response response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( "unexpected response code with \"" + key + "\" missing.", 400, response.getStatus() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldReturnAbsoluteURIForSeeOther() throws Exception
{
URI relativeURI = new URI( "/test/path" );
OutputFormat outputFormat = new OutputFormat( new JsonFormat(), new URI( "http://base.local:8765/" ), null );
Response response = outputFormat.seeOther( relativeURI );
assertEquals( 303, response.getStatus() );
assertEquals( new URI( "http://base.local:8765/test/path" ), response.getMetadata().getFirst( "Location" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void specifiedPropertiesOverrideKeyAndValueForUniquelyIndexedNodes()
{
final String key = "a_key";
String value = "a value";
Map<String, Object> postBody = new HashMap<>();
postBody.put( "key", key );
postBody.put( "value", value );
Map<String, Object> properties = new HashMap<>();
properties.put( "name", "Jürgen" );
properties.put( "age", "42" );
properties.put( "occupation", "crazy" );
postBody.put( "properties", properties );
Response response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 201, response.getStatus() );
Object node = response.getMetadata().getFirst( "Location" );
assertNotNull( node );
String uri = node.toString();
assertEquals( properties, helper.getNodeProperties( parseLong( uri.substring( uri.lastIndexOf( '/' ) + 1
) ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void uniquelyIndexedNodeGetsTheSpecifiedKeyAndValueAsPropertiesIfNoPropertiesAreSpecified()
{
final String key = "somekey";
String value = "somevalue";
Map<String, Object> postBody = new HashMap<>();
postBody.put( "key", key );
postBody.put( "value", value );
Response response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 201, response.getStatus() );
Object node = response.getMetadata().getFirst( "Location" );
assertNotNull( node );
String uri = node.toString();
Map<String, Object> properties = helper.getNodeProperties( parseLong( uri.substring( uri.lastIndexOf(
'/' ) + 1 ) ) );
assertEquals( 1, properties.size() );
assertEquals( value, properties.get( key ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotBeAbleToIndexNodeUniquelyWithBothUriAndPropertiesInPayload() throws Exception
{
URI node = (URI) service.createNode( null ).getMetadata().getFirst( "Location" );
Map<String, Object> postBody = new HashMap<>();
postBody.put( "key", "mykey" );
postBody.put( "value", "my/key" );
postBody.put( "uri", node.toString() );
postBody.put( "properties", new HashMap<String,Object>() );
Response response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 400, response.getStatus() );
assertEquals( Statement.ArgumentError.code().serialize(), singleErrorCode( response ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRespondWith201AndLocationWhenRelationshipIsCreatedWithoutProperties()
{
long startNode = helper.createNode();
long endNode = helper.createNode();
Response response = service.createRelationship( startNode, "{\"to\" : \"" + BASE_URI + endNode
+ "\", \"type\" : \"LOVES\"}" );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.get( "Location" )
.get( 0 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToIndexNodeUniquely()
{
Map<String, String> postBody = new HashMap<>();
postBody.put( "key", "mykey" );
postBody.put( "value", "my/key" );
Response response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata().getFirst( "Location" ) );
response = service.addToNodeIndex( "unique-nodes", "", "",
JsonHelper.createJsonFrom( postBody ) );
assertEquals( 200, response.getStatus() );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRespondWith201AndLocationWhenRelationshipIsCreatedWithProperties()
{
long startNode = helper.createNode();
long endNode = helper.createNode();
Response response = service.createRelationship( startNode,
"{\"to\" : \"" + BASE_URI + endNode + "\", \"type\" : \"LOVES\", " +
"\"properties\" : {\"foo\" : \"bar\"}}" );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.get( "Location" )
.get( 0 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldReturnRedirectToAbsoluteAPIUsingOutputFormat() throws Exception
{
Config config = Config.defaults( ServerSettings.browser_path, "/browser/" );
String baseUri = "http://www.example.com:5435";
DiscoveryService ds =
new DiscoveryService( config, new EntityOutputFormat( new JsonFormat(), new URI( baseUri ), null ), communityDiscoverableURIs( config, null ) );
Response response = ds.redirectToBrowser();
assertThat( response.getMetadata().getFirst( "Location" ), is( new URI( "http://www.example" + ".com:5435/browser/" ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
@SuppressWarnings( "unchecked" )
public void shouldRespondWith201LocationHeaderAndNodeRepresentationInJSONWhenPopulatedNodeCreatedWithArrays()
throws Exception
{
Response response = service.createNode( "{\"foo\" : [\"bar\", \"baz\"] }" );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.get( "Location" )
.get( 0 ) );
String json = entityAsString( response );
Map<String, Object> map = JsonHelper.jsonToMap( json );
assertNotNull( map );
Map<String, Object> data = (Map<String, Object>) map.get( "data" );
List<String> foo = (List<String>) data.get( "foo" );
assertNotNull( foo );
assertEquals( 2, foo.size() );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRespondWith201LocationHeaderAndNodeRepresentationInJSONWhenEmptyNodeCreated() throws Exception
{
Response response = service.createNode( null );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.get( "Location" )
.get( 0 ) );
checkContentTypeCharsetUtf8( response );
String json = entityAsString( response );
Map<String, Object> map = JsonHelper.jsonToMap( json );
assertNotNull( map );
assertTrue( map.containsKey( "self" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRespondWith201LocationHeaderAndNodeRepresentationInJSONWhenPopulatedNodeCreated()
throws Exception
{
Response response = service.createNode( "{\"foo\" : \"bar\"}" );
assertEquals( 201, response.getStatus() );
assertNotNull( response.getMetadata()
.get( "Location" )
.get( 0 ) );
checkContentTypeCharsetUtf8(response);
String json = entityAsString( response );
Map<String, Object> map = JsonHelper.jsonToMap( json );
assertNotNull( map );
assertTrue( map.containsKey( "self" ) );
@SuppressWarnings( "unchecked" )
Map<String, Object> data = (Map<String, Object>) map.get( "data" );
assertEquals( "bar", data.get( "foo" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToGetNodeRepresentationFromIndexUri() throws Exception
{
String key = "key_get_noderep";
String value = "value";
long nodeId = helper.createNode();
String indexName = "all-the-best-nodes";
helper.addNodeToIndex( indexName, key, value, nodeId );
Response response = service.getNodeFromIndexUri( indexName, key, value, nodeId );
assertEquals( 200, response.getStatus() );
checkContentTypeCharsetUtf8( response );
assertNull( response.getMetadata()
.get( "Location" ) );
Map<String, Object> map = JsonHelper.jsonToMap( entityAsString( response ) );
assertNotNull( map );
assertTrue( map.containsKey( "self" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldBeAbleToGetRelationshipRepresentationFromIndexUri() throws Exception
{
String key = "key_get_noderep";
String value = "value";
long startNodeId = helper.createNode();
long endNodeId = helper.createNode();
String relationshipType = "knows";
long relationshipId = helper.createRelationship( relationshipType, startNodeId, endNodeId );
String indexName = "all-the-best-relationships";
helper.addRelationshipToIndex( indexName, key, value, relationshipId );
Response response = service.getRelationshipFromIndexUri( indexName, key, value, relationshipId );
assertEquals( 200, response.getStatus() );
checkContentTypeCharsetUtf8(response);
assertNull( response.getMetadata()
.get( "Location" ) );
Map<String, Object> map = JsonHelper.jsonToMap( entityAsString( response ) );
assertNotNull( map );
assertTrue( map.containsKey( "self" ) );
}
内容来源于网络,如有侵权,请联系作者删除!