@Override public String getMimeType() { return MediaType.OCTET_STREAM.toString(); }
default MediaType findBestMatch(List<MediaType> types) { MediaType compatible = null; for (MediaType mine : mediaTypes()) { if (MediaType.ANY.equals(mine)) { // If we're looking for */*, then return application/json if it's an option if (types.contains(MediaType.JSON)) { return MediaType.JSON; } } for (MediaType other : types) { if (other.equals(mine)) { return other; } else if (compatible == null && other.isCompatible(mine)) { compatible = other; } } if (compatible != null) { return compatible; } } return null; } }
public DefaultMediaTypeMatcher(String mediaTypes, String extension) { this(mediaTypes); if (extension != null) { MediaType extensionMediaType = MediaType.lookup(extension); if (extensionMediaType != null) { this.mediaTypes.add(0, extensionMediaType); } } }
public ResourceCodec getResourceCodec(MediaType mediaType) { for (CodecRegistration each : this.codecs) { if (each.mediaType.equals(mediaType)) { return each.codec; } } return null; }
@Override public MediaType mediaType() { return new MediaType(fileInfo().getString("contentType")); }
MediaType mediaType = new MediaType(mediaTypes.substring(cur, end).trim()); this.mediaTypes.add(mediaType); cur = end + 1; String leftQstr = left.parameters().get("q"); String rightQstr = right.parameters().get("q");
public ResourceState decode(MediaType mediaType, ByteBuf buf) throws Exception { if (buf == null) { buf = Unpooled.EMPTY_BUFFER; } if (MediaType.OCTET_STREAM.equals(mediaType)) { return new DefaultBinaryResourceState(buf.retain()); } ResourceCodec codec = getResourceCodec(mediaType); if (codec == null || !codec.hasDecoder()) { throw new UnsupportedMediaTypeException(MediaTypeMatcher.singleton(mediaType)); } return codec.decode(buf); }
@Override public void createMember(RequestContext ctx, ResourceState state, Responder responder) { String path = (String) state.getProperty("path"); String destination = (String) state.getProperty("destination"); String contentType = (String) state.getProperty("content-type"); if (contentType == null) { contentType = "application/json"; } ResourceCodec codec = this.codecManager.getResourceCodec(new MediaType(contentType)); if (codec == null) { responder.internalError("content-type not supported: " + contentType); return; } try { URI destinationUri = new URI(destination); HttpClient httpClient = this.vertx.createHttpClient(); httpClient.setHost(destinationUri.getHost()); httpClient.setPort(destinationUri.getPort()); SecurityContext requestSecurityContext = ctx.securityContext(); HttpSubscription sub = new HttpSubscription(httpClient, path, destinationUri, codec, requestSecurityContext); this.subscriptionManager.addSubscription(sub); responder.resourceCreated(new HttpSubscriptionResource(this, sub)); } catch (URISyntaxException e) { responder.internalError(e.getMessage()); } }
public String toString() { return mediaType.toString(); } };
if (!lazyState.getContentType().equals(MediaType.ZIP)) { responder.invalidRequest("Invalid Request. Only zip files are acceptable"); return;
MediaType contentType = new MediaType(contentTypeHeader); out.add(new DefaultResourceRequest.Builder(RequestType.CREATE, new ResourcePath(path)) .resourceParams(params) .mediaTypeMatcher(mediaTypeMatcher) .requestAttribute(HttpHeaders.Names.AUTHORIZATION, msg.headers().get(HttpHeaders.Names.AUTHORIZATION)) .requestAttribute(HttpHeaders.Names.ACCEPT, new MediaType(acceptHeader)) .requestAttribute(HTTP_REQUEST, msg) .pagination(decodePagination(params)) } else if (msg.getMethod().equals(HttpMethod.PUT)) { String contentTypeHeader = msg.headers().get(HttpHeaders.Names.CONTENT_TYPE); MediaType contentType = new MediaType(contentTypeHeader); out.add(new DefaultResourceRequest.Builder(RequestType.UPDATE, new ResourcePath(path)) .resourceParams(params) .mediaTypeMatcher(mediaTypeMatcher) .requestAttribute(HttpHeaders.Names.AUTHORIZATION, msg.headers().get(HttpHeaders.Names.AUTHORIZATION)) .requestAttribute(HttpHeaders.Names.ACCEPT, new MediaType(acceptHeader)) .requestAttribute(HTTP_REQUEST, msg) .build());
@Override public MediaType mediaType() { String name = this.file.getName(); int lastDotLoc = name.lastIndexOf('.'); MediaType mediaType = null; if (lastDotLoc > 0) { mediaType = MediaType.lookup(name.substring(lastDotLoc + 1)); } if (mediaType == null) { mediaType = MediaType.OCTET_STREAM; } return mediaType; }
public HttpRequest data(String data, MediaType mediaType) { if (builder != null) { builder.setEntity(new StringEntity(data, ContentType.create(mediaType.toString(), "UTF-8"))); } return this; }
public HttpRequest data(JsonNode data, MediaType mediaType) { if (builder != null) { builder.setEntity(new StringEntity(data.toString(), ContentType.create(mediaType.toString(), "UTF-8"))); } return this; }
public HttpRequest accept(MediaType mediaType) { if (builder != null) { builder.addHeader(HttpHeaders.Names.ACCEPT, mediaType.toString()); } return this; }
private ServiceName installCodec(ServiceTarget target, MediaType mediaType, Class<? extends StateEncoder> encoderClass, ResourceDecoder decoder) { ServiceName name = codec(mediaType.toString()); CodecService codec = new CodecService(encoderClass, decoder); target.addService(name, codec) .install(); CodecInstallationService installer = new CodecInstallationService(mediaType); target.addService(name.append("install"), installer) .addDependency(name, ResourceCodec.class, installer.codecInjector()) .addDependency(CODEC_MANAGER, ResourceCodecManager.class, installer.codecManagerInjector()) .install(); return name.append("install"); } }
public void addClientScopeRolesForApplication(String authToken, String realmName, String clientApp, String appName, List<RoleRepresentation> roles) throws Exception { HttpPost post = new HttpPost(clientScopeForApplicationsEndpoint(realmName, clientApp, appName)); addAuthzHeader(post, authToken); post.setEntity(new StringEntity(JsonSerialization.writeValueAsString(roles), ContentType.create(MediaType.JSON.toString(), "UTF-8"))); exec(post, 204, "Unable to add roles to client application " + clientApp, new VoidHandler()); }
public void updateApplication(String authToken, String realmName, ApplicationRepresentation app) throws Exception { HttpPut put = new HttpPut(applicationEndpoint(realmName, app.getName())); addAuthzHeader(put, authToken); put.setEntity(new StringEntity(JsonSerialization.writeValueAsString(app), ContentType.create(MediaType.JSON.toString(), "UTF-8"))); exec(put, 204, "Unable to update application named " + app.getName() + " in " + realmName + " realm", new VoidHandler()); }
public void createApplicationRole(String authToken, String realmName, String appName, String roleName) throws Exception { RoleRepresentation role = new RoleRepresentation(); role.setName(roleName); HttpPost post = new HttpPost(applicationRolesEndpoint(realmName, appName)); addAuthzHeader(post, authToken); post.setEntity(new StringEntity(JsonSerialization.writeValueAsString(role), ContentType.create(MediaType.JSON.toString(), "UTF-8"))); exec(post, 201, "Unable to create application role named " + roleName + " in application " + appName, new VoidHandler()); }
public void createApplication(String authToken, String realmName, String appName) throws Exception { ApplicationRepresentation app = new ApplicationRepresentation(); app.setName(appName); HttpPost post = new HttpPost(realmApplicationsEndpoint(realmName)); addAuthzHeader(post, authToken); post.setEntity(new StringEntity(JsonSerialization.writeValueAsString(app), ContentType.create(MediaType.JSON.toString(), "UTF-8"))); exec(post, 201, "Unable to create application named " + appName + " in " + realmName + " realm", new VoidHandler()); }