Search in sources :

Example 1 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project wso2-axis2-transports by wso2.

the class XMPPSender method prepareOperationList.

/**
 * Prepares a list of service names deployed in current runtime
 * @param msgCtx
 * @return
 */
private static String prepareOperationList(MessageContext msgCtx, String chatMessage) {
    StringBuffer sb = new StringBuffer();
    // extract service name
    String serviceName = chatMessage.replace("getOperations", "");
    serviceName = serviceName.replaceAll(" ", "");
    if (log.isDebugEnabled()) {
        log.debug("Finding operations for service :" + serviceName);
    }
    try {
        AxisService service = msgCtx.getConfigurationContext().getAxisConfiguration().getService(serviceName);
        Iterator itrOperations = service.getOperations();
        int index = 1;
        while (itrOperations.hasNext()) {
            AxisOperation operation = (AxisOperation) itrOperations.next();
            String parameterList = getParameterListForOperation(operation);
            sb.append(index + "." + operation.getName().getLocalPart() + "(" + parameterList + ")" + "\n");
            index++;
        }
    } catch (AxisFault e) {
        log.error("Error occurred while retreiving AxisService : " + serviceName, e);
        sb.append("Error occurred while retrieving operations for service : " + serviceName);
    }
    return sb.toString();
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) Iterator(java.util.Iterator)

Example 2 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project wso2-axis2-transports by wso2.

the class XMPPPacketListener method createMessageContext.

/**
 * Creates message context using values received in XMPP packet
 * @param packet
 * @return MessageContext
 * @throws AxisFault
 */
private MessageContext createMessageContext(Packet packet) throws AxisFault {
    Message message = (Message) packet;
    Boolean isServerSide = (Boolean) message.getProperty(XMPPConstants.IS_SERVER_SIDE);
    String serviceName = (String) message.getProperty(XMPPConstants.SERVICE_NAME);
    String action = (String) message.getProperty(XMPPConstants.ACTION);
    MessageContext msgContext = null;
    TransportInDescription transportIn = configurationContext.getAxisConfiguration().getTransportIn("xmpp");
    TransportOutDescription transportOut = configurationContext.getAxisConfiguration().getTransportOut("xmpp");
    if ((transportIn != null) && (transportOut != null)) {
        msgContext = configurationContext.createMessageContext();
        msgContext.setTransportIn(transportIn);
        msgContext.setTransportOut(transportOut);
        if (isServerSide != null) {
            msgContext.setServerSide(isServerSide.booleanValue());
        }
        msgContext.setProperty(CONTENT_TYPE, "text/xml");
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
        msgContext.setIncomingTransportName("xmpp");
        Map services = configurationContext.getAxisConfiguration().getServices();
        AxisService axisService = (AxisService) services.get(serviceName);
        msgContext.setAxisService(axisService);
        msgContext.setSoapAction(action);
        // pass the configurationFactory to transport sender
        msgContext.setProperty("XMPPConfigurationFactory", this.xmppConnectionFactory);
        if (packet.getFrom() != null) {
            msgContext.setFrom(new EndpointReference(packet.getFrom()));
        }
        if (packet.getTo() != null) {
            msgContext.setTo(new EndpointReference(packet.getTo()));
        }
        XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
        xmppOutTransportInfo.setConnectionFactory(this.xmppConnectionFactory);
        String packetFrom = packet.getFrom();
        if (packetFrom != null) {
            EndpointReference fromEPR = new EndpointReference(packetFrom);
            xmppOutTransportInfo.setFrom(fromEPR);
            xmppOutTransportInfo.setDestinationAccount(packetFrom);
        }
        // Save Message-Id to set as In-Reply-To on reply
        String xmppMessageId = packet.getPacketID();
        if (xmppMessageId != null) {
            xmppOutTransportInfo.setInReplyTo(xmppMessageId);
        }
        xmppOutTransportInfo.setSequenceID((String) message.getProperty(XMPPConstants.SEQUENCE_ID));
        msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, xmppOutTransportInfo);
        buildSOAPEnvelope(packet, msgContext);
    } else {
        throw new AxisFault("Either transport in or transport out is null");
    }
    return msgContext;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) AxisService(org.apache.axis2.description.AxisService) MessageContext(org.apache.axis2.context.MessageContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) Map(java.util.Map) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project wso2-axis2-transports by wso2.

the class XMPPPacketListener method createSOAPEnvelopeForRawMessage.

