You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2005/07/14 09:37:10 UTC
svn commit: r219006 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis2/clientapi/ core/src/org/apache/axis2/context/
core/src/org/apache/axis2/transport/http/ samples/src/sample/yahooservices/
samples/src/sample/yahooservices/RESTSearch/
Author: deepal
Date: Thu Jul 14 00:37:09 2005
New Revision: 219006
URL: http://svn.apache.org/viewcvs?rev=219006&view=rev
Log:
applying Samindas' patch
Added:
webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/
webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/
webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/RESTSearchClient.java
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java?rev=219006&r1=219005&r2=219006&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java Thu Jul 14 00:37:09 2005
@@ -1,20 +1,20 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Runtime state of the engine
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Runtime state of the engine
+*/
package org.apache.axis2.clientapi;
import org.apache.axis2.addressing.EndpointReference;
@@ -41,8 +41,15 @@
protected String soapVersionURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
protected String soapAction = "";
protected boolean doREST = false;
+ protected boolean doRestThroughPOST = false;
protected String wsaAction;
+ public void setRestThroughPOST(boolean b) {
+ doRestThroughPOST = b;
+ }
+
+
+
public void setDoREST(boolean b) {
doREST = b;
}
@@ -75,6 +82,7 @@
serviceContext.getServiceConfig().addOperation(axisop);
}
msgCtx.setDoingREST(doREST);
+ msgCtx.setRestThroughPOST(doRestThroughPOST);
if (wsaAction != null) {
msgCtx.setWSAAction(wsaAction);
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java?rev=219006&r1=219005&r2=219006&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java Thu Jul 14 00:37:09 2005
@@ -1,18 +1,18 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
package org.apache.axis2.context;
import org.apache.axis2.addressing.EndpointReference;
@@ -130,6 +130,10 @@
private boolean doingMTOM = false;
//Are we doing REST now?
private boolean doingREST = false;
+ //Rest through GET of HTTP
+ private boolean doRESTthroughPOST = false;
+
+
/**
* Conveniance Method, but before call engine.send() or engine.receive() one must send transport in/out
@@ -507,12 +511,12 @@
}
/* (non-Javadoc)
- * @see org.apache.axis2.context.AbstractContext#getProperty(java.lang.Object, boolean)
- */
+ * @see org.apache.axis2.context.AbstractContext#getProperty(java.lang.Object, boolean)
+ */
public Object getProperty(String key, boolean persistent) {
Object obj = super.getProperty(key, persistent);
- //The context hirachy might not have constructed fully, the check should
+ //The context hirachy might not have constructed fully, the check should
//look for the disconnected grandparents
if (obj == null && operationContext == null && serviceContext != null) {
obj = serviceContext.getProperty(key, persistent);
@@ -602,5 +606,13 @@
public void setDoingREST(boolean b) {
doingREST = b;
}
+
+ public void setRestThroughPOST(boolean b){
+ doRESTthroughPOST = b;
+ }
+ public boolean isRestThroughPOST(){
+ return doRESTthroughPOST;
+ }
+
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?rev=219006&r1=219005&r2=219006&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Thu Jul 14 00:37:09 2005
@@ -21,7 +21,6 @@
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisFault;
@@ -29,7 +28,6 @@
import org.apache.axis2.om.OMElement;
import org.apache.axis2.om.impl.OMOutputImpl;
import org.apache.axis2.transport.TransportSender;
-import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -37,6 +35,7 @@
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
@@ -53,6 +52,8 @@
TransportSender {
private boolean chuncked = false;
+ private boolean doMTOM = false;
+
private String httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
public static final String HTTP_METHOD = "HTTP_METHOD";
@@ -112,112 +113,27 @@
}
- public void writeMessageWithCommons(MessageContext msgContext,
+ public void writeMessageWithCommons(MessageContext msgContext,
EndpointReference toURL,
- OMElement dataout) throws AxisFault {
+ OMElement dataout)
+ throws AxisFault {
try {
URL url = new URL(toURL.getAddress());
//Configure the transport
String soapAction = msgContext.getWSAAction();
//settign soapAction
- String soapActionString = soapAction == null ? "" : soapAction;
+ String soapActionString = soapAction == null ? "" : soapAction.toString();
- PostMethod postMethod = new PostMethod();
- postMethod.setPath(url.getFile());
- msgContext.setProperty(HTTP_METHOD, postMethod);
- postMethod.setRequestEntity(
- new AxisRequestEntity(dataout,
- chuncked, msgContext.isDoingMTOM()));
- if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)
- && chuncked) {
- postMethod.setContentChunked(true);
- }
+ //supporting RESTFacility..
- if (msgContext.isDoingMTOM()) {
- postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- omOutput.getOptimizedContentType());
- } else {
- postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- "text/xml; charset=utf-8");
- }
- postMethod.setRequestHeader(HTTPConstants.HEADER_ACCEPT,
- HTTPConstants.HEADER_ACCEPT_APPL_SOAP
- + HTTPConstants.HEADER_ACCEPT_APPLICATION_DIME
- + HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED
- + HTTPConstants.HEADER_ACCEPT_TEXT_ALL);
- postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url
- .getHost());
- postMethod.setRequestHeader(HTTPConstants.HEADER_CACHE_CONTROL,
- "no-cache");
- postMethod
- .setRequestHeader(HTTPConstants.HEADER_PRAGMA, "no-cache");
- //content length is not set yet
- //setting HTTP vesion
-
- if (httpVersion != null) {
- if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
- //postMethod.setHttp11(false); todo method to findout the
- // transport version...
- //allowing keep-alive for 1.0
- postMethod.setRequestHeader(
- HTTPConstants.HEADER_CONNECTION,
- HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
- } else {
- // allowing keep-alive for 1.1
- postMethod.setRequestHeader(
- HTTPConstants.HEADER_CONNECTION,
- HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
- }
- }
- // othervise assumes HTTP 1.1 and keep-alive is default.
if (!msgContext.isDoingREST()) {
- postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION,
- soapActionString);
+ this.transportConfigurationPOST(msgContext,dataout,url,soapActionString,doMTOM);
}
-
- //execuite the HtttpMethodBase - a connection manager can be given
- // for handle multiple
- httpClient = new HttpClient();
- //hostConfig handles the socket functions..
- HostConfiguration hostConfig = getHostConfiguration(msgContext,
- url);
-
- //code that wirte the stream to the wire
-
- this.httpClient.executeMethod(hostConfig, postMethod);
- if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
- InputStream in = postMethod.getResponseBodyAsStream();
- if (in == null) {
- throw new AxisFault("Input Stream can not be Null");
- }
- msgContext.getOperationContext().setProperty(
- MessageContext.TRANSPORT_IN, in);
- Header contentTypeHeader = postMethod
- .getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
- if (contentTypeHeader != null) {
- String contentType = contentTypeHeader.getValue();
- if (contentType != null
- &&
- contentType
- .indexOf(
- HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) >=
- 0) {
- OperationContext opContext = msgContext
- .getOperationContext();
- if (opContext != null) {
- opContext.setProperty(
- HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
- contentType);
- }
- }
- }
-
- } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
- return;
- } else {
- throw new AxisFault("Error " + postMethod.getStatusCode()
- + " Error Message is "
- + postMethod.getResponseBodyAsString());
+ if (msgContext.isDoingREST() && !msgContext.isRestThroughPOST()) {
+ this.transportConfigurationGET(msgContext,url);
+ }
+ if (msgContext.isDoingREST() && msgContext.isRestThroughPOST()) {
+ this.transportConfigurationPOST(msgContext,dataout,url,soapActionString,doMTOM);
}
} catch (MalformedURLException e) {
throw new AxisFault(e);
@@ -228,7 +144,6 @@
}
}
-
protected HostConfiguration getHostConfiguration(MessageContext context,
URL targetURL) {
//TODO cheaking wheather the host is a proxy
@@ -359,5 +274,90 @@
}
}
+
+ private void transportConfigurationPOST(MessageContext msgContext,
+ OMElement dataout, URL url, String soapActionString, boolean doMTOM) throws MalformedURLException, AxisFault, IOException {
+ PostMethod postMethod = new PostMethod();
+ postMethod.setPath(url.getFile());
+ msgContext.setProperty(HTTP_METHOD, postMethod);
+ postMethod.setRequestEntity(new AxisRequestEntity(dataout, chuncked,doMTOM));
+ if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chuncked) {
+ ((PostMethod) postMethod).setContentChunked(true);
+ }
+
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=utf-8");
+ postMethod.setRequestHeader(HTTPConstants.HEADER_ACCEPT,
+ HTTPConstants.HEADER_ACCEPT_APPL_SOAP
+ + HTTPConstants.HEADER_ACCEPT_APPLICATION_DIME
+ + HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED
+ + HTTPConstants.HEADER_ACCEPT_TEXT_ALL);
+ postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CACHE_CONTROL, "no-cache");
+ postMethod.setRequestHeader(HTTPConstants.HEADER_PRAGMA, "no-cache");
+ //content length is not set yet
+ //setting HTTP vesion
+
+ if (httpVersion != null) {
+ if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
+ //postMethod.setHttp11(false); todo method to findout the transport version...
+ //allowing keep-alive for 1.0
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ } else {
+ // allowing keep-alive for 1.1
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ }
+ }
+ // othervise assumes HTTP 1.1 and keep-alive is default.
+ if (!msgContext.isDoingREST()) {
+ postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapActionString);
+ }
+
+ //execuite the HtttpMethodBase - a connection manager can be given for handle multiple
+ httpClient = new HttpClient();
+ //hostConfig handles the socket functions..
+ HostConfiguration hostConfig = getHostConfiguration(msgContext, url);
+
+ //code that wirte the stream to the wire
+
+ this.httpClient.executeMethod(hostConfig, postMethod);
+ if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
+ InputStream in = postMethod.getResponseBodyAsStream();
+ if (in == null) {
+ throw new AxisFault("Input Stream can not be Null");
+ }
+ msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN, in);
+ } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ return;
+ } else {
+ throw new AxisFault("Error " + postMethod.getStatusCode() + " Error Message is " + postMethod.getResponseBodyAsString());
+ }
+
+ }
+ private void transportConfigurationGET(MessageContext msgContext, URL url) throws MalformedURLException, AxisFault, IOException {
+ GetMethod getMehtod = new GetMethod();
+ getMehtod.setPath(url.getFile());
+ getMehtod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=utf-8");
+ this.httpClient = new HttpClient();
+ HostConfiguration hostConfig = this.getHostConfiguration(msgContext, url);
+
+ this.httpClient.executeMethod(hostConfig, getMehtod);
+ if (getMehtod.getStatusCode() == HttpStatus.SC_OK) {
+
+ InputStream in = getMehtod.getResponseBodyAsStream();
+ if (in == null) {
+ throw new AxisFault("Input Stream can not be Null");
+ }
+ msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN, in);
+ } else if (getMehtod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ return;
+ } else {
+ throw new AxisFault("Error " + getMehtod.getStatusCode() + " Error Message is " + getMehtod.getResponseBodyAsString());
+ }
+ }
+
}
Added: webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/RESTSearchClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/RESTSearchClient.java?rev=219006&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/RESTSearchClient.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/sample/yahooservices/RESTSearch/RESTSearchClient.java Thu Jul 14 00:37:09 2005
@@ -0,0 +1,51 @@
+package sample.yahooservices.RESTSearch;
+
+import org.apache.axis2.clientapi.Call;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.Constants;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.OMOutputImpl;
+
+
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLOutputFactory;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: saminda
+ * Date: Jul 11, 2005
+ * Time: 2:25:56 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class RESTSearchClient {
+ private static String eprGet =
+ "http://api.search.yahooservices.com/WebSearchService/V1/webSearch?appid=ApacheRestDemo&query=finances&format=pdf";
+
+
+
+ public static void main(String[] args) {
+ try{
+ Call call = new Call();
+ call.setTo(new EndpointReference(AddressingConstants.WSA_TO, eprGet));
+ call.setTransportInfo(Constants.TRANSPORT_COMMONS_HTTP,Constants.TRANSPORT_HTTP, false);
+ call.setDoREST(true);
+ call.setRestThroughPOST(false);
+
+ //if post is through GET of HTTP
+ OMElement response = call.invokeBlocking("",OMAbstractFactory.getOMFactory().createOMElement("","",""));
+
+ XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+ response.serializeWithCache(new OMOutputImpl(writer));
+ writer.flush();
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+
+}