Search in sources :

Example 6 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class AxisTestEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, AxisTestEndpointContext context, Channel channel, AxisServiceConfigurator[] configurators) throws Exception {
    this.context = context;
    TransportListener listener = context.getTransportListener();
    if (listener instanceof TransportErrorSource) {
        transportErrorSource = (TransportErrorSource) listener;
        errorListener = new TransportErrorListener() {

            public void error(TransportError error) {
                AxisService s = error.getService();
                if (s == null || s == service) {
                    onTransportError(error.getException());
                }
            }
        };
        transportErrorSource.addErrorListener(errorListener);
    } else {
        transportErrorSource = null;
    }
    String path;
    try {
        path = new URI(channel.getEndpointReference().getAddress()).getPath();
    } catch (URISyntaxException ex) {
        path = null;
    }
    String serviceName;
    if (path != null && path.startsWith(Channel.CONTEXT_PATH + "/")) {
        serviceName = path.substring(Channel.CONTEXT_PATH.length() + 1);
    } else {
        serviceName = "TestService-" + UUID.randomUUID();
    }
    service = new AxisService(serviceName);
    service.addOperation(createOperation());
    if (configurators != null) {
        for (AxisServiceConfigurator configurator : configurators) {
            configurator.setupService(service, false);
        }
    }
    // Output service parameters to log file
    // FIXME: This actually doesn't give the expected result because the AxisTestEndpoint might be reused
    // by several test cases and in that case the log file is only produced once
    List<Parameter> params = (List<Parameter>) service.getParameters();
    if (!params.isEmpty()) {
        PrintWriter log = new PrintWriter(logManager.createLog("service-parameters"), false);
        try {
            for (Parameter param : params) {
                log.print(param.getName());
                log.print("=");
                log.println(param.getValue());
            }
        } finally {
            log.close();
        }
    }
    // We want to receive all messages through the same operation:
    service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
    context.getAxisConfiguration().addService(service);
    // The transport may disable the service. In that case, fail directly.
    if (!BaseUtils.isUsingTransport(service, context.getTransportName())) {
        Assert.fail("The service has been disabled by the transport");
    }
}
Also used : TransportError(org.apache.axis2.transport.base.event.TransportError) AxisServiceConfigurator(org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator) AxisService(org.apache.axis2.description.AxisService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TransportErrorSource(org.apache.axis2.transport.base.event.TransportErrorSource) TransportListener(org.apache.axis2.transport.TransportListener) TransportErrorListener(org.apache.axis2.transport.base.event.TransportErrorListener) Parameter(org.apache.axis2.description.Parameter) List(java.util.List) PrintWriter(java.io.PrintWriter) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 7 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class RESTTestCase method checkMessageData.

@Override
protected void checkMessageData(RESTMessage expected, RESTMessage actual) throws Exception {
    Set<Parameter> expectedParameters = new HashSet<Parameter>(Arrays.asList(expected.getParameters()));
    for (Parameter actualParameter : actual.getParameters()) {
        assertTrue(expectedParameters.remove(actualParameter));
    }
    assertTrue(expectedParameters.isEmpty());
}
Also used : Parameter(org.apache.axis2.transport.testkit.message.RESTMessage.Parameter) HashSet(java.util.HashSet)

Example 8 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class UDPSender method waitForReply.

private void waitForReply(MessageContext messageContext, DatagramSocket datagramSocket, String contentType) throws IOException {
    // message context in asnych model
    if (!(messageContext.getAxisOperation() instanceof OutInAxisOperation) && messageContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null) {
        return;
    }
    // TODO set the maximum size parameter
    byte[] inputBuffer = new byte[4096];
    DatagramPacket packet = new DatagramPacket(inputBuffer, inputBuffer.length);
    datagramSocket.receive(packet);
    // create the soap envelope
    try {
        MessageContext respMessageContext = messageContext.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
        InputStream inputStream = new ByteArrayInputStream(inputBuffer, 0, packet.getLength());
        SOAPEnvelope envelope = TransportUtils.createSOAPMessage(respMessageContext, inputStream, contentType);
        respMessageContext.setEnvelope(envelope);
    } catch (XMLStreamException e) {
        throw new AxisFault("Can not build the soap message ", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DatagramPacket(java.net.DatagramPacket) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation)

Example 9 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class ContentTypeRuleFactory method parse.

public static ContentTypeRuleSet parse(Parameter param) throws AxisFault {
    ContentTypeRuleSet ruleSet = new ContentTypeRuleSet();
    Object value = param.getValue();
    if (value instanceof OMElement) {
        OMElement element = (OMElement) value;
        // TODO: seems like a bug in Axis2 and is inconsistent with Synapse's way of parsing parameter in proxy definitions
        if (element == param.getParameterElement()) {
            element = element.getFirstElement();
        }
        if (element.getLocalName().equals("rules")) {
            for (Iterator it = element.getChildElements(); it.hasNext(); ) {
                ruleSet.addRule(parse((OMElement) it.next()));
            }
        } else {
            throw new AxisFault("Expected <rules> element");
        }
    } else {
        ruleSet.addRule(new DefaultRule((String) value));
    }
    return ruleSet;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 10 with Parameter

use of org.apache.axis2.transport.testkit.message.RESTMessage.Parameter in project wso2-axis2-transports by wso2.

the class RabbitMQConnectionFactoryManager method loadConnectionFactoryDefinitions.

/**
 * Create ConnectionFactory instances for the definitions in the transport configuration,
 * and add these into our collection of connectionFactories map keyed by name
 *
 * @param trpDesc the transport description for RabbitMQ AMQP
 */
private void loadConnectionFactoryDefinitions(ParameterInclude trpDesc, SecretResolver secretResolver) {
    for (Parameter parameter : trpDesc.getParameters()) {
        RabbitMQConnectionFactory amqpConFactory = new RabbitMQConnectionFactory(parameter, secretResolver);
        connectionFactories.put(amqpConFactory.getName(), amqpConFactory);
    }
}
Also used : Parameter(org.apache.axis2.description.Parameter)

Aggregations

Parameter (org.apache.axis2.description.Parameter)23 AxisFault (org.apache.axis2.AxisFault)10 AxisService (org.apache.axis2.description.AxisService)6 QName (javax.xml.namespace.QName)4 MessageContext (org.apache.axis2.context.MessageContext)4 Iterator (java.util.Iterator)3 OMElement (org.apache.axiom.om.OMElement)3 AxisOperation (org.apache.axis2.description.AxisOperation)3 AMQP (com.rabbitmq.client.AMQP)2 List (java.util.List)2 Map (java.util.Map)2 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)2 ConsumerCancelledException (com.rabbitmq.client.ConsumerCancelledException)1 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)1 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1