/**
 * Creates a SOAP envelope using details found in chat message.
 * @param msgCtx
 * @param chatMessage
 * @return
 */
private SOAPEnvelope createSOAPEnvelopeForRawMessage(MessageContext msgCtx, String chatMessage) throws AxisFault {
    // TODO : need to add error handling logic
    String callRemoved = chatMessage.replaceFirst("call", "");
    // extract Service name
    String serviceName = callRemoved.trim().substring(0, callRemoved.indexOf(":") - 1);
    String operationName = callRemoved.trim().substring(callRemoved.indexOf(":"), callRemoved.indexOf("(") - 1);
    // Extract parameters from IM message
    String parameterList = callRemoved.trim().substring(callRemoved.indexOf("("), callRemoved.trim().length() - 1);
    StringTokenizer st = new StringTokenizer(parameterList, ",");
    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        String name = token.substring(0, token.indexOf("="));
        String value = token.substring(token.indexOf("=") + 1);
        parameterMap.put(name, value);
    }
    SOAPEnvelope envelope = null;
    try {
        msgCtx.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
        if (serviceName != null && serviceName.trim().length() > 0) {
            AxisService axisService = msgCtx.getConfigurationContext().getAxisConfiguration().getService(serviceName);
            msgCtx.setAxisService(axisService);
            AxisOperation axisOperation = axisService.getOperationBySOAPAction("urn:" + operationName);
            if (axisOperation != null) {
                msgCtx.setAxisOperation(axisOperation);
            }
        }
        if (operationName != null && operationName.trim().length() > 0) {
            msgCtx.setSoapAction("urn:" + operationName);
        }
        XMPPOutTransportInfo xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
        // This should be only set for messages received via chat.
        // TODO : need to read from a constant
        xmppOutTransportInfo.setContentType("xmpp/text");
        msgCtx.setServerSide(true);
        // TODO : need to support SOAP12 as well
        SOAPFactory soapFactory = new SOAP11Factory();
        envelope = BuilderUtil.buildsoapMessage(msgCtx, parameterMap, soapFactory);
    // TODO : improve error handling & messages
    } catch (AxisFault e) {
        throw new AxisFault(e.getMessage());
    } catch (OMException e) {
        throw new AxisFault(e.getMessage());
    } catch (FactoryConfigurationError e) {
        throw new AxisFault(e.getMessage());
    }
    return envelope;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) StringTokenizer(java.util.StringTokenizer) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) OMException(org.apache.axiom.om.OMException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 4 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName 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 5 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project MassBank-web by MassBank.

the class AdminActions method editServiceParameters.

@Action(name = EDIT_SERVICE_PARAMETERS)
public View editServiceParameters(HttpServletRequest req) throws AxisFault {
    String serviceName = req.getParameter("axisService");
    AxisService service = configContext.getAxisConfiguration().getServiceForActivation(serviceName);
    if (service.isActive()) {
        if (serviceName != null) {
            req.getSession().setAttribute(Constants.SERVICE, configContext.getAxisConfiguration().getService(serviceName));
        }
        req.setAttribute("serviceName", serviceName);
        req.setAttribute("parameters", getParameters(service));
        Map<String, Map<String, String>> operations = new TreeMap<String, Map<String, String>>();
        for (Iterator<AxisOperation> it = service.getOperations(); it.hasNext(); ) {
            AxisOperation operation = it.next();
            operations.put(operation.getName().getLocalPart(), getParameters(operation));
        }
        req.setAttribute("operations", operations);
    } else {
        req.setAttribute("status", "Service " + serviceName + " is not an active service" + ". \n Only parameters of active services can be edited.");
    }
    return new View("editServiceParameters.jsp");
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

AxisService (org.apache.axis2.description.AxisService)116 AxisFault (org.apache.axis2.AxisFault)54 AxisOperation (org.apache.axis2.description.AxisOperation)36 QName (javax.xml.namespace.QName)27 ArrayList (java.util.ArrayList)26 OMElement (org.apache.axiom.om.OMElement)26 IOException (java.io.IOException)21 URL (java.net.URL)19 ServiceClient (org.apache.axis2.client.ServiceClient)19 Options (org.apache.axis2.client.Options)18 HashMap (java.util.HashMap)17 Service (javax.xml.ws.Service)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17 File (java.io.File)16 Iterator (java.util.Iterator)16 EndpointReference (org.apache.axis2.addressing.EndpointReference)16 List (java.util.List)15 Map (java.util.Map)15 MessageContext (org.apache.axis2.context.MessageContext)15