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


Java IApimanBuffer类代码示例

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


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

示例1: changeResponseWhenCallbackParamNameIsSavedInContext

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
@Test
public void changeResponseWhenCallbackParamNameIsSavedInContext() throws Exception {
    JsonpConfigBean config = new JsonpConfigBean();

    // given
    String functionName = "testFunction";
    sContext.setAttribute(JsonpPolicy.CALLBACK_FUNCTION_NAME, functionName);
    ApiResponse response = new ApiResponse();
    String json = "{\"name\": \"test\"}";
    IApimanBuffer chunk = new ByteBuffer(json.getBytes().length);
    chunk.append(json);
    IAsyncHandler<IApimanBuffer> bodyHandler = mock(IAsyncHandler.class);
    // when
    IReadWriteStream<ApiResponse> responseDataHandler = jsonpPolicy.getResponseDataHandler(response, sContext, config);
    ApiResponse head = responseDataHandler.getHead();
    responseDataHandler.bodyHandler(bodyHandler);
    responseDataHandler.write(chunk);
    responseDataHandler.end();
    // then
    assertSame(response, head);

    verify(bodyHandler).handle(refEq(new ByteBuffer("testFunction(")));
    verify(bodyHandler).handle(refEq(new ByteBuffer(json)));
    verify(bodyHandler).handle(refEq(new ByteBuffer(")")));
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JsonpPolicyTest.java

示例2: write

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.io.IWriteStream#write(io.apiman.gateway.engine.io.IApimanBuffer)
 */
@Override
public void write(IApimanBuffer chunk) {
    try {
        if (!connected) {
            throw new IOException("Not connected."); //$NON-NLS-1$
        }
        if (outputStream == null) {
            outputStream = connection.getOutputStream();
        }
        if (chunk instanceof ByteBuffer) {
            byte[] buffer = (byte[]) chunk.getNativeBuffer();
            outputStream.write(buffer, 0, chunk.length());
        } else {
            outputStream.write(chunk.getBytes());
        }
    } catch (IOException e) {
        handleConnectionError(e);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:HttpApiConnection.java

示例3: write

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
@Override
public void write(IApimanBuffer chunk) {
    if (inboundFinished) {
        throw new IllegalStateException(Messages.getString("HttpConnector.0"));
    }

    if (chunk.getNativeBuffer() instanceof Buffer) {
        clientRequest.write((Buffer) chunk.getNativeBuffer());
        // When write queue has diminished sufficiently, drain handler will be invoked.
        if (clientRequest.writeQueueFull() && drainHandler != null) {
            clientRequest.drainHandler(drainHandler::handle);
        }
    } else {
        throw new IllegalArgumentException(Messages.getString("HttpConnector.1"));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:17,代码来源:HttpConnector.java

示例4: setup

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
@Before
public void setup() {
    Policy policyBean = mock(Policy.class);
    given(policyBean.getPolicyImpl()).willReturn(PassthroughPolicy.QUALIFIED_NAME);
    given(policyBean.getPolicyJsonConfig()).willReturn("{}");

    mockBufferInbound = mock(IApimanBuffer.class);
    given(mockBufferInbound.toString()).willReturn("stottie");

    mockBufferOutbound = mock(IApimanBuffer.class);
    given(mockBufferOutbound.toString()).willReturn("bacon");

    policyList = new ArrayList<>();
    policyList.add(policyBean);

    mockBodyHandler = mock(IAsyncHandler.class);
    mockEndHandler = mock(IAsyncHandler.class);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:19,代码来源:DefaultEngineFactoryTest.java

示例5: shouldPreserveBufferOrder

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
@Test
public void shouldPreserveBufferOrder() {
    policies.add(pwcOne);
    requestChain = new RequestChain(policies, mockContext);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);

    requestChain.doApply(mockRequest);

    IApimanBuffer buffer1 = mock(IApimanBuffer.class);
    IApimanBuffer buffer2 = mock(IApimanBuffer.class);
    IApimanBuffer buffer3 = mock(IApimanBuffer.class);

    requestChain.write(buffer1);
    requestChain.write(buffer2);
    requestChain.write(buffer3);

    requestChain.end();

    InOrder order = inOrder(mockBodyHandler, mockEndHandler);
    order.verify(mockBodyHandler).handle(buffer1);
    order.verify(mockBodyHandler).handle(buffer2);
    order.verify(mockBodyHandler).handle(buffer3);
    order.verify(mockEndHandler).handle((Void) null);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:26,代码来源:PolicyChainTest.java

示例6: responseDataHandler

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * See {@link AbstractMappedDataPolicy#responseDataHandler(ApiResponse, IPolicyContext, Object)}
 */
@Override
protected IReadWriteStream<ApiResponse> responseDataHandler(final ApiResponse response,
                                                            final IPolicyContext context,
                                                            final CookieRemoveConfigBean config) {
    // short-circuit
    if (context.getAttribute(ATTRIBUTE_SKIP, false)) {
        return null;
    }

    if (ResponseBehaviour.PassThrough.equals(config.getResponseBehaviour())) {
        // default response behaviour
        return null;

    } else {
        // discard response body from back-end service
        return new AbstractStream<ApiResponse>() {
            @Override
            protected void handleHead(ApiResponse head) {
            }

            @Override
            public ApiResponse getHead() {
                return response;
            }

            @Override
            public void write(IApimanBuffer chunk) {
                // discard chunk
            }
        };
    }
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:36,代码来源:CookieRemovePolicy.java

示例7: getNativeBuffer

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
private Buffer getNativeBuffer(IApimanBuffer buffer) {
	if (buffer.getNativeBuffer() instanceof Buffer) {
		return (Buffer) buffer.getNativeBuffer();
	} else {
		logger.debug("Received an IApimanBuffer with a non-Vert.x implementation. " //$NON-NLS-1$
				+ "This will function but may require copying and be less efficient."); //$NON-NLS-1$
		return Buffer.buffer(buffer.getBytes());
	}
}
 
开发者ID:apiman,项目名称:apiman,代码行数:10,代码来源:HttpClientComponentImpl.java

示例8: putBinary

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.ICacheStoreComponent#putBinary(java.lang.String, java.lang.Object, long)
 */
@Override
public <T> ISignalWriteStream putBinary(final String cacheKey, final T jsonObject, final long timeToLive)
        throws IOException {
    final IApimanBuffer dataBuffer = bufferFactory.createBuffer(0);
    return new ISignalWriteStream() {
        private boolean finished = false;
        private boolean aborted = false;
        @Override
        public void abort(Throwable t) {
            aborted = true;
            finished = false;
        }
        @Override
        public boolean isFinished() {
            return finished;
        }
        @Override
        public void write(IApimanBuffer chunk) {
            dataBuffer.append(chunk);
        }
        @Override
        public void end() {
            if (!aborted) {
                synchronized (mutex) {
                    InfinispanCacheEntry entry = (InfinispanCacheEntry) getCache().get(cacheKey);
                    if (entry == null) {
                        entry = new InfinispanCacheEntry();
                    }
                    entry.setHead(jsonObject);
                    entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000));
                    entry.setData(dataBuffer.getBytes());
                    getCache().put(cacheKey, entry);
                }
            }
        }
    };
}
 
开发者ID:apiman,项目名称:apiman,代码行数:41,代码来源:InfinispanCacheStoreComponent.java

示例9: write

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.io.AbstractStream#write(io.apiman.gateway.engine.io.IApimanBuffer)
 */
@Override
public void write(IApimanBuffer chunk) {
    if (buffer == null) {
        buffer = bufferFactory.cloneBuffer(chunk);
    } else {
        buffer.append(chunk);
    }
    atEnd = false;
    processBuffer();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:14,代码来源:URLRewritingStream.java

示例10: requestDataHandler

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#requestDataHandler(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiRequest> requestDataHandler(final ApiRequest request,
        final IPolicyContext context, final TransferQuotaConfig config) {
    // *************************************************************
    // Step 2:  if upload quotas are enabled, then count all bytes
    //          uploaded to the back-end API
    // *************************************************************
    if (config.getDirection() == TransferDirectionType.upload || config.getDirection() == TransferDirectionType.both) {
        return new AbstractStream<ApiRequest>() {
            private long total = 0;
            @Override
            public ApiRequest getHead() {
                return request;
            }
            @Override
            protected void handleHead(ApiRequest head) {
            }
            @Override
            public void write(IApimanBuffer chunk) {
                total += chunk.length();
                super.write(chunk);
            }
            @Override
            public void end() {
                context.setAttribute(BYTES_UPLOADED_ATTR, total);
                super.end();
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:36,代码来源:TransferQuotaPolicy.java

示例11: responseDataHandler

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#responseDataHandler(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiResponse> responseDataHandler(final ApiResponse response,
        final IPolicyContext context, final TransferQuotaConfig config) {
    // *************************************************************
    // Step 4:  if download quotas are enabled, then count all bytes
    //          downloaded from the back-end API and store the count
    // ---
    // Note: we have no easy way to fail the request if the download
    //       quota is exceeded - so we'll pass and then fail on the
    //       next request (see Step 1)
    // *************************************************************
    if (config.getDirection() == TransferDirectionType.download || config.getDirection() == TransferDirectionType.both) {
        return new AbstractStream<ApiResponse>() {
            private long total = 0;
            @Override
            public ApiResponse getHead() {
                return response;
            }
            @Override
            protected void handleHead(ApiResponse head) {
            }
            @Override
            public void write(IApimanBuffer chunk) {
                total += chunk.length();
                super.write(chunk);
            }
            @Override
            public void end() {
                doFinalApply(context, config, total);
                super.end();
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:40,代码来源:TransferQuotaPolicy.java

示例12: putBinary

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.ICacheStoreComponent#putBinary(java.lang.String, java.lang.Object, long)
 */
@Override
public <T> ISignalWriteStream putBinary(final String cacheKey, final T jsonObject, final long timeToLive)
        throws IOException {
    final ESCacheEntry entry = new ESCacheEntry();
    entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000));
    entry.setHead(mapper.writeValueAsString(jsonObject));
    final IApimanBuffer data = bufferFactory.createBuffer();
    return new ISignalWriteStream() {
        boolean finished = false;
        boolean aborted = false;
        @Override
        public void abort(Throwable t) {
            finished = true;
            aborted = false;
        }
        @Override
        public boolean isFinished() {
            return finished;
        }
        @Override
        public void write(IApimanBuffer chunk) {
            data.append(chunk);
        }
        @Override
        public void end() {
            if (!aborted) {
                entry.setData(Base64.encodeBase64String(data.getBytes()));
                Index index = new Index.Builder(entry).refresh(false).index(getIndexName())
                        .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$
                try {
                    getClient().execute(index);
                } catch (Throwable e) {
                }
            }
            finished = true;
        }
    };
}
 
开发者ID:apiman,项目名称:apiman,代码行数:42,代码来源:ESCacheStoreComponent.java

示例13: write

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.io.AbstractStream#write(io.apiman.gateway.engine.io.IApimanBuffer)
 */
@Override
public void write(IApimanBuffer chunk) {
    if (finished) {
        throw new IllegalStateException("Attempted write after #end() was called."); //$NON-NLS-1$
    }

    if (headPolicyHandler != null) {
        headPolicyHandler.write(chunk);
    } else {
        handleBody(chunk);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:16,代码来源:Chain.java

示例14: scan

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
/**
 * Append the given data to any existing buffer, then scan the buffer
 * looking for the soap headers.  If scanning is complete, this method
 * will return true.  If more data is required, then the method will return
 * false.  If an error condition is detected, then an exception will be
 * thrown.
 * @param buffer
 */
public boolean scan(IApimanBuffer buffer) throws SoapEnvelopeNotFoundException {
    if (this.buffer == null) {
        this.buffer = buffer;
    } else {
        this.buffer.append(buffer);
    }
    boolean scanComplete = doScan();
    // If our buffer is already "max size" but we haven't found the start of the
    // soap envelope yet, then we're likely not going to find it.
    if (!scanComplete && this.buffer.length() >= getMaxBufferLength()) {
        throw new SoapEnvelopeNotFoundException();
    }
    return scanComplete;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:SoapHeaderScanner.java

示例15: write

import io.apiman.gateway.engine.io.IApimanBuffer; //导入依赖的package包/类
public void write(IApimanBuffer chunk) {
    if (fileOS == null) {
        try {
            fileOS = new FileOutputStream(tmpFile);
            fileOS.write(chunk.getBytes());
        } catch (IOException e) {
            // TODO: Log the error.
            // The response will not be cached as it might not contain a valid body
            writeFailed = true;
        }
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:13,代码来源:CachedResponse.java


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