use of org.apache.axis2.util.URL in project wso2-synapse by wso2.
the class URLRewriteMediator method mediate.
public boolean mediate(MessageContext messageContext) {
if (messageContext.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(messageContext)) {
return true;
}
}
URIFragments fragments;
URI inputURI = getInputAddress(messageContext);
if (inputURI != null) {
/*try {
URL url = new URL(inputURI.toString());
} catch (MalformedURLException e) {
handleException("Malformed URL when processing " + inputURI, e, messageContext);
}*/
fragments = new URIFragments(inputURI);
} else {
fragments = new URIFragments();
}
try {
for (RewriteRule r : rules) {
r.rewrite(fragments, messageContext);
}
if (outputProperty != null) {
messageContext.setProperty(outputProperty, fragments.toURIString());
} else {
messageContext.setTo(new EndpointReference(fragments.toURIString()));
}
if (log.isDebugEnabled()) {
log.debug("URL Rewrite Mediator has rewritten the address url : \n " + messageContext.getEnvelope());
}
} catch (URISyntaxException e) {
handleException("Error while constructing a URI from the fragments", e, messageContext);
}
return true;
}
use of org.apache.axis2.util.URL in project wso2-synapse by wso2.
the class AxisOperationClient method sendCustomPayload.
/**
* Send custom payload
*
* <ns:getQuote>
* <ns:request>
* <ns:symbols>
* <ns:company></ns:company>
* </ns:symbols>
* </ns:request>
* </ns:getQuote>
* @param trpUrl Transport url
* @param addUrl WS-Addressing EPR url
* @param symbol Stock quote symbol
* @param action Soap action
* @return
* @throws AxisFault
*/
public OMElement sendCustomPayload(String trpUrl, String addUrl, String symbol, String action) throws AxisFault {
init();
OMElement payload = createCustomPayload(symbol);
operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
setMessageContext(addUrl, trpUrl, action);
outMsgCtx.setEnvelope(createSOAPEnvelope(payload));
operationClient.addMessageContext(outMsgCtx);
operationClient.execute(true);
MessageContext inMsgtCtx = operationClient.getMessageContext("In");
SOAPEnvelope response = inMsgtCtx.getEnvelope();
return response;
}
use of org.apache.axis2.util.URL in project wso2-synapse by wso2.
the class AxisOperationClient method createMultipleQuoteRequest.
/**
* Creating the multiple quote request
*
* @param trpUrl Transport URL
* @param addUrl WS-Addressing EPR url
* @param symbol Stock quote symbol
* @param iterations No of iterations
* @return Response from the backend
* @throws IOException
*/
private OMElement createMultipleQuoteRequest(String trpUrl, String addUrl, String symbol, int iterations) throws IOException {
init();
operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
setMessageContext(addUrl, trpUrl, null);
outMsgCtx.setEnvelope(createSOAPEnvelope(symbol, iterations));
operationClient.addMessageContext(outMsgCtx);
operationClient.execute(true);
MessageContext inMsgtCtx = operationClient.getMessageContext("In");
SOAPEnvelope response = inMsgtCtx.getEnvelope();
return response;
}
use of org.apache.axis2.util.URL in project wso2-synapse by wso2.
the class SynapseXPathVariableContext method getVariableValue.
/**
* Gets the variable values resolved from the context. This includes the
* <dl>
* <dt><tt>body</tt></dt>
* <dd>The SOAP 1.1 or 1.2 body element.</dd>
* <dt><tt>header</tt></dt>
* <dd>The SOAP 1.1 or 1.2 header element.</dd>
* </dl>
* and the following variable prefixes
* <dl>
* <dt><tt>ctx</tt></dt>
* <dd>Prefix for Synapse MessageContext properties</dd>
* <dt><tt>axis2</tt></dt>
* <dd>Prefix for Axis2 MessageContext properties</dd>
* <dt><tt>trp</tt></dt>
* <dd>Prefix for the transport headers</dd>
* </dl>
* If the variable is unknown, this method attempts to resolve it using
* the parent variable context.
*
* @param namespaceURI namespaces for the variable resolution
* @param prefix string prefix for the variable resolution
* @param localName string local name for the variable resolution
* @return Resolved variable value
* @throws UnresolvableException if the variable specified does not found
*/
public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException {
if (namespaceURI == null) {
if (env != null) {
if (SynapseXPathConstants.SOAP_BODY_VARIABLE.equals(localName)) {
return env.getBody();
} else if (SynapseXPathConstants.SOAP_HEADER_VARIABLE.equals(localName)) {
return env.getHeader();
} else if (SynapseXPathConstants.SOAP_ENVELOPE_VARIABLE.equals(localName)) {
return env;
}
}
if (prefix != null && !"".equals(prefix) && synCtx != null) {
if (SynapseXPathConstants.MESSAGE_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
return synCtx.getProperty(localName);
} else if (SynapseXPathConstants.AXIS2_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
return ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(localName);
} else if (SynapseXPathConstants.FUNC_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
TemplateContext topCtxt = functionStack.peek();
if (topCtxt != null) {
Object result = topCtxt.getParameterValue(localName);
if (result != null && result instanceof SynapseXPath && env != null) {
SynapseXPath expression = (SynapseXPath) topCtxt.getParameterValue(localName);
try {
return expression.evaluate(env);
} catch (JaxenException e) {
return null;
}
} else {
return result;
}
}
} else if (SynapseXPathConstants.TRANSPORT_VARIABLE_PREFIX.equals(prefix)) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
return headersMap.get(localName);
} else {
return null;
}
} else if (SynapseXPathConstants.URL_VARIABLE_PREFIX.equals(prefix)) {
EndpointReference toEPR = synCtx.getTo();
if (toEPR != null) {
String completeURL = toEPR.getAddress();
AxisBindingOperation axisBindingOperation = (AxisBindingOperation) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(Constants.AXIS_BINDING_OPERATION);
String queryParameterSeparator = null;
if (axisBindingOperation != null) {
queryParameterSeparator = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
}
if (queryParameterSeparator == null) {
queryParameterSeparator = WSDL20DefaultValueHolder.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
}
int i = completeURL.indexOf("?");
if (i > -1) {
String queryString = completeURL.substring(i + 1);
if (queryString != null && !queryString.equals("")) {
String[] params = queryString.split(queryParameterSeparator);
if (params == null || params.length == 0) {
return "";
}
for (String param : params) {
String[] temp = param.split("=");
if (temp != null && temp.length >= 1) {
if (temp[0].equalsIgnoreCase(localName)) {
try {
return temp.length > 1 ? URIEncoderDecoder.decode(temp[1]) : "";
} catch (UnsupportedEncodingException e) {
String msg = "Couldn't decode the URL parameter " + "value " + temp[1] + " with name " + localName;
log.error(msg, e);
throw new UnresolvableException(msg + e.getMessage());
}
}
}
}
}
}
}
return "";
} else if (SynapseXPathConstants.OPERATION_SCOPE_VARIABLE_PREFIX.equals(prefix)) {
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
return axis2smc.getAxis2MessageContext().getOperationContext().getProperty(localName);
} else if (SynapseXPathConstants.SYSTEM_SCOPE_VARIABLE_PREFIX.equals(prefix)) {
String propVal = System.getProperty(localName);
if (propVal != null) {
return propVal;
} else {
return "";
}
} else {
Object o = synCtx.getProperty(prefix);
if (o instanceof Map) {
Object valueObject = ((Map) o).get(localName);
if (valueObject != null) {
return valueObject.toString();
}
}
}
}
}
// try resolving using available custom extensions
Object obj = XpathExtensionUtil.resolveVariableContext(synCtx, namespaceURI, prefix, localName);
if (obj != null) {
return obj;
}
return parent.getVariableValue(namespaceURI, prefix, localName);
}
use of org.apache.axis2.util.URL in project wso2-synapse by wso2.
the class DefaultHttpGetProcessor method generateXsd.
/**
* Generates Schema.
*
* @param response HttpResponse
* @param conn NHttpServerConnection
* @param os OutputStream
* @param serviceName service name
* @param parameters url parameters
*/
protected void generateXsd(HttpRequest request, HttpResponse response, MessageContext messageCtx, NHttpServerConnection conn, OutputStream os, String serviceName, Map<String, String> parameters, boolean isRestDispatching) {
if (parameters.get("xsd") == null || "".equals(parameters.get("xsd"))) {
AxisService service = cfgCtx.getAxisConfiguration().getServices().get(serviceName);
if (service != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
service.printSchema(baos);
response.addHeader(CONTENT_TYPE, TEXT_XML);
serverHandler.commitResponseHideExceptions(conn, response);
os.write(baos.toByteArray());
closeOutputStream(os);
} catch (Exception e) {
handleBrowserException(response, conn, os, "Error generating ?xsd output for service : " + serviceName, e);
}
} else {
processGetAndDelete(request, response, messageCtx, conn, os, serviceName, isRestDispatching);
}
} else {
// cater for named xsds - check for the xsd name
String schemaName = parameters.get("xsd");
AxisService service = cfgCtx.getAxisConfiguration().getServices().get(serviceName);
if (service != null) {
// run the population logic just to be sure
service.populateSchemaMappings();
// write out the correct schema
Map schemaTable = service.getSchemaMappingTable();
XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
if (schema == null) {
int dotIndex = schemaName.indexOf('.');
if (dotIndex > 0) {
String schemaKey = schemaName.substring(0, dotIndex);
schema = (XmlSchema) schemaTable.get(schemaKey);
}
}
// schema found - write it to the stream
if (schema != null) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
schema.write(baos);
response.addHeader(CONTENT_TYPE, TEXT_XML);
serverHandler.commitResponseHideExceptions(conn, response);
os.write(baos.toByteArray());
closeOutputStream(os);
} catch (Exception e) {
handleBrowserException(response, conn, os, "Error generating named ?xsd output for service : " + serviceName, e);
}
} else {
// no schema available by that name - send 404
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
closeOutputStream(os);
}
} else {
processGetAndDelete(request, response, messageCtx, conn, os, serviceName, isRestDispatching);
}
}
}
Aggregations