List of usage examples for javax.xml.ws Holder Holder
public Holder()
From source file:org.apache.servicecomb.loadbalance.TestLoadbalanceHandler.java
@Test public void retryPoolDaemon() throws ExecutionException, InterruptedException { ExecutorService RETRY_POOL = Deencapsulation.getField(handler, "RETRY_POOL"); Holder<Thread> nameHolder = new Holder<>(); RETRY_POOL.submit(() -> {/*from www . jav a 2 s .c om*/ nameHolder.value = Thread.currentThread(); }).get(); Assert.assertThat(nameHolder.value.getName(), Matchers.startsWith("retry-pool-thread-")); Assert.assertTrue(nameHolder.value.isDaemon()); }
From source file:org.apache.servicecomb.transport.highway.TestHighwayClient.java
private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, HighwayClientConnection tcpClient, Object decodedResponse) throws Exception { new MockUp<VertxUtils>() { @Mock// w w w. j av a 2s . co m <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) { return true; } }; new MockUp<ClientPoolManager<HighwayClientConnectionPool>>() { @Mock public HighwayClientConnectionPool findClientPool(boolean sync) { return pool; } }; new MockUp<ProtobufManager>() { @Mock public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) { return operationProtobuf; } }; new MockUp<HighwayClientConnectionPool>() { @Mock HighwayClientConnection findOrCreateClient(String endpoint) { return tcpClient; } }; new MockUp<HighwayCodec>() { @Mock public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf, long msgId) { return null; } @Mock Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData) throws Throwable { if (decodedResponse instanceof Response) { return (Response) decodedResponse; } throw (Throwable) decodedResponse; } }; client.init(vertx); Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta); Mockito.when(invocation.getEndpoint()).thenReturn(endpoint); Mockito.when(invocation.getEndpoint().getEndpoint()).thenReturn("endpoint"); Mockito.when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor()); Mockito.when(invocation.getInvocationStageTrace()).thenReturn(invocationStageTrace); Holder<Object> result = new Holder<>(); client.send(invocation, ar -> { result.value = ar.getResult(); }); return result.value; }
From source file:org.codice.alliance.core.email.impl.EmailSenderImplTest.java
@Test public void testAttachment() throws IOException, MessagingException { final List<String> attachmentLines = new LinkedList<>(); Holder<String> filename = new Holder<>(); int bodyPartIndex = 1; emailSender = new EmailSenderImpl() { @Override//from w ww . ja v a2 s . c om void send(Message message) throws MessagingException { try { FileInputStream fis = (FileInputStream) ((MimeMultipart) message.getContent()) .getBodyPart(bodyPartIndex).getContent(); filename.value = ((MimeMultipart) message.getContent()).getBodyPart(bodyPartIndex) .getFileName(); attachmentLines.addAll(IOUtils.readLines(fis)); } catch (IOException e) { throw new RuntimeException(e); } } }; emailSender.setMailHost(HOST); String attachedData = "attached data"; String attachedFilename = "fileName.txt"; emailSender.sendEmail(FROM_ADDR, TO_ADDR, SUBJECT_LINE, BODY, Collections.singletonList( new ImmutablePair<>(attachedFilename, new ByteArrayInputStream(attachedData.getBytes())))); assertThat(filename.value, is(attachedFilename)); assertThat(attachmentLines, is(Collections.singletonList(attachedData))); }
From source file:org.codice.alliance.core.email.impl.EmailSenderImplTest.java
/** Set the max attachment size to 1MB and send an attachment of size 2MB. */ @Test(expected = IOException.class) public void testTooBigAttachment() throws IOException, MessagingException { final List<String> attachmentLines = new LinkedList<>(); Holder<String> filename = new Holder<>(); int bodyPartIndex = 1; emailSender = new EmailSenderImpl() { @Override/*from www . ja va 2 s .c om*/ void send(Message message) throws MessagingException { try { FileInputStream fis = (FileInputStream) ((MimeMultipart) message.getContent()) .getBodyPart(bodyPartIndex).getContent(); filename.value = ((MimeMultipart) message.getContent()).getBodyPart(bodyPartIndex) .getFileName(); attachmentLines.addAll(IOUtils.readLines(fis)); } catch (IOException e) { throw new RuntimeException(e); } } }; emailSender.setMaxAttachmentSize(1); emailSender.setMailHost(HOST); String attachedData = generateString(2000000); String attachedFilename = "fileName.txt"; emailSender.sendEmail(FROM_ADDR, TO_ADDR, SUBJECT_LINE, BODY, Collections.singletonList( new ImmutablePair<>(attachedFilename, new ByteArrayInputStream(attachedData.getBytes())))); }
From source file:org.gatein.wsrp.consumer.handlers.ActionHandler.java
@Override protected BlockingInteractionResponse performRequest(PerformBlockingInteraction interaction) throws Exception { Holder<UpdateResponse> updateResponseHolder = new Holder<UpdateResponse>(); Holder<String> redirectURL = new Holder<String>(); // invocation if (debug) {/*from w ww .ja va 2s .c om*/ log.debug("performBlockingInteraction on '" + interaction.getPortletContext().getPortletHandle() + "'"); } final Holder<List<Extension>> extensions = new Holder<List<Extension>>(); consumer.getMarkupService().performBlockingInteraction(interaction.getRegistrationContext(), interaction.getPortletContext(), interaction.getRuntimeContext(), interaction.getUserContext(), interaction.getMarkupParams(), interaction.getInteractionParams(), updateResponseHolder, redirectURL, extensions); // construct response final BlockingInteractionResponse response; if (redirectURL.value != null) { response = WSRPTypeFactory.createBlockingInteractionResponse(redirectURL.value); } else { response = WSRPTypeFactory.createBlockingInteractionResponse(updateResponseHolder.value); } if (ParameterValidation.existsAndIsNotEmpty(extensions.value) && !WSRPUtils.isSingletonListWithNullOrEmptyElement(extensions.value)) { response.getExtensions().addAll(extensions.value); } return response; }
From source file:org.gatein.wsrp.consumer.handlers.ResourceHandler.java
@Override protected ResourceResponse performRequest(GetResource request) throws Exception { Holder<SessionContext> sessionContextHolder = new Holder<SessionContext>(); Holder<ResourceContext> resourceContextHolder = new Holder<ResourceContext>(); Holder<PortletContext> portletContextHolder = new Holder<PortletContext>(request.getPortletContext()); final Holder<List<Extension>> extensions = new Holder<List<Extension>>(); consumer.getMarkupService().getResource(request.getRegistrationContext(), portletContextHolder, request.getRuntimeContext(), request.getUserContext(), request.getResourceParams(), resourceContextHolder, sessionContextHolder, extensions); ResourceResponse resourceResponse = WSRPTypeFactory.createResourceResponse(resourceContextHolder.value); resourceResponse.setPortletContext(portletContextHolder.value); resourceResponse.setSessionContext(sessionContextHolder.value); if (ParameterValidation.existsAndIsNotEmpty(extensions.value) && !WSRPUtils.isSingletonListWithNullOrEmptyElement(extensions.value)) { resourceResponse.getExtensions().addAll(extensions.value); }//ww w . j ava2 s . c o m return resourceResponse; }
From source file:org.mule.modules.zuora.zuora.api.CxfZuoraClient.java
@Override public User getUserInfo() throws Exception { try {//from w w w . jav a2s . c o m Holder<String> userId = new Holder<String>(); Holder<String> tenantId = new Holder<String>(); Holder<String> tenantName = new Holder<String>(); Holder<String> userEmail = new Holder<String>(); Holder<String> userFullName = new Holder<String>(); Holder<String> username = new Holder<String>(); this.soap.getUserInfo(tenantId, tenantName, userEmail, userFullName, userId, username); // TODO return new User(userId.value, username.value, userEmail.value, userFullName.value, tenantId.value, tenantName.value); } catch (UnexpectedErrorFault unexpectedErrorFault) { if (unexpectedErrorFault.getFaultInfo().getFaultCode() == ErrorCode.INVALID_SESSION) { throw new SessionTimedOutException(); } throw unexpectedErrorFault; } }
From source file:org.nuxeo.stanbol.temis.engine.TemisLuxidEnhancementEngine.java
@Override protected void activate(ComponentContext ce) throws ConfigurationException { super.activate(ce); @SuppressWarnings("unchecked") Dictionary<String, String> properties = ce.getProperties(); String urlString = getFromPropertiesOrEnv(properties, SERVICE_WSDL_URL_PROPERTY); accountId = getFromPropertiesOrEnv(properties, SERVICE_ACCOUNT_ID_PROPERTY); accountPassword = getFromPropertiesOrEnv(properties, SERVICE_ACCOUNT_PASSWORD_PROPERTY); annotationPlan = getFromPropertiesOrEnv(properties, SERVICE_ANNOTATION_PLAN_PROPERTY); casConsumer = getFromPropertiesOrEnv(properties, SERVICE_CAS_CONSUMER_PROPERTY, DEFAULT_CAS_CONSUMER); // check the connection to fail early in case of bad configuration // parameters String sessionId = null;// ww w.jav a2 s .com try { TemisWebService tws = new TemisWebService(new URL(urlString), SERVICE_NAME); wsPort = tws.getWebAnnotationPort(); sessionId = connect(); // check that the requested annotationPlan is available to the // authenticated user Holder<ArrayOfAnnotationPlan> plans = new Holder<ArrayOfAnnotationPlan>(); Holder<Fault> fault = new Holder<Fault>(); wsPort.getPlans(sessionId, plans, fault); handleFault(fault); boolean foundPlan = false; List<String> availablePlanNames = new ArrayList<String>(); for (AnnotationPlan availablePlan : plans.value.getReturn()) { if (availablePlan.getName().equals(annotationPlan)) { foundPlan = true; break; } availablePlanNames.add(availablePlan.getName()); } if (!foundPlan) { throw new TemisEnhancementEngineException(String.format( "The requested annotationPlan '%s' is does not belong to" + " the list of available plans: '%s'", annotationPlan, StringUtils.join(availablePlanNames, ", "))); } } catch (TemisEnhancementEngineException e) { log.error(e, e); throw new ConfigurationException(SERVICE_WSDL_URL_PROPERTY, e.getMessage()); } catch (MalformedURLException e) { throw new ConfigurationException(SERVICE_WSDL_URL_PROPERTY, e.getMessage()); } finally { if (sessionId != null) { wsPort.closeSession(sessionId); } } }
From source file:org.nuxeo.stanbol.temis.engine.TemisLuxidEnhancementEngine.java
public String connect() throws TemisEnhancementEngineException { Holder<String> token = new Holder<String>(); Holder<Fault> fault = new Holder<Fault>(); wsPort.authenticate(accountId, accountPassword, token, fault); handleFault(fault);//from w w w . ja v a 2 s.c o m return token.value; }
From source file:org.nuxeo.stanbol.temis.engine.TemisLuxidEnhancementEngine.java
@Override public void computeEnhancements(ContentItem ci) throws EngineException { String token = null;/* w ww .j a va2 s . c om*/ LiteralFactory literalFactory = LiteralFactory.getInstance(); MGraph g = ci.getMetadata(); try { token = connect(); Holder<Fault> fault = new Holder<Fault>(); // TODO: read charset from the request instead of hardcoding UTF-8 // requirement // TODO: extract ~3 sentences context for each annotation is // possible String luxidInput = IOUtils.toString(ci.getStream(), "UTF-8"); Holder<Output> output = new Holder<Output>(); wsPort.annotateString(token, annotationPlan, luxidInput, casConsumer, output, fault); handleFault(fault); for (OutputPart part : output.value.getParts()) { if ("DOCUMENT".equals(part.getName()) && "text/xml".equals(part.getMime())) { String luxidOutput = part.getText(); handleLuxidOutput(ci, literalFactory, g, luxidInput, luxidOutput); } } } catch (IOException e) { throw new EngineException(e); } catch (JAXBException e) { throw new EngineException(e); } finally { if (token != null) { wsPort.closeSession(token); } } }