本文整理匯總了Java中org.apache.commons.lang3.SerializationUtils類的典型用法代碼示例。如果您正苦於以下問題:Java SerializationUtils類的具體用法?Java SerializationUtils怎麽用?Java SerializationUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SerializationUtils類屬於org.apache.commons.lang3包,在下文中一共展示了SerializationUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyServiceAttributeFilterAllowedAttributes
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void verifyServiceAttributeFilterAllowedAttributes() {
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAllowedAttributes(Arrays.asList("attr1", "attr3"));
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), 2);
assertTrue(attr.containsKey("attr1"));
assertTrue(attr.containsKey("attr3"));
final byte[] data = SerializationUtils.serialize(policy);
final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
assertNotNull(p2);
assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:25,代碼來源:RegisteredServiceAttributeReleasePolicyTests.java
示例2: verifyServiceAttributeFilterAllAttributes
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void verifyServiceAttributeFilterAllAttributes() {
final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), map.size());
final byte[] data = SerializationUtils.serialize(policy);
final ReturnAllAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
assertNotNull(p2);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:RegisteredServiceAttributeReleasePolicyTests.java
示例3: testMessageSliceWithStreamWriteFailure
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void testMessageSliceWithStreamWriteFailure() throws IOException {
try (MessageAssembler assembler = newMessageAssembler("testMessageSliceWithStreamWriteFailure")) {
IOException mockFailure = new IOException("mock IOException");
doThrow(mockFailure).when(mockFiledBackedStream).write(any(byte[].class), anyInt(), anyInt());
doThrow(mockFailure).when(mockFiledBackedStream).write(any(byte[].class));
doThrow(mockFailure).when(mockFiledBackedStream).write(anyInt());
doThrow(mockFailure).when(mockFiledBackedStream).flush();
final MessageSliceIdentifier identifier = new MessageSliceIdentifier(IDENTIFIER, 1);
final BytesMessage message = new BytesMessage(new byte[]{1, 2, 3});
final MessageSlice messageSlice = new MessageSlice(identifier, SerializationUtils.serialize(message), 1, 1,
SlicedMessageState.INITIAL_SLICE_HASH_CODE, testProbe.ref());
assembler.handleMessage(messageSlice, testProbe.ref());
final MessageSliceReply reply = testProbe.expectMsgClass(MessageSliceReply.class);
assertFailedMessageSliceReply(reply, IDENTIFIER, false);
assertEquals("Failure cause", mockFailure, reply.getFailure().get().getCause());
assertFalse("MessageAssembler did not remove state for " + identifier, assembler.hasState(identifier));
verify(mockFiledBackedStream).cleanup();
}
}
示例4: verifyServiceAttributeFilterAllowedAttributesWithARegexFilter
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void verifyServiceAttributeFilterAllowedAttributesWithARegexFilter() {
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAllowedAttributes(Arrays.asList("attr1", "attr3", "another"));
policy.setAttributeFilter(new RegisteredServiceRegexAttributeFilter("v3"));
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), 1);
assertTrue(attr.containsKey("attr3"));
final byte[] data = SerializationUtils.serialize(policy);
final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
assertNotNull(p2);
assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
assertEquals(p2.getAttributeFilter(), policy.getAttributeFilter());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:26,代碼來源:RegisteredServiceRegexAttributeFilterTests.java
示例5: verifyServiceAttributeFilterAllowedAttributesWithARegexFilter
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void verifyServiceAttributeFilterAllowedAttributesWithARegexFilter() {
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAllowedAttributes(Arrays.asList("attr1", "attr3", "another"));
policy.setAttributeFilter(new RegisteredServiceRegexAttributeFilter("v3"));
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), 1);
assertTrue(attr.containsKey("attr3"));
final byte[] data = SerializationUtils.serialize(policy);
final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
assertNotNull(p2);
assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
assertEquals(p2.getAttributeFilter(), policy.getAttributeFilter());
}
示例6: testMessageSliceWithByteSourceFailure
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void testMessageSliceWithByteSourceFailure() throws IOException {
try (MessageAssembler assembler = newMessageAssembler("testMessageSliceWithByteSourceFailure")) {
IOException mockFailure = new IOException("mock IOException");
doThrow(mockFailure).when(mockByteSource).openStream();
doThrow(mockFailure).when(mockByteSource).openBufferedStream();
final MessageSliceIdentifier identifier = new MessageSliceIdentifier(IDENTIFIER, 1);
final BytesMessage message = new BytesMessage(new byte[]{1, 2, 3});
final MessageSlice messageSlice = new MessageSlice(identifier, SerializationUtils.serialize(message), 1, 1,
SlicedMessageState.INITIAL_SLICE_HASH_CODE, testProbe.ref());
assembler.handleMessage(messageSlice, testProbe.ref());
final MessageSliceReply reply = testProbe.expectMsgClass(MessageSliceReply.class);
assertFailedMessageSliceReply(reply, IDENTIFIER, false);
assertEquals("Failure cause", mockFailure, reply.getFailure().get().getCause());
assertFalse("MessageAssembler did not remove state for " + identifier, assembler.hasState(identifier));
verify(mockFiledBackedStream).cleanup();
}
}
示例7: invokeSecurityTokenServiceForToken
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
private void invokeSecurityTokenServiceForToken(final AuthenticationTransaction transaction, final AuthenticationBuilder builder,
final WSFederationRegisteredService rp, final SecurityTokenServiceClient sts) {
final UsernamePasswordCredential up = transaction.getCredentials()
.stream()
.filter(UsernamePasswordCredential.class::isInstance)
.map(UsernamePasswordCredential.class::cast)
.findFirst()
.orElse(null);
if (up != null) {
try {
sts.getProperties().put(SecurityConstants.USERNAME, up.getUsername());
final String uid = credentialCipherExecutor.encode(up.getUsername());
sts.getProperties().put(SecurityConstants.PASSWORD, uid);
final SecurityToken token = sts.requestSecurityToken(rp.getAppliesTo());
final String tokenStr = EncodingUtils.encodeBase64(SerializationUtils.serialize(token));
builder.addAttribute(WSFederationConstants.SECURITY_TOKEN_ATTRIBUTE, tokenStr);
} catch (final Exception e) {
throw new AuthenticationException(e.getMessage());
}
}
}
示例8: generateReEncryptionKey
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Override
public byte[] generateReEncryptionKey(String encryptionKeyName, String dstEncryptionKeyName, KeyPairMaterial destinationKey)
throws IOException {
BBS98BCReEncryptionKeyGenerator reEncryptionKeyGenerator =
new BBS98BCReEncryptionKeyGenerator();
KeyPairVersion srcKey = provider.getKeyPairVersion(encryptionKeyName);
KeyPairSpec srcKeySpec = new KeyPairSpec(srcKey.getPublicMaterial().getMaterial(),
srcKey.getPrivateMaterial().getMaterial(), reEncryptionKeyGenerator.getAlgorithm());
KeyPairSpec dstKeySpec = new KeyPairSpec(destinationKey.getPublic(),
destinationKey.getPrivate(), reEncryptionKeyGenerator.getAlgorithm());
ECPrivateKey dstSk =
SerializationUtils.deserialize(dstKeySpec.getPrivate().getKeyMaterial());
try {
reEncryptionKeyGenerator.initialize(dstSk.getParameters());
ReEncryptionKey reKey = reEncryptionKeyGenerator.generateReEncryptionKey(
srcKeySpec.getPrivate().getKeyMaterial(), dstKeySpec.getPrivate().getKeyMaterial());
return reKey.getEncoded();
} catch(InvalidAlgorithmParameterException e)
{
e.printStackTrace(System.err);
}
return null;
}
示例9: testSingleMessageSlice
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void testSingleMessageSlice() {
try (MessageAssembler assembler = newMessageAssembler("testSingleMessageSlice")) {
final FileBackedOutputStream fileBackStream = spy(new FileBackedOutputStream(100000000, null));
doReturn(fileBackStream).when(mockFiledBackedStreamFactory).newInstance();
final MessageSliceIdentifier identifier = new MessageSliceIdentifier(IDENTIFIER, 1);
final BytesMessage message = new BytesMessage(new byte[]{1, 2, 3});
final MessageSlice messageSlice = new MessageSlice(identifier, SerializationUtils.serialize(message), 1, 1,
SlicedMessageState.INITIAL_SLICE_HASH_CODE, testProbe.ref());
assembler.handleMessage(messageSlice, testProbe.ref());
final MessageSliceReply reply = testProbe.expectMsgClass(MessageSliceReply.class);
assertSuccessfulMessageSliceReply(reply, IDENTIFIER, 1);
assertAssembledMessage(mockAssembledMessageCallback, message, testProbe.ref());
assertFalse("MessageAssembler did not remove state for " + identifier, assembler.hasState(identifier));
verify(fileBackStream).cleanup();
}
}
示例10: buildCustomizedExecutorTaskInfo
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
private Protos.TaskInfo buildCustomizedExecutorTaskInfo(final TaskContext taskContext, final CloudAppConfiguration appConfig, final CloudJobConfiguration jobConfig,
final ShardingContexts shardingContexts, final Protos.Offer offer, final Protos.CommandInfo command) {
Protos.TaskInfo.Builder result = Protos.TaskInfo.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskContext.getId()).build())
.setName(taskContext.getTaskName()).setSlaveId(offer.getSlaveId())
.addResources(buildResource("cpus", jobConfig.getCpuCount(), offer.getResourcesList()))
.addResources(buildResource("mem", jobConfig.getMemoryMB(), offer.getResourcesList()))
.setData(ByteString.copyFrom(new TaskInfoData(shardingContexts, jobConfig).serialize()));
Protos.ExecutorInfo.Builder executorBuilder = Protos.ExecutorInfo.newBuilder().setExecutorId(Protos.ExecutorID.newBuilder()
.setValue(taskContext.getExecutorId(jobConfig.getAppName()))).setCommand(command)
.addResources(buildResource("cpus", appConfig.getCpuCount(), offer.getResourcesList()))
.addResources(buildResource("mem", appConfig.getMemoryMB(), offer.getResourcesList()));
if (env.getJobEventRdbConfiguration().isPresent()) {
executorBuilder.setData(ByteString.copyFrom(SerializationUtils.serialize(env.getJobEventRdbConfigurationMap()))).build();
}
return result.setExecutor(executorBuilder.build()).build();
}
示例11: testAssembledMessageStateExpiration
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void testAssembledMessageStateExpiration() throws IOException {
final int expiryDuration = 200;
try (MessageAssembler assembler = newMessageAssemblerBuilder("testAssembledMessageStateExpiration")
.expireStateAfterInactivity(expiryDuration, TimeUnit.MILLISECONDS).build()) {
final MessageSliceIdentifier identifier = new MessageSliceIdentifier(IDENTIFIER, 1);
final BytesMessage message = new BytesMessage(new byte[]{1, 2, 3});
final MessageSlice messageSlice = new MessageSlice(identifier, SerializationUtils.serialize(message), 1, 2,
SlicedMessageState.INITIAL_SLICE_HASH_CODE, testProbe.ref());
assembler.handleMessage(messageSlice, testProbe.ref());
final MessageSliceReply reply = testProbe.expectMsgClass(MessageSliceReply.class);
assertSuccessfulMessageSliceReply(reply, IDENTIFIER, 1);
assertTrue("MessageAssembler should have remove state for " + identifier, assembler.hasState(identifier));
Uninterruptibles.sleepUninterruptibly(expiryDuration + 50, TimeUnit.MILLISECONDS);
assertFalse("MessageAssembler did not remove state for " + identifier, assembler.hasState(identifier));
verify(mockFiledBackedStream).cleanup();
}
}
示例12: run
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Override
public void run() {
Thread.currentThread().setContextClassLoader(TaskThread.class.getClassLoader());
executorDriver.sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(Protos.TaskState.TASK_RUNNING).build());
Map<String, Object> data = SerializationUtils.deserialize(taskInfo.getData().toByteArray());
ShardingContexts shardingContexts = (ShardingContexts) data.get("shardingContext");
@SuppressWarnings("unchecked")
JobConfigurationContext jobConfig = new JobConfigurationContext((Map<String, String>) data.get("jobConfigContext"));
try {
ElasticJob elasticJob = getElasticJobInstance(jobConfig);
final CloudJobFacade jobFacade = new CloudJobFacade(shardingContexts, jobConfig, jobEventBus);
if (jobConfig.isTransient()) {
JobExecutorFactory.getJobExecutor(elasticJob, jobFacade).execute();
executorDriver.sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(Protos.TaskState.TASK_FINISHED).build());
} else {
new DaemonTaskScheduler(elasticJob, jobConfig, jobFacade, executorDriver, taskInfo.getTaskId()).init();
}
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
log.error("Elastic-Job-Cloud-Executor error", ex);
executorDriver.sendStatusUpdate(Protos.TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(Protos.TaskState.TASK_ERROR).setMessage(ExceptionUtil.transform(ex)).build());
executorDriver.stop();
throw ex;
}
}
示例13: testSlicingWithFailure
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Test
public void testSlicingWithFailure() {
LOG.info("testSlicingWithFailure starting");
final BytesMessage message = new BytesMessage(new byte[]{1, 2, 3});
final int messageSliceSize = SerializationUtils.serialize(message).length / 2;
try (MessageSlicer slicer = newMessageSlicer("testSlicingWithFailure", messageSliceSize)) {
final boolean wasSliced = slice(slicer, IDENTIFIER, message, sendToProbe.ref(), replyToProbe.ref(),
mockOnFailureCallback);
assertTrue(wasSliced);
MessageSlice sliceMessage = sendToProbe.expectMsgClass(MessageSlice.class);
MessageSliceException failure = new MessageSliceException("mock failure",
new IOException("mock IOException"));
slicer.handleMessage(MessageSliceReply.failed(sliceMessage.getIdentifier(), failure, sendToProbe.ref()));
assertFailureCallback(IOException.class);
assertFalse("MessageSlicer did not remove state for " + sliceMessage.getIdentifier(),
slicer.hasState(sliceMessage.getIdentifier()));
}
LOG.info("testSlicingWithFailure ending");
}
示例14: handleData
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@Override
public void handleData(NBTTagCompound data)
{
Biome b = Biome.getBiome(data.getInteger("biomeID"));
DimBlockPos dbp = SerializationUtils.deserialize(data.getByteArray("blockPosData"));
if (MC.getSide() == Side.CLIENT)
{
VoidApi.proxy.getClientListener().addScheduledTask(() -> {
if (VoidApi.proxy.getClientWorld().isBlockLoaded(dbp.pos))
ChunkUtils.setBiomeAt(b, dbp.pos, VoidApi.proxy.getClientWorld());}
);
}
else
{
WorldServer ws = DimensionManager.getWorld(dbp.dim);
ws.addScheduledTask(() -> {
if (ws.isBlockLoaded(dbp.pos))
ChunkUtils.setBiomeAt(b, dbp.pos, ws);}
);
}
}
示例15: createResponse
import org.apache.commons.lang3.SerializationUtils; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public MockResponse createResponse(MockRequest request) {
Optional<String> targetKey = getObjectKey(request);
Optional<Bucket> targetBucket = getBucket(request);
Optional<S3Object> source = getSourceFromHeader(request);
if (request.utils().areAllPresent(targetKey, targetBucket, source)) {
S3Object copy = SerializationUtils.clone(source.get());
copy.setKey(targetKey.get());
targetBucket.get().getObjects().add(copy);
}
return new MockResponse(
successBody("CopyObject", "<LastModified>" + ISO8601Utils.format(new Date())
+ "</LastModified>\n" + " <ETag>" + UUID.randomUUID().toString() + "</ETag>"));
}